aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorGravatar Rogan Creswick <creswick@gmail.com>2013-01-02 14:56:40 -0800
committerGravatar Rogan Creswick <creswick@gmail.com>2013-01-02 14:56:40 -0800
commit75139375b76cb277546da2429d8e983ca6758f61 (patch)
tree5b8d180f5f6dc9809eeec1612726a1de36cb7365 /tools
parentdbf076b39ca655500f2c0546b0ea57ceffca33b3 (diff)
added addon-sdk-1.7, without any changes
Diffstat (limited to 'tools')
-rw-r--r--tools/addon-sdk-1.7/LICENSE30
-rw-r--r--tools/addon-sdk-1.7/README36
-rw-r--r--tools/addon-sdk-1.7/bin/activate86
-rw-r--r--tools/addon-sdk-1.7/bin/activate.bat135
-rw-r--r--tools/addon-sdk-1.7/bin/activate.ps199
-rwxr-xr-xtools/addon-sdk-1.7/bin/cfx33
-rw-r--r--tools/addon-sdk-1.7/bin/cfx.bat6
-rw-r--r--tools/addon-sdk-1.7/bin/deactivate.bat23
-rwxr-xr-xtools/addon-sdk-1.7/bin/integration-scripts/buildbot-run-cfx-helper14
-rw-r--r--tools/addon-sdk-1.7/bin/integration-scripts/integration-check364
-rw-r--r--tools/addon-sdk-1.7/examples/annotator/README.md46
-rw-r--r--tools/addon-sdk-1.7/examples/annotator/data/annotation/annotation.html31
-rw-r--r--tools/addon-sdk-1.7/examples/annotator/data/annotation/annotation.js11
-rw-r--r--tools/addon-sdk-1.7/examples/annotator/data/editor/annotation-editor.html39
-rw-r--r--tools/addon-sdk-1.7/examples/annotator/data/editor/annotation-editor.js23
-rw-r--r--tools/addon-sdk-1.7/examples/annotator/data/jquery-1.4.2.min.js154
-rw-r--r--tools/addon-sdk-1.7/examples/annotator/data/list/annotation-list.css40
-rw-r--r--tools/addon-sdk-1.7/examples/annotator/data/list/annotation-list.html26
-rw-r--r--tools/addon-sdk-1.7/examples/annotator/data/list/annotation-list.js31
-rw-r--r--tools/addon-sdk-1.7/examples/annotator/data/matcher.js50
-rw-r--r--tools/addon-sdk-1.7/examples/annotator/data/selector.js73
-rw-r--r--tools/addon-sdk-1.7/examples/annotator/data/widget/pencil-off.pngbin0 -> 1740 bytes
-rw-r--r--tools/addon-sdk-1.7/examples/annotator/data/widget/pencil-on.pngbin0 -> 2054 bytes
-rw-r--r--tools/addon-sdk-1.7/examples/annotator/data/widget/widget.js17
-rw-r--r--tools/addon-sdk-1.7/examples/annotator/lib/main.js294
-rw-r--r--tools/addon-sdk-1.7/examples/annotator/package.json9
-rw-r--r--tools/addon-sdk-1.7/examples/annotator/tests/test-main.js7
-rwxr-xr-xtools/addon-sdk-1.7/examples/library-detector/README.md13
-rwxr-xr-xtools/addon-sdk-1.7/examples/library-detector/data/icons/closure.icobin0 -> 1150 bytes
-rwxr-xr-xtools/addon-sdk-1.7/examples/library-detector/data/icons/jquery.icobin0 -> 3638 bytes
-rwxr-xr-xtools/addon-sdk-1.7/examples/library-detector/data/icons/jquery_ui.icobin0 -> 1150 bytes
-rwxr-xr-xtools/addon-sdk-1.7/examples/library-detector/data/icons/modernizr.icobin0 -> 1150 bytes
-rwxr-xr-xtools/addon-sdk-1.7/examples/library-detector/data/icons/mootools.pngbin0 -> 386 bytes
-rwxr-xr-xtools/addon-sdk-1.7/examples/library-detector/data/icons/yui.icobin0 -> 6598 bytes
-rwxr-xr-xtools/addon-sdk-1.7/examples/library-detector/data/library-detector.js97
-rwxr-xr-xtools/addon-sdk-1.7/examples/library-detector/data/widget.js14
-rwxr-xr-xtools/addon-sdk-1.7/examples/library-detector/lib/main.js107
-rwxr-xr-xtools/addon-sdk-1.7/examples/library-detector/package.json9
-rw-r--r--tools/addon-sdk-1.7/examples/library-detector/test/test-main.js7
-rw-r--r--tools/addon-sdk-1.7/examples/reading-data/data/mom.pngbin0 -> 4778 bytes
-rw-r--r--tools/addon-sdk-1.7/examples/reading-data/data/sample.html7
-rw-r--r--tools/addon-sdk-1.7/examples/reading-data/lib/main.js44
-rw-r--r--tools/addon-sdk-1.7/examples/reading-data/package.json9
-rw-r--r--tools/addon-sdk-1.7/examples/reading-data/tests/test-main.js24
-rw-r--r--tools/addon-sdk-1.7/examples/reddit-panel/README.md14
-rw-r--r--tools/addon-sdk-1.7/examples/reddit-panel/data/jquery-1.4.4.min.js167
-rw-r--r--tools/addon-sdk-1.7/examples/reddit-panel/data/panel.js35
-rw-r--r--tools/addon-sdk-1.7/examples/reddit-panel/lib/main.js31
-rw-r--r--tools/addon-sdk-1.7/examples/reddit-panel/package.json9
-rw-r--r--tools/addon-sdk-1.7/examples/reddit-panel/tests/test-main.js21
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/README.md12
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/data/index.html12
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/data/moz_favicon.icobin0 -> 1406 bytes
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/data/pagemod-css-include-file.css1
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/data/test-context-menu.js5
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/data/test-page-mod.html12
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/data/test-page-worker.html12
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/data/test-page-worker.js29
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/data/test.html12
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/docs/clipboard.md62
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/docs/context-menu.md719
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/docs/hotkeys.md78
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/docs/notifications.md64
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/docs/page-mod.md412
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/docs/page-worker.md325
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/docs/panel.md607
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/docs/passwords.md568
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/docs/private-browsing.md50
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/docs/request.md203
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/docs/selection.md90
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/docs/self.md79
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/docs/simple-prefs.md75
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/docs/simple-storage.md220
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/docs/tabs.md385
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/docs/timers.md52
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/docs/widget.md909
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/docs/windows.md191
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/lib/addon-page.js33
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/lib/clipboard.js230
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/lib/context-menu.js1492
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/lib/hotkeys.js37
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/lib/l10n.js149
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/lib/notifications.js79
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/lib/page-mod.js319
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/lib/page-worker.js65
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/lib/panel.js381
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/lib/passwords.js59
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/lib/private-browsing.js61
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/lib/request.js208
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/lib/selection.js421
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/lib/simple-prefs.js68
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/lib/simple-storage.js237
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/lib/tabs.js28
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/lib/timers.js8
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/lib/widget.js923
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/lib/windows.js210
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/locale/en-GB.properties11
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/locale/eo.properties5
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/locale/fr-FR.properties14
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/package.json12
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/helpers.js23
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/pagemod-test-helpers.js67
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-addon-page.js51
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-clipboard.js64
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-context-menu.html45
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-context-menu.js2067
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-hotkeys.js160
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-l10n.js97
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-module.js37
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-notifications.js46
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-page-mod.js526
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-page-worker.js366
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-panel.js466
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-passwords.js281
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-private-browsing.js204
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-request.js340
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-selection.js458
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-simple-prefs.js175
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-simple-storage.js311
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-tabs.js900
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-timers.js12
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-widget.js1010
-rw-r--r--tools/addon-sdk-1.7/packages/addon-kit/tests/test-windows.js309
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/README.md35
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/data/content-proxy.js847
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/data/test-content-symbiont.js5
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/data/test-message-manager.js6
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/data/test-trusted-document.html17
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/data/worker.js247
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/api-utils.md157
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/app-strings.md65
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/base.md207
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/byte-streams.md68
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/collection.md77
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/content.md15
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/content/loader.md92
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/content/proxy.md241
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/content/symbiont.md140
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/content/worker.md130
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/cortex.md160
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/cuddlefish.md7
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/environment.md43
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/errors.md42
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/event/core.md51
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/event/target.md95
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/events.md78
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/file.md151
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/frame/utils.md53
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/globals.md100
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/hidden-frame.md83
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/httpd.md31
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/light-traits.md295
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/list.md98
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/match-pattern.md246
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/memory.md7
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/message-manager.md13
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/namespace.md71
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/observer-service.md73
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/plain-text-console.md7
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/preferences-service.md116
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/promise.md394
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/querystring.md37
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/runtime.md75
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/sandbox.md51
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/tab-browser.md140
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/text-streams.md102
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/traceback.md66
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/traits.md244
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/unit-test.md393
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/unload.md61
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/url.md85
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/uuid.md27
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/window-utils.md88
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/window/utils.md90
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/xhr.md95
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/xpcom.md216
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/docs/xul-app.md76
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/api-utils.js153
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/app-strings.js63
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/array.js69
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/base.js177
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/byte-streams.js102
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/channel.js46
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/collection.js108
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/content.js11
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/content/loader.js179
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/content/symbiont.js183
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/content/worker.js491
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/cortex.js109
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/cuddlefish.js302
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/dom/events.js136
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/dom/events/keys.js60
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/env!.js20
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/environment.js54
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/errors.js60
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/event/core.js147
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/event/target.js76
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/events.js178
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/events/assembler.js53
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/file.js192
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/find-tests.js5
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/frame/utils.js59
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/functional.js159
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/globals!.js93
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/hidden-frame.js166
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/httpd.js5166
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/keyboard/hotkeys.js107
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/keyboard/observer.js53
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/keyboard/utils.js186
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/l10n/locale.js122
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/l10n/plural-rules.js387
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/light-traits.js596
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/list.js114
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/match-pattern.js103
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/memory.js114
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/message-manager.js203
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/namespace.js43
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/observer-service.js175
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/passwords/utils.js101
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/plain-text-console.js82
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/preferences-service.js124
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/process.js76
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/promise.js219
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/querystring.js117
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/runtime.js15
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/sandbox.js46
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/self!.js48
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/system.js120
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/tab-browser.js727
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/tabs/events.js26
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/tabs/observer.js93
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/tabs/tab.js264
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/tabs/utils.js59
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/test.js108
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/test/assert.js331
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/text-streams.js240
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/timer.js78
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/traceback.js123
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/traits.js183
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/traits/core.js317
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/type.js340
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/unit-test-finder.js76
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/unit-test.js440
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/unload.js63
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/url.js113
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/utils/data.js71
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/utils/object.js46
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/utils/registry.js57
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/utils/thumbnail.js43
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/uuid.js13
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/window-utils.js278
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/window/utils.js110
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/windows/dom.js27
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/windows/loader.js120
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/windows/observer.js53
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/windows/tabs.js178
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/xhr.js150
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/xpcom.js207
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/lib/xul-app.js63
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/package.json14
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/commonjs-test-adapter/asserts.js54
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/fixtures/es5.js8
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/fixtures/sandbox-complex-character.js5
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/fixtures/sandbox-normal.js7
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/helpers.js24
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/loader/fixture.js6
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/add.js9
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/async1.js14
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/async2.js8
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/badExportAndReturn.js10
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/badFirst.js9
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/badSecond.js8
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/blue.js9
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/castor.js10
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/cheetah.js9
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/color.js7
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/dupe.js15
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/dupeNested.js15
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/dupeSetExports.js8
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/exportsEquals.js5
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/green.js10
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/lion.js7
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/orange.js10
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/pollux.js10
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/red.js16
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/setExports.js5
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/subtract.js9
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/tiger.js8
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/traditional1.js12
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/traditional2.js6
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/modules/types/cat.js5
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-api-utils.js241
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-app-strings.js62
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-array.js40
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-base.js240
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-byte-streams.js169
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-collection.js127
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-commonjs-test-adapter.js11
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-content-loader.js226
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-content-proxy.js807
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-content-symbiont.js190
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-content-worker.js465
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-cortex.js122
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-dom.js88
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-environment.js50
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-errors.js70
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-event-core.js217
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-event-target.js167
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-events.js267
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-file.js273
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-frame-utils.js67
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-functional.js170
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-globals.js22
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-hidden-frame.js51
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-httpd.js72
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-keyboard-observer.js36
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-keyboard-utils.js62
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-l10n-locale.js141
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-l10n-plural-rules.js82
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-light-traits.js11
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-list.js207
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-loader.js35
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-match-pattern.js127
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-memory.js19
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-message-manager.js600
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-modules.js148
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-namespace.js95
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-observer-service.js77
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-passwords-utils.js142
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-plain-text-console.js68
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-preferences-service.js112
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-process.js36
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-promise.js311
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-querystring.js206
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-registry.js80
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-require.js29
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-sandbox.js113
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-self.js54
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-set-exports.js35
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-tab-browser.js493
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-tab-observer.js39
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-tab.js110
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-text-streams.js156
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-timer.js131
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-traceback.js118
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-traits-core.js838
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-traits.js398
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-type.js92
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-unit-test.js251
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-unload.js161
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-url.js204
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-uuid.js27
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-window-loader.js120
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-window-observer.js48
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-window-utils.js321
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-window-utils2.js67
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-xhr.js75
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-xpcom.js217
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/test-xul-app.js45
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/traits/assert.js98
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/traits/descriptor-tests.js335
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/traits/inheritance-tests.js104
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/traits/object-tests.js321
-rw-r--r--tools/addon-sdk-1.7/packages/api-utils/tests/traits/utils.js56
-rw-r--r--tools/addon-sdk-1.7/packages/test-harness/README.md12
-rw-r--r--tools/addon-sdk-1.7/packages/test-harness/docs/harness.md6
-rw-r--r--tools/addon-sdk-1.7/packages/test-harness/docs/run-tests.md13
-rw-r--r--tools/addon-sdk-1.7/packages/test-harness/lib/harness.js324
-rw-r--r--tools/addon-sdk-1.7/packages/test-harness/lib/run-tests.js101
-rw-r--r--tools/addon-sdk-1.7/packages/test-harness/package.json8
-rw-r--r--tools/addon-sdk-1.7/packages/test-harness/tests/test-packaging.js18
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/__init__.py797
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/_version.py171
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/app-extension/application.ini11
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/app-extension/bootstrap.js216
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/app-extension/install.rdf33
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/bunch.py34
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/docs/__init__.py4
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/docs/apiparser.py392
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/docs/apirenderer.py302
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/docs/generate.py292
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/docs/renderapi.readme.md210
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/docs/webdocs.py193
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/manifest.py751
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/mobile-utils/bootstrap.js78
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/mobile-utils/install.rdf39
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/options_defaults.py26
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/options_xul.py64
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/packaging.py435
-rwxr-xr-xtools/addon-sdk-1.7/python-lib/cuddlefish/preflight.py77
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/prefs.py115
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/property_parser.py106
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/rdf.py190
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/runner.py696
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/templates.py83
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/__init__.py65
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/addons/simplest-test/main.js17
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/addons/simplest-test/package.json6
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/addons/simplest-test/tests/test-minimal.js7
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/explicit-icon/explicit-icon.png0
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/explicit-icon/explicit-icon64.png0
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/explicit-icon/lib/main.js4
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/explicit-icon/package.json5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/implicit-icon/icon.png0
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/implicit-icon/icon64.png0
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/implicit-icon/lib/main.js4
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/implicit-icon/package.json3
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/no-icon/lib/main.js4
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/no-icon/package.json3
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588661-files/packages/bar/lib/bar-loader.js4
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588661-files/packages/bar/package.json3
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588661-files/packages/foo/lib/foo-loader.js4
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588661-files/packages/foo/package.json4
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-611495-files/jspath-one/docs/main.md5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-611495-files/jspath-one/lib/main.js8
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-611495-files/jspath-one/package.json5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/commonjs-naming/doc/foo.md5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/commonjs-naming/lib/foo-loader.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/commonjs-naming/package.json3
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/commonjs-naming/test/test-foo.js7
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/original-naming/docs/foo.md5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/original-naming/lib/foo-loader.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/original-naming/package.json3
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/original-naming/tests/test-foo.js7
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/doc/foo.md5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/lib/foo.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/lib/loader.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/package.json3
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/test/test-foo.js7
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-locale/locale/emptyFolder0
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-locale/package.json1
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/doc/foo.md5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/foo.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/loader.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/package.json3
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/test/test-foo.js7
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/alt-lib/foo.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/alt-lib/loader.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/doc/foo.md5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/package.json4
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/test/test-foo.js7
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/alt2-lib/foo.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/alt2-lib/loader.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/doc/foo.md5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/package.json4
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/test/test-foo.js7
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-669274-files/packages/extra-options/docs/main.md5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-669274-files/packages/extra-options/lib/main.js8
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-669274-files/packages/extra-options/package.json6
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-715340-files/pkg-1-pack/package.json10
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-715340-files/pkg-2-unpack/package.json10
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-715340-files/pkg-3-pack/package.json9
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/e10s-adapter-files/packages/foo/lib/bar-e10s-adapter.js11
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/e10s-adapter-files/packages/foo/lib/bar.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/e10s-adapter-files/packages/foo/lib/foo.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/e10s-adapter-files/packages/foo/package.json1
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/five/lib/main.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/five/package.json3
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four-deps/four-a/lib/misc.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four-deps/four-a/package.json4
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four-deps/four-a/topfiles/main.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four/lib/main.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four/package.json3
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/one/lib/main.js9
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/one/lib/subdir/three.js6
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/one/lib/two.js8
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/one/package.json4
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/seven/data/text.data1
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/seven/lib/main.js6
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/seven/lib/unused.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/seven/package.json4
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/six/lib/unused.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/six/package.json3
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/six/unreachable.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/data/msg.txt1
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/data/subdir/submsg.txt1
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/lib/main.js8
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/lib/subdir/subfile.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/lib/unused.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/locale/fr-FR.properties5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/package.json3
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-b/lib/main.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-b/locale/fr-FR.properties6
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-b/package.json3
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-c/lib/main.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-c/lib/sub/foo.js6
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-c/locale/fr-FR.properties9
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-c/package.json3
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/lib/main.js8
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/package.json3
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/tests/nontest.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/tests/test-one.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/tests/test-two.js5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/preferences-files/packages/no-prefs/lib/main.js4
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/preferences-files/packages/no-prefs/package.json6
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/preferences-files/packages/simple-prefs/lib/main.js4
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/preferences-files/packages/simple-prefs/package.json18
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/dev-guide-source/index.md7
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/dev-guide-source/no_h1.md7
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/static-files/another.html5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/static-files/base.html161
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/static-files/index.html27
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/docs/APIreference.html469
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/docs/APIsample.md162
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/doc/aardvark-feeder.md12
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/doc/main.md0
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/lib/ignore_me3
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/lib/main.js8
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/lib/surprise.js/ignore_me_too2
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/package.json7
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/anteater_files/lib/main.js8
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/anteater_files/package.json8
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/api-utils/lib/loader.js7
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/api-utils/package.json5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/barbeque/lib/bar-module.js7
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/barbeque/package.json4
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/minimal/docs/main.md5
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/minimal/lib/main.js8
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/minimal/package.json4
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/xpi-template/components/harness.js8
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_apiparser.py538
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_apirenderer.py31
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_generate.py173
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_init.py148
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_licenses.py88
-rwxr-xr-xtools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_linker.py234
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_manifest.py254
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_packaging.py116
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_preflight.py147
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_property_parser.py75
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_rdf.py45
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_runner.py27
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_util.py22
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_version.py28
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_webdocs.py97
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_xpi.py412
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/util.py23
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/version_comparator.py206
-rw-r--r--tools/addon-sdk-1.7/python-lib/cuddlefish/xpi.py155
-rw-r--r--tools/addon-sdk-1.7/python-lib/jetpack_sdk_env.py66
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/AUTHORS43
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/LICENSE30
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/__init__.py603
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/blockparser.py95
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/blockprocessors.py460
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/commandline.py96
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/etree_loader.py33
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/extensions/__init__.py0
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/extensions/abbr.py95
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/extensions/codehilite.py224
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/extensions/def_list.py104
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/extensions/extra.py49
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/extensions/fenced_code.py117
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/extensions/footnotes.py293
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/extensions/headerid.py195
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/extensions/html_tidy.py62
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/extensions/imagelinks.py119
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/extensions/meta.py90
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/extensions/rss.py114
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/extensions/tables.py97
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/extensions/toc.py140
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/extensions/wikilinks.py155
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/html4.py274
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/inlinepatterns.py371
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/odict.py162
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/postprocessors.py77
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/preprocessors.py214
-rw-r--r--tools/addon-sdk-1.7/python-lib/markdown/treeprocessors.py329
-rw-r--r--tools/addon-sdk-1.7/python-lib/mozrunner/__init__.py690
-rw-r--r--tools/addon-sdk-1.7/python-lib/mozrunner/killableprocess.py316
-rw-r--r--tools/addon-sdk-1.7/python-lib/mozrunner/qijo.py166
-rw-r--r--tools/addon-sdk-1.7/python-lib/mozrunner/winprocess.py383
-rw-r--r--tools/addon-sdk-1.7/python-lib/mozrunner/wpk.py80
-rw-r--r--tools/addon-sdk-1.7/python-lib/plural-rules-generator.py174
-rw-r--r--tools/addon-sdk-1.7/python-lib/simplejson/LICENSE.txt19
-rw-r--r--tools/addon-sdk-1.7/python-lib/simplejson/__init__.py376
-rw-r--r--tools/addon-sdk-1.7/python-lib/simplejson/decoder.py343
-rw-r--r--tools/addon-sdk-1.7/python-lib/simplejson/encoder.py385
-rw-r--r--tools/addon-sdk-1.7/python-lib/simplejson/scanner.py67
-rw-r--r--tools/addon-sdk-1.7/python-lib/simplejson/tool.py44
580 files changed, 73798 insertions, 0 deletions
diff --git a/tools/addon-sdk-1.7/LICENSE b/tools/addon-sdk-1.7/LICENSE
new file mode 100644
index 0000000..ad8d321
--- /dev/null
+++ b/tools/addon-sdk-1.7/LICENSE
@@ -0,0 +1,30 @@
+The files which make up the SDK are developed by Mozilla and licensed
+under the MPL 2.0 (http://mozilla.org/MPL/2.0/), with the exception of the
+components listed below, which are made available by their authors under
+the licenses listed alongside.
+
+syntaxhighlighter
+------------------
+doc/static-files/syntaxhighlighter
+Made available under the MIT license.
+
+jQuery
+------
+examples/reddit-panel/data/jquery-1.4.4.min.js
+examples/annotator/data/jquery-1.4.2.min.js
+Made available under the MIT license.
+
+simplejson
+----------
+python-lib/simplejson
+Made available under the MIT license.
+
+Python Markdown
+---------------
+python-lib/markdown
+Made available under the BSD license.
+
+LibraryDetector
+---------------
+examples/library-detector/data/library-detector.js
+Made available under the MIT license.
diff --git a/tools/addon-sdk-1.7/README b/tools/addon-sdk-1.7/README
new file mode 100644
index 0000000..edebf5f
--- /dev/null
+++ b/tools/addon-sdk-1.7/README
@@ -0,0 +1,36 @@
+Add-on SDK README
+==================
+
+Before proceeding, please make sure you've installed Python 2.5,
+2.6, or 2.7 (if it's not already on your system):
+
+ http://python.org/download/
+
+Note that Python 3.0 and 3.1 are not supported in this release.
+
+For Windows users, MozillaBuild (https://wiki.mozilla.org/MozillaBuild)
+will install the correct version of Python and the MSYS package, which
+will make it easier to work with the SDK.
+
+To get started, first enter the same directory that this README file
+is in (the SDK's root directory) using a shell program. On Unix systems
+or on Windows with MSYS, you can execute the following command:
+
+ source bin/activate
+
+Windows users using cmd.exe should instead run:
+
+ bin\activate.bat
+
+Then run:
+
+ cfx docs
+
+This should start a documentation server and open a web browser
+with further instructions.
+
+
+Bugs
+-------
+
+* file a bug: https://bugzilla.mozilla.org/enter_bug.cgi?product=Add-on%20SDK \ No newline at end of file
diff --git a/tools/addon-sdk-1.7/bin/activate b/tools/addon-sdk-1.7/bin/activate
new file mode 100644
index 0000000..8f2d9dd
--- /dev/null
+++ b/tools/addon-sdk-1.7/bin/activate
@@ -0,0 +1,86 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# This file must be used with "source bin/activate" *from bash*
+# you cannot run it directly
+
+deactivate () {
+ if [ -n "$_OLD_VIRTUAL_PATH" ] ; then
+ PATH="$_OLD_VIRTUAL_PATH"
+ export PATH
+ unset _OLD_VIRTUAL_PATH
+ fi
+
+ # This should detect bash and zsh, which have a hash command that must
+ # be called to get it to forget past commands. Without forgetting
+ # past commands the $PATH changes we made may not be respected
+ if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
+ hash -r
+ fi
+
+ if [ -n "$_OLD_VIRTUAL_PS1" ] ; then
+ PS1="$_OLD_VIRTUAL_PS1"
+ export PS1
+ unset _OLD_VIRTUAL_PS1
+ fi
+
+ if [ -n "$_OLD_PYTHONPATH" ] ; then
+ PYTHONPATH="$_OLD_PYTHONPATH"
+ export PYTHONPATH
+ unset _OLD_PYTHONPATH
+ fi
+
+ unset CUDDLEFISH_ROOT
+
+ unset VIRTUAL_ENV
+ if [ ! "$1" = "nondestructive" ] ; then
+ # Self destruct!
+ unset deactivate
+ fi
+}
+
+# unset irrelavent variables
+deactivate nondestructive
+
+_OLD_PYTHONPATH="$PYTHONPATH"
+_OLD_VIRTUAL_PATH="$PATH"
+
+VIRTUAL_ENV="`pwd`"
+
+if [ "x$OSTYPE" = "xmsys" ] ; then
+ CUDDLEFISH_ROOT="`pwd -W | sed s,/,\\\\\\\\,g`"
+ PATH="`pwd`/bin:$PATH"
+ # msys will convert any env vars with PATH in it to use msys
+ # form and will unconvert before launching
+ PYTHONPATH="`pwd -W`/python-lib;$PYTHONPATH"
+else
+ CUDDLEFISH_ROOT="$VIRTUAL_ENV"
+ PYTHONPATH="$VIRTUAL_ENV/python-lib:$PYTHONPATH"
+ PATH="$VIRTUAL_ENV/bin:$PATH"
+fi
+
+VIRTUAL_ENV="`pwd`"
+
+export CUDDLEFISH_ROOT
+export PYTHONPATH
+export PATH
+
+_OLD_VIRTUAL_PS1="$PS1"
+if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then
+ # special case for Aspen magic directories
+ # see http://www.zetadev.com/software/aspen/
+ PS1="[`basename \`dirname \"$VIRTUAL_ENV\"\``] $PS1"
+else
+ PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1"
+fi
+export PS1
+
+# This should detect bash and zsh, which have a hash command that must
+# be called to get it to forget past commands. Without forgetting
+# past commands the $PATH changes we made may not be respected
+if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
+ hash -r
+fi
+
+python -c "from jetpack_sdk_env import welcome; welcome()"
diff --git a/tools/addon-sdk-1.7/bin/activate.bat b/tools/addon-sdk-1.7/bin/activate.bat
new file mode 100644
index 0000000..5a6b885
--- /dev/null
+++ b/tools/addon-sdk-1.7/bin/activate.bat
@@ -0,0 +1,135 @@
+@echo off
+rem This Source Code Form is subject to the terms of the Mozilla Public
+rem License, v. 2.0. If a copy of the MPL was not distributed with this
+rem file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+set VIRTUAL_ENV=%~dp0
+set VIRTUAL_ENV=%VIRTUAL_ENV:~0,-5%
+set CUDDLEFISH_ROOT=%VIRTUAL_ENV%
+
+SET PYTHONKEY=SOFTWARE\Python\PythonCore
+
+rem look for 32-bit windows and python, or 64-bit windows and python
+
+SET PYTHONVERSION=2.7
+call:CheckPython PYTHONINSTALL %PYTHONKEY%\%PYTHONVERSION%\InstallPath
+if "%PYTHONINSTALL%" NEQ "" goto FoundPython
+
+SET PYTHONVERSION=2.6
+call:CheckPython PYTHONINSTALL %PYTHONKEY%\%PYTHONVERSION%\InstallPath
+if "%PYTHONINSTALL%" NEQ "" goto FoundPython
+
+SET PYTHONVERSION=2.5
+call:CheckPython PYTHONINSTALL %PYTHONKEY%\%PYTHONVERSION%\InstallPath
+if "%PYTHONINSTALL%" NEQ "" goto FoundPython
+
+if not defined ProgramFiles(x86) goto win32
+
+rem look for 32-bit python on 64-bit windows
+
+SET PYTHONKEY=SOFTWARE\Wow6432Node\Python\PythonCore
+
+SET PYTHONVERSION=2.7
+call:CheckPython PYTHONINSTALL %PYTHONKEY%\%PYTHONVERSION%\InstallPath
+if "%PYTHONINSTALL%" NEQ "" goto FoundPython
+
+SET PYTHONVERSION=2.6
+call:CheckPython PYTHONINSTALL %PYTHONKEY%\%PYTHONVERSION%\InstallPath
+if "%PYTHONINSTALL%" NEQ "" goto FoundPython
+
+SET PYTHONVERSION=2.5
+call:CheckPython PYTHONINSTALL %PYTHONKEY%\%PYTHONVERSION%\InstallPath
+if "%PYTHONINSTALL%" NEQ "" goto FoundPython
+
+:win32
+
+SET PYTHONVERSION=
+set PYTHONKEY=
+echo Warning: Failed to find Python installation directory
+goto :EOF
+
+:FoundPython
+
+if defined _OLD_PYTHONPATH (
+ set PYTHONPATH=%_OLD_PYTHONPATH%
+)
+if not defined PYTHONPATH (
+ set PYTHONPATH=;
+)
+set _OLD_PYTHONPATH=%PYTHONPATH%
+set PYTHONPATH=%VIRTUAL_ENV%\python-lib;%PYTHONPATH%
+
+if not defined PROMPT (
+ set PROMPT=$P$G
+)
+
+if defined _OLD_VIRTUAL_PROMPT (
+ set PROMPT=%_OLD_VIRTUAL_PROMPT%
+)
+
+set _OLD_VIRTUAL_PROMPT=%PROMPT%
+set PROMPT=(%VIRTUAL_ENV%) %PROMPT%
+
+if defined _OLD_VIRTUAL_PATH goto OLDPATH
+goto SKIPPATH
+:OLDPATH
+PATH %_OLD_VIRTUAL_PATH%
+
+:SKIPPATH
+set _OLD_VIRTUAL_PATH=%PATH%
+PATH %VIRTUAL_ENV%\bin;%PYTHONINSTALL%;%PATH%
+set PYTHONKEY=
+set PYTHONINSTALL=
+set PYTHONVERSION=
+set key=
+set reg=
+set _tokens=
+cd "%VIRTUAL_ENV%"
+python -c "from jetpack_sdk_env import welcome; welcome()"
+GOTO :EOF
+
+:CheckPython
+::CheckPython(retVal, key)
+::Reads the registry at %2% and checks if a Python exists there.
+::Checks both HKLM and HKCU, then checks the executable actually exists.
+SET key=%2%
+SET "%~1="
+SET reg=reg
+if defined ProgramFiles(x86) (
+ rem 32-bit cmd on 64-bit windows
+ if exist %WINDIR%\sysnative\reg.exe SET reg=%WINDIR%\sysnative\reg.exe
+)
+rem On Vista+, the last line of output is:
+rem (default) REG_SZ the_value
+rem (but note the word "default" will be localized.
+rem On XP, the last line of output is:
+rem <NO NAME>\tREG_SZ\tthe_value
+rem (not sure if "NO NAME" is localized or not!)
+rem SO: we use ")>" as the tokens to split on, then nuke
+rem the REG_SZ and any tabs or spaces.
+FOR /F "usebackq tokens=2 delims=)>" %%A IN (`%reg% QUERY HKLM\%key% /ve 2^>NUL`) DO SET "%~1=%%A"
+rem Remove the REG_SZ
+set PYTHONINSTALL=%PYTHONINSTALL:REG_SZ=%
+rem Remove tabs (note the literal \t in the next line
+set PYTHONINSTALL=%PYTHONINSTALL: =%
+rem Remove spaces.
+set PYTHONINSTALL=%PYTHONINSTALL: =%
+if exist %PYTHONINSTALL%\python.exe goto :EOF
+rem It may be a 32bit Python directory built from source, in which case the
+rem executable is in the PCBuild directory.
+if exist %PYTHONINSTALL%\PCBuild\python.exe (set "PYTHONINSTALL=%PYTHONINSTALL%\PCBuild" & goto :EOF)
+rem Or maybe a 64bit build directory.
+if exist %PYTHONINSTALL%\PCBuild\amd64\python.exe (set "PYTHONINSTALL=%PYTHONINSTALL%\PCBuild\amd64" & goto :EOF)
+
+rem And try HKCU
+FOR /F "usebackq tokens=2 delims=)>" %%A IN (`%reg% QUERY HKCU\%key% /ve 2^>NUL`) DO SET "%~1=%%A"
+set PYTHONINSTALL=%PYTHONINSTALL:REG_SZ=%
+set PYTHONINSTALL=%PYTHONINSTALL: =%
+set PYTHONINSTALL=%PYTHONINSTALL: =%
+if exist %PYTHONINSTALL%\python.exe goto :EOF
+if exist %PYTHONINSTALL%\PCBuild\python.exe (set "PYTHONINSTALL=%PYTHONINSTALL%\PCBuild" & goto :EOF)
+if exist %PYTHONINSTALL%\PCBuild\amd64\python.exe (set "PYTHONINSTALL=%PYTHONINSTALL%\PCBuild\amd64" & goto :EOF)
+rem can't find it here, so arrange to try the next key
+set PYTHONINSTALL=
+
+GOTO :EOF
diff --git a/tools/addon-sdk-1.7/bin/activate.ps1 b/tools/addon-sdk-1.7/bin/activate.ps1
new file mode 100644
index 0000000..5d939d4
--- /dev/null
+++ b/tools/addon-sdk-1.7/bin/activate.ps1
@@ -0,0 +1,99 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+$Env:VIRTUAL_ENV = (gl);
+$Env:CUDDLEFISH_ROOT = $Env:VIRTUAL_ENV;
+
+# http://stackoverflow.com/questions/5648931/powershell-test-if-registry-value-exists/5652674#5652674
+Function Test-RegistryValue {
+ param(
+ [Alias("PSPath")]
+ [Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
+ [String]$Path
+ ,
+ [Parameter(Position = 1, Mandatory = $true)]
+ [String]$Name
+ ,
+ [Switch]$PassThru
+ )
+
+ process {
+ if (Test-Path $Path) {
+ $Key = Get-Item -LiteralPath $Path
+ if ($Key.GetValue($Name, $null) -ne $null) {
+ if ($PassThru) {
+ Get-ItemProperty $Path $Name
+ } else {
+ $true
+ }
+ } else {
+ $false
+ }
+ } else {
+ $false
+ }
+ }
+}
+
+$WINCURVERKEY = 'HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion';
+$WIN64 = (Test-RegistryValue $WINCURVERKEY 'ProgramFilesDir (x86)');
+
+if($WIN64) {
+ $PYTHONKEY='HKLM:SOFTWARE\Wow6432Node\Python\PythonCore';
+}
+else {
+ $PYTHONKEY='HKLM:SOFTWARE\Python\PythonCore';
+}
+
+$Env:PYTHONVERSION = '';
+$Env:PYTHONINSTALL = '';
+
+foreach ($version in @('2.6', '2.5', '2.4')) {
+ if (Test-RegistryValue "$PYTHONKEY\$version\InstallPath" '(default)') {
+ $Env:PYTHONVERSION = $version;
+ }
+}
+
+if ($Env:PYTHONVERSION) {
+ $Env:PYTHONINSTALL = (Get-Item "$PYTHONKEY\$version\InstallPath)").'(default)';
+}
+
+if ($Env:PYTHONINSTALL) {
+ $Env:Path += ";$Env:PYTHONINSTALL";
+}
+
+if (Test-Path Env:_OLD_PYTHONPATH) {
+ $Env:PYTHONPATH = $Env:_OLD_PYTHONPATH;
+}
+else {
+ $Env:PYTHONPATH = '';
+}
+
+$Env:_OLD_PYTHONPATH=$Env:PYTHONPATH;
+$Env:PYTHONPATH= "$Env:VIRTUAL_ENV\python-lib;$Env:PYTHONPATH";
+
+if (Test-Path Function:_OLD_VIRTUAL_PROMPT) {
+ Set-Content Function:Prompt (Get-Content Function:_OLD_VIRTUAL_PROMPT);
+}
+else {
+ function global:_OLD_VIRTUAL_PROMPT {}
+}
+
+Set-Content Function:_OLD_VIRTUAL_PROMPT (Get-Content Function:Prompt);
+
+function global:prompt { "($Env:VIRTUAL_ENV) $(_OLD_VIRTUAL_PROMPT)"; };
+
+if (Test-Path Env:_OLD_VIRTUAL_PATH) {
+ $Env:PATH = $Env:_OLD_VIRTUAL_PATH;
+}
+else {
+ $Env:_OLD_VIRTUAL_PATH = $Env:PATH;
+}
+
+$Env:Path="$Env:VIRTUAL_ENV\bin;$Env:Path"
+
+[System.Console]::WriteLine("Note: this PowerShell SDK activation script is experimental.")
+
+python -c "from jetpack_sdk_env import welcome; welcome()"
+
diff --git a/tools/addon-sdk-1.7/bin/cfx b/tools/addon-sdk-1.7/bin/cfx
new file mode 100755
index 0000000..2be9d19
--- /dev/null
+++ b/tools/addon-sdk-1.7/bin/cfx
@@ -0,0 +1,33 @@
+#! /usr/bin/env python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+import os
+import sys
+
+# set the cuddlefish "root directory" for this process if it's not already
+# set in the environment
+cuddlefish_root = os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0])))
+
+if 'CUDDLEFISH_ROOT' not in os.environ:
+ os.environ['CUDDLEFISH_ROOT'] = cuddlefish_root
+
+# add our own python-lib path to the python module search path.
+python_lib_dir = os.path.join(cuddlefish_root, "python-lib")
+if python_lib_dir not in sys.path:
+ sys.path.append(python_lib_dir)
+
+# now export to env so sub-processes get it too
+if 'PYTHONPATH' not in os.environ:
+ os.environ['PYTHONPATH'] = python_lib_dir
+elif python_lib_dir not in os.environ['PYTHONPATH'].split(os.pathsep):
+ paths = os.environ['PYTHONPATH'].split(os.pathsep)
+ paths.insert(0, python_lib_dir)
+ os.environ['PYTHONPATH'] = os.pathsep.join(paths)
+
+import cuddlefish
+
+if __name__ == '__main__':
+ cuddlefish.run()
diff --git a/tools/addon-sdk-1.7/bin/cfx.bat b/tools/addon-sdk-1.7/bin/cfx.bat
new file mode 100644
index 0000000..215b034
--- /dev/null
+++ b/tools/addon-sdk-1.7/bin/cfx.bat
@@ -0,0 +1,6 @@
+@echo off
+rem This Source Code Form is subject to the terms of the Mozilla Public
+rem License, v. 2.0. If a copy of the MPL was not distributed with this
+rem file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+python "%VIRTUAL_ENV%\bin\cfx" %*
diff --git a/tools/addon-sdk-1.7/bin/deactivate.bat b/tools/addon-sdk-1.7/bin/deactivate.bat
new file mode 100644
index 0000000..e6bcd92
--- /dev/null
+++ b/tools/addon-sdk-1.7/bin/deactivate.bat
@@ -0,0 +1,23 @@
+@echo off
+rem This Source Code Form is subject to the terms of the Mozilla Public
+rem License, v. 2.0. If a copy of the MPL was not distributed with this
+rem file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+if defined _OLD_VIRTUAL_PROMPT (
+ set "PROMPT=%_OLD_VIRTUAL_PROMPT%"
+)
+set _OLD_VIRTUAL_PROMPT=
+
+if defined _OLD_VIRTUAL_PATH (
+ set "PATH=%_OLD_VIRTUAL_PATH%"
+)
+set _OLD_VIRTUAL_PATH=
+
+if defined _OLD_PYTHONPATH (
+ set "PYTHONPATH=%_OLD_PYTHONPATH%"
+)
+set _OLD_PYTHONPATH=
+
+set CUDDLEFISH_ROOT=
+
+:END
diff --git a/tools/addon-sdk-1.7/bin/integration-scripts/buildbot-run-cfx-helper b/tools/addon-sdk-1.7/bin/integration-scripts/buildbot-run-cfx-helper
new file mode 100755
index 0000000..56c76ad
--- /dev/null
+++ b/tools/addon-sdk-1.7/bin/integration-scripts/buildbot-run-cfx-helper
@@ -0,0 +1,14 @@
+#!/bin/bash
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+source ./bin/activate
+if [ type -P xvfb-run ]
+then
+ xvfb-run cfx $*
+else
+ cfx $*
+fi
+deactivate
diff --git a/tools/addon-sdk-1.7/bin/integration-scripts/integration-check b/tools/addon-sdk-1.7/bin/integration-scripts/integration-check
new file mode 100644
index 0000000..d64472f
--- /dev/null
+++ b/tools/addon-sdk-1.7/bin/integration-scripts/integration-check
@@ -0,0 +1,364 @@
+#!/usr/bin/env python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import signal
+import threading
+import urllib2, urllib
+import zipfile
+import tarfile
+import subprocess
+import optparse
+import sys, re
+#import win32api
+
+
+class SDK:
+ def __init__(self):
+ try:
+ # Take the current working directory
+ self.default_path = os.getcwd()
+ if sys.platform == "win32":
+ self.mswindows = True
+ else:
+ self.mswindows = False
+ # Take the default home path of the user.
+ home = os.path.expanduser('~')
+
+ # The following are the parameters that can be used to pass a dynamic URL, a specific path or a binry. The binary is not used yet. It will be used in version 2.0
+ # If a dynamic path is to be mentioned, it should start with a '/'. For eg. "/Desktop"
+ parser = optparse.OptionParser()
+ parser.add_option('-u', '--url', dest = 'url', default = 'https://ftp.mozilla.org/pub/mozilla.org/labs/jetpack/addon-sdk-latest.zip')
+ parser.add_option('-p', '--path', dest = 'path', default = self.default_path)
+ parser.add_option('-b', '--binary', dest = 'binary')#, default='/Applications/Firefox.app')
+ (options, args) = parser.parse_args()
+
+ # Get the URL from the parameter
+ self.link = options.url
+ # Set the base path for the user. If the user supplies the path, use the home variable as well. Else, take the default path of this script as the installation directory.
+ if options.path!=self.default_path:
+ if self.mswindows:
+ self.base_path = home + str(options.path).strip() + '\\'
+ else:
+ self.base_path = home + str(options.path).strip() + '/'
+ else:
+ if self.mswindows:
+ self.base_path = str(options.path).strip() + '\\'
+ else:
+ self.base_path = str(options.path).strip() + '/'
+ assert ' ' not in self.base_path, "You cannot have a space in your home path. Please remove the space before you continue."
+ print('Your Base path is =' + self.base_path)
+
+ # This assignment is not used in this program. It will be used in version 2 of this script.
+ self.bin = options.binary
+ # if app or bin is empty, dont pass anything
+
+ # Search for the .zip file or tarball file in the URL.
+ i = self.link.rfind('/')
+
+ self.fname = self.link[i+1:]
+ z = re.search('zip',self.fname,re.I)
+ g = re.search('gz',self.fname,re.I)
+ if z:
+ print 'zip file present in the URL.'
+ self.zip = True
+ self.gz = False
+ elif g:
+ print 'gz file present in the URL'
+ self.gz = True
+ self.zip = False
+ else:
+ print 'zip/gz file not present. Check the URL.'
+ return
+ print("File name is =" + self.fname)
+
+ # Join the base path and the zip/tar file name to crate a complete Local file path.
+ self.fpath = self.base_path + self.fname
+ print('Your local file path will be=' + self.fpath)
+ except AssertionError, e:
+ print e.args[0]
+ sys.exit(1)
+
+ # Download function - to download the SDK from the URL to the local machine.
+ def download(self,url,fpath,fname):
+ try:
+ # Start the download
+ print("Downloading...Please be patient!")
+ urllib.urlretrieve(url,filename = fname)
+ print('Download was successful.')
+ except ValueError: # Handles broken URL errors.
+ print 'The URL is ether broken or the file does not exist. Please enter the correct URL.'
+ raise
+ except urllib2.URLError: # Handles URL errors
+ print '\nURL not correct. Check again!'
+ raise
+
+ # Function to extract the downloaded zipfile.
+ def extract(self, zipfilepath, extfile):
+ try:
+ # Timeout is set to 30 seconds.
+ timeout = 30
+ # Change the directory to the location of the zip file.
+ try:
+ os.chdir(zipfilepath)
+ except OSError:
+ # Will reach here if zip file doesnt exist
+ print 'O/S Error:' + zipfilepath + 'does not exist'
+ raise
+
+ # Get the folder name of Jetpack to get the exact version number.
+ if self.zip:
+ try:
+ f = zipfile.ZipFile(extfile, "r")
+ except IOError as (errno, strerror): # Handles file errors
+ print "I/O error - Cannot perform extract operation: {1}".format(errno, strerror)
+ raise
+ list = f.namelist()[0]
+ temp_name = list.split('/')
+ print('Folder Name= ' +temp_name[0])
+ self.folder_name = temp_name[0]
+ elif self.gz:
+ try:
+ f = tarfile.open(extfile,'r')
+ except IOError as (errno, strerror): # Handles file errors
+ print "I/O error - Cannot perform extract operation: {1}".format(errno, strerror)
+ raise
+ list = f.getnames()[0]
+ temp_name = list.split('/')
+ print('Folder Name= ' +temp_name[0])
+ self.folder_name = temp_name[0]
+
+ print ('Starting to Extract...')
+
+ # Timeout code. The subprocess.popen exeutes the command and the thread waits for a timeout. If the process does not finish within the mentioned-
+ # timeout, the process is killed.
+ kill_check = threading.Event()
+
+ if self.zip:
+ # Call the command to unzip the file.
+ if self.mswindows:
+ zipfile.ZipFile.extractall(f)
+ else:
+ p = subprocess.Popen('unzip '+extfile, stdout=subprocess.PIPE, shell=True)
+ pid = p.pid
+ elif self.gz:
+ # Call the command to untar the file.
+ if self.mswindows:
+ tarfile.TarFile.extractall(f)
+ else:
+ p = subprocess.Popen('tar -xf '+extfile, stdout=subprocess.PIPE, shell=True)
+ pid = p.pid
+
+ #No need to handle for windows because windows automatically replaces old files with new files. It does not ask the user(as it does in Mac/Unix)
+ if self.mswindows==False:
+ watch = threading.Timer(timeout, kill_process, args=(pid, kill_check, self.mswindows ))
+ watch.start()
+ (stdout, stderr) = p.communicate()
+ watch.cancel() # if it's still waiting to run
+ success = not kill_check.isSet()
+
+ # Abort process if process fails.
+ if not success:
+ raise RuntimeError
+ kill_check.clear()
+ print('Extraction Successful.')
+ except RuntimeError:
+ print "Ending the program"
+ sys.exit(1)
+ except:
+ print "Error during file extraction: ", sys.exc_info()[0]
+ raise
+
+ # Function to run the cfx testall comands and to make sure the SDK is not broken.
+ def run_testall(self, home_path, folder_name):
+ try:
+ timeout = 500
+
+ self.new_dir = home_path + folder_name
+ try:
+ os.chdir(self.new_dir)
+ except OSError:
+ # Will reach here if the jetpack 0.X directory doesnt exist
+ print 'O/S Error: Jetpack directory does not exist at ' + self.new_dir
+ raise
+ print '\nStarting tests...'
+ # Timeout code. The subprocess.popen exeutes the command and the thread waits for a timeout. If the process does not finish within the mentioned-
+ # timeout, the process is killed.
+ kill_check = threading.Event()
+
+ # Set the path for the logs. They will be in the parent directory of the Jetpack SDK.
+ log_path = home_path + 'tests.log'
+
+ # Subprocess call to set up the jetpack environment and to start the tests. Also sends the output to a log file.
+ if self.bin != None:
+ if self.mswindows:
+ p = subprocess.Popen("bin\\activate && cfx testall -a firefox -b \"" + self.bin + "\"" , stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
+ proc_handle = p._handle
+ (stdout,stderr) = p.communicate()
+ else:
+ p = subprocess.Popen('. bin/activate; cfx testall -a firefox -b ' + self.bin , stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
+ pid = p.pid
+ (stdout,stderr) = p.communicate()
+ elif self.bin == None:
+ if self.mswindows:
+ p=subprocess.Popen('bin\\activate && cfx testall -a firefox > '+log_path, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
+ proc_handle = p._handle
+ (stdout,stderr) = p.communicate()
+ else:
+ p = subprocess.Popen('. bin/activate; cfx testall -a firefox > '+log_path, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
+ pid = p.pid
+ (stdout,stderr) = p.communicate()
+
+ #Write the output to log file
+ f=open(log_path,"w")
+ f.write(stdout+stderr)
+ f.close()
+
+ #Watchdog for timeout process
+ if self.mswindows:
+ watch = threading.Timer(timeout, kill_process, args=(proc_handle, kill_check, self.mswindows))
+ else:
+ watch = threading.Timer(timeout, kill_process, args=(pid, kill_check, self.mswindows))
+ watch.start()
+ watch.cancel() # if it's still waiting to run
+ success = not kill_check.isSet()
+ if not success:
+ raise RuntimeError
+ kill_check.clear()
+
+ if p.returncode!=0:
+ print('\nAll tests were not successful. Check the test-logs in the jetpack directory.')
+ result_sdk(home_path)
+ #sys.exit(1)
+ raise RuntimeError
+ else:
+ ret_code=result_sdk(home_path)
+ if ret_code==0:
+ print('\nAll tests were successful. Yay \o/ . Running a sample package test now...')
+ else:
+ print ('\nThere were errors during the tests.Take a look at logs')
+ raise RuntimeError
+ except RuntimeError:
+ print "Ending the program"
+ sys.exit(1)
+ except:
+ print "Error during the testall command execution:", sys.exc_info()[0]
+ raise
+
+ def package(self, example_dir):
+ try:
+ timeout = 30
+
+ print '\nNow Running packaging tests...'
+
+ kill_check = threading.Event()
+
+ # Set the path for the example logs. They will be in the parent directory of the Jetpack SDK.
+ exlog_path = example_dir + 'test-example.log'
+ # Subprocess call to test the sample example for packaging.
+ if self.bin!=None:
+ if self.mswindows:
+ p = subprocess.Popen('bin\\activate && cfx run --pkgdir examples\\reading-data --static-args="{\"quitWhenDone\":true}" -b \"" + self.bin + "\"' , stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
+ proc_handle = p._handle
+ (stdout, stderr) = p.communicate()
+ else:
+ p = subprocess.Popen('. bin/activate; cfx run --pkgdir examples/reading-data --static-args=\'{\"quitWhenDone\":true}\' -b ' + self.bin , stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
+ pid = p.pid
+ (stdout, stderr) = p.communicate()
+ elif self.bin==None:
+ if self.mswindows:
+ p = subprocess.Popen('bin\\activate && cfx run --pkgdir examples\\reading-data --static-args="{\"quitWhenDone\":true}"', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
+ proc_handle = p._handle
+ (stdout, stderr) = p.communicate()
+ else:
+ p = subprocess.Popen('. bin/activate; cfx run --pkgdir examples/reading-data --static-args=\'{\"quitWhenDone\":true}\' ', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
+ pid = p.pid
+ (stdout, stderr) = p.communicate()
+
+ #Write the output to log file
+ f=open(exlog_path,"w")
+ f.write(stdout+stderr)
+ f.close()
+
+ #Watch dog for timeout process
+ if self.mswindows:
+ watch = threading.Timer(timeout, kill_process, args=(proc_handle, kill_check, self.mswindows))
+ else:
+ watch = threading.Timer(timeout, kill_process, args=(pid, kill_check, self.mswindows))
+ watch.start()
+ watch.cancel() # if it's still waiting to run
+ success = not kill_check.isSet()
+ if not success:
+ raise RuntimeError
+ kill_check.clear()
+
+ if p.returncode != 0:
+ print('\nSample tests were not executed correctly. Check the test-example log in jetpack diretory.')
+ result_example(example_dir)
+ raise RuntimeError
+ else:
+ ret_code=result_example(example_dir)
+ if ret_code==0:
+ print('\nAll tests pass. The SDK is working! Yay \o/')
+ else:
+ print ('\nTests passed with warning.Take a look at logs')
+ sys.exit(1)
+
+ except RuntimeError:
+ print "Ending program"
+ sys.exit(1)
+ except:
+ print "Error during running sample tests:", sys.exc_info()[0]
+ raise
+
+def result_sdk(sdk_dir):
+ log_path = sdk_dir + 'tests.log'
+ print 'Results are logged at:' + log_path
+ try:
+ f = open(log_path,'r')
+ # Handles file errors
+ except IOError :
+ print 'I/O error - Cannot open test log at ' + log_path
+ raise
+
+ for line in reversed(open(log_path).readlines()):
+ if line.strip()=='FAIL':
+ print ('\nOverall result - FAIL. Look at the test log at '+log_path)
+ return 1
+ return 0
+
+
+def result_example(sdk_dir):
+ exlog_path = sdk_dir + 'test-example.log'
+ print 'Sample test results are logged at:' + exlog_path
+ try:
+ f = open(exlog_path,'r')
+ # Handles file errors
+ except IOError :
+ print 'I/O error - Cannot open sample test log at ' + exlog_path
+ raise
+
+ #Read the file in reverse and check for the keyword 'FAIL'.
+ for line in reversed(open(exlog_path).readlines()):
+ if line.strip()=='FAIL':
+ print ('\nOverall result for Sample tests - FAIL. Look at the test log at '+exlog_path)
+ return 1
+ return 0
+
+def kill_process(process, kill_check, mswindows):
+ print '\nProcess Timedout. Killing the process. Please Rerun this script.'
+ if mswindows:
+ win32api.TerminateProcess(process, -1)
+ else:
+ os.kill(process, signal.SIGKILL)
+ kill_check.set()# tell the main routine to kill. Used SIGKILL to hard kill the process.
+ return
+
+if __name__ == "__main__":
+ obj = SDK()
+ obj.download(obj.link,obj.fpath,obj.fname)
+ obj.extract(obj.base_path,obj.fname)
+ obj.run_testall(obj.base_path,obj.folder_name)
+ obj.package(obj.base_path)
diff --git a/tools/addon-sdk-1.7/examples/annotator/README.md b/tools/addon-sdk-1.7/examples/annotator/README.md
new file mode 100644
index 0000000..d376240
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/annotator/README.md
@@ -0,0 +1,46 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+This add-on enables users to add notes, or annotations, to Web pages.
+
+Usage
+-----
+
+To switch the annotator on, left-click the pencil icon in the Add-on Bar. The
+icon should turn yellow: this indicates that the annotator is active. To switch
+it off, click it again. Switching it on/off only stops you from entering
+annotations: existing annotations are still displayed.
+
+When the annotator is active and the user moves the mouse over a page element
+that can be annotated, the annotator highlights that elements by giving it a
+yellow background.
+
+If the user clicks on a highlighted element the add-on opens a dialog for the
+user to enter the annotation. When the user hits <return> the annotation is
+saved.
+
+Elements which have been annotated are displayed with a yellow border: when the
+user moves the mouse over one of these elements, the add-on displays the
+annotation associated with that element.
+
+To view all annotations in a list, right-click the pencil icon.
+
+The add-on is deactivated in private browsing mode, meaning that new annotations
+can't be created although existing ones are still shown. On exiting private
+browsing the add-on returns to its previous activation state.
+
+Known Issues/Limitations
+------------------------
+
+It is not possible to delete annotations, or to edit them after creating them,
+but it would be simple to add this.
+
+When right-clicking the annotator icon the add-on bar's context-menu is shown:
+this is tracked by
+[bug 626326](https://bugzilla.mozilla.org/show_bug.cgi?id=626326).
+
+The list of annotations should be anchored to the widget. The annotation
+editor, and the annotation itself, should be anchored to the element which is
+annotated. The will be done when the implementation of panel-anchoring is
+extended.
diff --git a/tools/addon-sdk-1.7/examples/annotator/data/annotation/annotation.html b/tools/addon-sdk-1.7/examples/annotator/data/annotation/annotation.html
new file mode 100644
index 0000000..f61c5e1
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/annotator/data/annotation/annotation.html
@@ -0,0 +1,31 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+ <title>Annotation</title>
+ <style type="text/css" media="all">
+
+body {
+ font: 100% arial, helvetica, sans-serif;
+ }
+
+div {
+ text-align:left;
+ }
+
+</style>
+
+</head>
+
+<body>
+
+<div id = "annotation">
+</div>
+
+</body>
+</html>
diff --git a/tools/addon-sdk-1.7/examples/annotator/data/annotation/annotation.js b/tools/addon-sdk-1.7/examples/annotator/data/annotation/annotation.js
new file mode 100644
index 0000000..c1f57aa
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/annotator/data/annotation/annotation.js
@@ -0,0 +1,11 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+Initialize annotation content.
+*/
+
+self.on('message', function(message) {
+ $('#annotation').text(message);
+});
diff --git a/tools/addon-sdk-1.7/examples/annotator/data/editor/annotation-editor.html b/tools/addon-sdk-1.7/examples/annotator/data/editor/annotation-editor.html
new file mode 100644
index 0000000..6125999
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/annotator/data/editor/annotation-editor.html
@@ -0,0 +1,39 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+ <title>Annotation</title>
+ <style type="text/css" media="all">
+ body, html {
+ font: 100% arial, helvetica, sans-serif;
+ padding: 0;
+ margin: 0;
+ position: fixed;
+ }
+ textarea {
+ width: 100%;
+ height: 100%;
+ margin: 10px;
+ padding: 0;
+ color: inherit !important;
+ font: inherit !important;
+ background: transparent;
+ border: none;
+ }
+ </style>
+
+</head>
+
+<body>
+
+<textarea rows='10' cols='20' id='annotation-box'>
+</textarea>
+
+</body>
+
+</html>
diff --git a/tools/addon-sdk-1.7/examples/annotator/data/editor/annotation-editor.js b/tools/addon-sdk-1.7/examples/annotator/data/editor/annotation-editor.js
new file mode 100644
index 0000000..2fe5888
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/annotator/data/editor/annotation-editor.js
@@ -0,0 +1,23 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+On a return key, send the content of the textArea back to the add-on,
+and zero the textArea for the next time.
+*/
+
+var textArea = document.getElementById('annotation-box');
+
+textArea.onkeyup = function(event) {
+ if (event.keyCode == 13) {
+ self.postMessage(textArea.value);
+ textArea.value = '';
+ }
+};
+
+self.on('message', function() {
+ var textArea = document.getElementById('annotation-box');
+ textArea.value = '';
+ textArea.focus();
+});
diff --git a/tools/addon-sdk-1.7/examples/annotator/data/jquery-1.4.2.min.js b/tools/addon-sdk-1.7/examples/annotator/data/jquery-1.4.2.min.js
new file mode 100644
index 0000000..7c24308
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/annotator/data/jquery-1.4.2.min.js
@@ -0,0 +1,154 @@
+/*!
+ * jQuery JavaScript Library v1.4.2
+ * http://jquery.com/
+ *
+ * Copyright 2010, John Resig
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://jquery.org/license
+ *
+ * Includes Sizzle.js
+ * http://sizzlejs.com/
+ * Copyright 2010, The Dojo Foundation
+ * Released under the MIT, BSD, and GPL Licenses.
+ *
+ * Date: Sat Feb 13 22:33:48 2010 -0500
+ */
+(function(A,w){function ma(){if(!c.isReady){try{s.documentElement.doScroll("left")}catch(a){setTimeout(ma,1);return}c.ready()}}function Qa(a,b){b.src?c.ajax({url:b.src,async:false,dataType:"script"}):c.globalEval(b.text||b.textContent||b.innerHTML||"");b.parentNode&&b.parentNode.removeChild(b)}function X(a,b,d,f,e,j){var i=a.length;if(typeof b==="object"){for(var o in b)X(a,o,b[o],f,e,d);return a}if(d!==w){f=!j&&f&&c.isFunction(d);for(o=0;o<i;o++)e(a[o],b,f?d.call(a[o],o,e(a[o],b)):d,j);return a}return i?
+e(a[0],b):w}function J(){return(new Date).getTime()}function Y(){return false}function Z(){return true}function na(a,b,d){d[0].type=a;return c.event.handle.apply(b,d)}function oa(a){var b,d=[],f=[],e=arguments,j,i,o,k,n,r;i=c.data(this,"events");if(!(a.liveFired===this||!i||!i.live||a.button&&a.type==="click")){a.liveFired=this;var u=i.live.slice(0);for(k=0;k<u.length;k++){i=u[k];i.origType.replace(O,"")===a.type?f.push(i.selector):u.splice(k--,1)}j=c(a.target).closest(f,a.currentTarget);n=0;for(r=
+j.length;n<r;n++)for(k=0;k<u.length;k++){i=u[k];if(j[n].selector===i.selector){o=j[n].elem;f=null;if(i.preType==="mouseenter"||i.preType==="mouseleave")f=c(a.relatedTarget).closest(i.selector)[0];if(!f||f!==o)d.push({elem:o,handleObj:i})}}n=0;for(r=d.length;n<r;n++){j=d[n];a.currentTarget=j.elem;a.data=j.handleObj.data;a.handleObj=j.handleObj;if(j.handleObj.origHandler.apply(j.elem,e)===false){b=false;break}}return b}}function pa(a,b){return"live."+(a&&a!=="*"?a+".":"")+b.replace(/\./g,"`").replace(/ /g,
+"&")}function qa(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function ra(a,b){var d=0;b.each(function(){if(this.nodeName===(a[d]&&a[d].nodeName)){var f=c.data(a[d++]),e=c.data(this,f);if(f=f&&f.events){delete e.handle;e.events={};for(var j in f)for(var i in f[j])c.event.add(this,j,f[j][i],f[j][i].data)}}})}function sa(a,b,d){var f,e,j;b=b&&b[0]?b[0].ownerDocument||b[0]:s;if(a.length===1&&typeof a[0]==="string"&&a[0].length<512&&b===s&&!ta.test(a[0])&&(c.support.checkClone||!ua.test(a[0]))){e=
+true;if(j=c.fragments[a[0]])if(j!==1)f=j}if(!f){f=b.createDocumentFragment();c.clean(a,b,f,d)}if(e)c.fragments[a[0]]=j?f:1;return{fragment:f,cacheable:e}}function K(a,b){var d={};c.each(va.concat.apply([],va.slice(0,b)),function(){d[this]=a});return d}function wa(a){return"scrollTo"in a&&a.document?a:a.nodeType===9?a.defaultView||a.parentWindow:false}var c=function(a,b){return new c.fn.init(a,b)},Ra=A.jQuery,Sa=A.$,s=A.document,T,Ta=/^[^<]*(<[\w\W]+>)[^>]*$|^#([\w-]+)$/,Ua=/^.[^:#\[\.,]*$/,Va=/\S/,
+Wa=/^(\s|\u00A0)+|(\s|\u00A0)+$/g,Xa=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,P=navigator.userAgent,xa=false,Q=[],L,$=Object.prototype.toString,aa=Object.prototype.hasOwnProperty,ba=Array.prototype.push,R=Array.prototype.slice,ya=Array.prototype.indexOf;c.fn=c.prototype={init:function(a,b){var d,f;if(!a)return this;if(a.nodeType){this.context=this[0]=a;this.length=1;return this}if(a==="body"&&!b){this.context=s;this[0]=s.body;this.selector="body";this.length=1;return this}if(typeof a==="string")if((d=Ta.exec(a))&&
+(d[1]||!b))if(d[1]){f=b?b.ownerDocument||b:s;if(a=Xa.exec(a))if(c.isPlainObject(b)){a=[s.createElement(a[1])];c.fn.attr.call(a,b,true)}else a=[f.createElement(a[1])];else{a=sa([d[1]],[f]);a=(a.cacheable?a.fragment.cloneNode(true):a.fragment).childNodes}return c.merge(this,a)}else{if(b=s.getElementById(d[2])){if(b.id!==d[2])return T.find(a);this.length=1;this[0]=b}this.context=s;this.selector=a;return this}else if(!b&&/^\w+$/.test(a)){this.selector=a;this.context=s;a=s.getElementsByTagName(a);return c.merge(this,
+a)}else return!b||b.jquery?(b||T).find(a):c(b).find(a);else if(c.isFunction(a))return T.ready(a);if(a.selector!==w){this.selector=a.selector;this.context=a.context}return c.makeArray(a,this)},selector:"",jquery:"1.4.2",length:0,size:function(){return this.length},toArray:function(){return R.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this.slice(a)[0]:this[a]},pushStack:function(a,b,d){var f=c();c.isArray(a)?ba.apply(f,a):c.merge(f,a);f.prevObject=this;f.context=this.context;if(b===
+"find")f.selector=this.selector+(this.selector?" ":"")+d;else if(b)f.selector=this.selector+"."+b+"("+d+")";return f},each:function(a,b){return c.each(this,a,b)},ready:function(a){c.bindReady();if(c.isReady)a.call(s,c);else Q&&Q.push(a);return this},eq:function(a){return a===-1?this.slice(a):this.slice(a,+a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(R.apply(this,arguments),"slice",R.call(arguments).join(","))},map:function(a){return this.pushStack(c.map(this,
+function(b,d){return a.call(b,d,b)}))},end:function(){return this.prevObject||c(null)},push:ba,sort:[].sort,splice:[].splice};c.fn.init.prototype=c.fn;c.extend=c.fn.extend=function(){var a=arguments[0]||{},b=1,d=arguments.length,f=false,e,j,i,o;if(typeof a==="boolean"){f=a;a=arguments[1]||{};b=2}if(typeof a!=="object"&&!c.isFunction(a))a={};if(d===b){a=this;--b}for(;b<d;b++)if((e=arguments[b])!=null)for(j in e){i=a[j];o=e[j];if(a!==o)if(f&&o&&(c.isPlainObject(o)||c.isArray(o))){i=i&&(c.isPlainObject(i)||
+c.isArray(i))?i:c.isArray(o)?[]:{};a[j]=c.extend(f,i,o)}else if(o!==w)a[j]=o}return a};c.extend({noConflict:function(a){A.$=Sa;if(a)A.jQuery=Ra;return c},isReady:false,ready:function(){if(!c.isReady){if(!s.body)return setTimeout(c.ready,13);c.isReady=true;if(Q){for(var a,b=0;a=Q[b++];)a.call(s,c);Q=null}c.fn.triggerHandler&&c(s).triggerHandler("ready")}},bindReady:function(){if(!xa){xa=true;if(s.readyState==="complete")return c.ready();if(s.addEventListener){s.addEventListener("DOMContentLoaded",
+L,false);A.addEventListener("load",c.ready,false)}else if(s.attachEvent){s.attachEvent("onreadystatechange",L);A.attachEvent("onload",c.ready);var a=false;try{a=A.frameElement==null}catch(b){}s.documentElement.doScroll&&a&&ma()}}},isFunction:function(a){return $.call(a)==="[object Function]"},isArray:function(a){return $.call(a)==="[object Array]"},isPlainObject:function(a){if(!a||$.call(a)!=="[object Object]"||a.nodeType||a.setInterval)return false;if(a.constructor&&!aa.call(a,"constructor")&&!aa.call(a.constructor.prototype,
+"isPrototypeOf"))return false;var b;for(b in a);return b===w||aa.call(a,b)},isEmptyObject:function(a){for(var b in a)return false;return true},error:function(a){throw a;},parseJSON:function(a){if(typeof a!=="string"||!a)return null;a=c.trim(a);if(/^[\],:{}\s]*$/.test(a.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return A.JSON&&A.JSON.parse?A.JSON.parse(a):(new Function("return "+
+a))();else c.error("Invalid JSON: "+a)},noop:function(){},globalEval:function(a){if(a&&Va.test(a)){var b=s.getElementsByTagName("head")[0]||s.documentElement,d=s.createElement("script");d.type="text/javascript";if(c.support.scriptEval)d.appendChild(s.createTextNode(a));else d.text=a;b.insertBefore(d,b.firstChild);b.removeChild(d)}},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,b,d){var f,e=0,j=a.length,i=j===w||c.isFunction(a);if(d)if(i)for(f in a){if(b.apply(a[f],
+d)===false)break}else for(;e<j;){if(b.apply(a[e++],d)===false)break}else if(i)for(f in a){if(b.call(a[f],f,a[f])===false)break}else for(d=a[0];e<j&&b.call(d,e,d)!==false;d=a[++e]);return a},trim:function(a){return(a||"").replace(Wa,"")},makeArray:function(a,b){b=b||[];if(a!=null)a.length==null||typeof a==="string"||c.isFunction(a)||typeof a!=="function"&&a.setInterval?ba.call(b,a):c.merge(b,a);return b},inArray:function(a,b){if(b.indexOf)return b.indexOf(a);for(var d=0,f=b.length;d<f;d++)if(b[d]===
+a)return d;return-1},merge:function(a,b){var d=a.length,f=0;if(typeof b.length==="number")for(var e=b.length;f<e;f++)a[d++]=b[f];else for(;b[f]!==w;)a[d++]=b[f++];a.length=d;return a},grep:function(a,b,d){for(var f=[],e=0,j=a.length;e<j;e++)!d!==!b(a[e],e)&&f.push(a[e]);return f},map:function(a,b,d){for(var f=[],e,j=0,i=a.length;j<i;j++){e=b(a[j],j,d);if(e!=null)f[f.length]=e}return f.concat.apply([],f)},guid:1,proxy:function(a,b,d){if(arguments.length===2)if(typeof b==="string"){d=a;a=d[b];b=w}else if(b&&
+!c.isFunction(b)){d=b;b=w}if(!b&&a)b=function(){return a.apply(d||this,arguments)};if(a)b.guid=a.guid=a.guid||b.guid||c.guid++;return b},uaMatch:function(a){a=a.toLowerCase();a=/(webkit)[ \/]([\w.]+)/.exec(a)||/(opera)(?:.*version)?[ \/]([\w.]+)/.exec(a)||/(msie) ([\w.]+)/.exec(a)||!/compatible/.test(a)&&/(mozilla)(?:.*? rv:([\w.]+))?/.exec(a)||[];return{browser:a[1]||"",version:a[2]||"0"}},browser:{}});P=c.uaMatch(P);if(P.browser){c.browser[P.browser]=true;c.browser.version=P.version}if(c.browser.webkit)c.browser.safari=
+true;if(ya)c.inArray=function(a,b){return ya.call(b,a)};T=c(s);if(s.addEventListener)L=function(){s.removeEventListener("DOMContentLoaded",L,false);c.ready()};else if(s.attachEvent)L=function(){if(s.readyState==="complete"){s.detachEvent("onreadystatechange",L);c.ready()}};(function(){c.support={};var a=s.documentElement,b=s.createElement("script"),d=s.createElement("div"),f="script"+J();d.style.display="none";d.innerHTML=" <link/><table></table><a href='/a' style='color:red;float:left;opacity:.55;'>a</a><input type='checkbox'/>";
+var e=d.getElementsByTagName("*"),j=d.getElementsByTagName("a")[0];if(!(!e||!e.length||!j)){c.support={leadingWhitespace:d.firstChild.nodeType===3,tbody:!d.getElementsByTagName("tbody").length,htmlSerialize:!!d.getElementsByTagName("link").length,style:/red/.test(j.getAttribute("style")),hrefNormalized:j.getAttribute("href")==="/a",opacity:/^0.55$/.test(j.style.opacity),cssFloat:!!j.style.cssFloat,checkOn:d.getElementsByTagName("input")[0].value==="on",optSelected:s.createElement("select").appendChild(s.createElement("option")).selected,
+parentNode:d.removeChild(d.appendChild(s.createElement("div"))).parentNode===null,deleteExpando:true,checkClone:false,scriptEval:false,noCloneEvent:true,boxModel:null};b.type="text/javascript";try{b.appendChild(s.createTextNode("window."+f+"=1;"))}catch(i){}a.insertBefore(b,a.firstChild);if(A[f]){c.support.scriptEval=true;delete A[f]}try{delete b.test}catch(o){c.support.deleteExpando=false}a.removeChild(b);if(d.attachEvent&&d.fireEvent){d.attachEvent("onclick",function k(){c.support.noCloneEvent=
+false;d.detachEvent("onclick",k)});d.cloneNode(true).fireEvent("onclick")}d=s.createElement("div");d.innerHTML="<input type='radio' name='radiotest' checked='checked'/>";a=s.createDocumentFragment();a.appendChild(d.firstChild);c.support.checkClone=a.cloneNode(true).cloneNode(true).lastChild.checked;c(function(){var k=s.createElement("div");k.style.width=k.style.paddingLeft="1px";s.body.appendChild(k);c.boxModel=c.support.boxModel=k.offsetWidth===2;s.body.removeChild(k).style.display="none"});a=function(k){var n=
+s.createElement("div");k="on"+k;var r=k in n;if(!r){n.setAttribute(k,"return;");r=typeof n[k]==="function"}return r};c.support.submitBubbles=a("submit");c.support.changeBubbles=a("change");a=b=d=e=j=null}})();c.props={"for":"htmlFor","class":"className",readonly:"readOnly",maxlength:"maxLength",cellspacing:"cellSpacing",rowspan:"rowSpan",colspan:"colSpan",tabindex:"tabIndex",usemap:"useMap",frameborder:"frameBorder"};var G="jQuery"+J(),Ya=0,za={};c.extend({cache:{},expando:G,noData:{embed:true,object:true,
+applet:true},data:function(a,b,d){if(!(a.nodeName&&c.noData[a.nodeName.toLowerCase()])){a=a==A?za:a;var f=a[G],e=c.cache;if(!f&&typeof b==="string"&&d===w)return null;f||(f=++Ya);if(typeof b==="object"){a[G]=f;e[f]=c.extend(true,{},b)}else if(!e[f]){a[G]=f;e[f]={}}a=e[f];if(d!==w)a[b]=d;return typeof b==="string"?a[b]:a}},removeData:function(a,b){if(!(a.nodeName&&c.noData[a.nodeName.toLowerCase()])){a=a==A?za:a;var d=a[G],f=c.cache,e=f[d];if(b){if(e){delete e[b];c.isEmptyObject(e)&&c.removeData(a)}}else{if(c.support.deleteExpando)delete a[c.expando];
+else a.removeAttribute&&a.removeAttribute(c.expando);delete f[d]}}}});c.fn.extend({data:function(a,b){if(typeof a==="undefined"&&this.length)return c.data(this[0]);else if(typeof a==="object")return this.each(function(){c.data(this,a)});var d=a.split(".");d[1]=d[1]?"."+d[1]:"";if(b===w){var f=this.triggerHandler("getData"+d[1]+"!",[d[0]]);if(f===w&&this.length)f=c.data(this[0],a);return f===w&&d[1]?this.data(d[0]):f}else return this.trigger("setData"+d[1]+"!",[d[0],b]).each(function(){c.data(this,
+a,b)})},removeData:function(a){return this.each(function(){c.removeData(this,a)})}});c.extend({queue:function(a,b,d){if(a){b=(b||"fx")+"queue";var f=c.data(a,b);if(!d)return f||[];if(!f||c.isArray(d))f=c.data(a,b,c.makeArray(d));else f.push(d);return f}},dequeue:function(a,b){b=b||"fx";var d=c.queue(a,b),f=d.shift();if(f==="inprogress")f=d.shift();if(f){b==="fx"&&d.unshift("inprogress");f.call(a,function(){c.dequeue(a,b)})}}});c.fn.extend({queue:function(a,b){if(typeof a!=="string"){b=a;a="fx"}if(b===
+w)return c.queue(this[0],a);return this.each(function(){var d=c.queue(this,a,b);a==="fx"&&d[0]!=="inprogress"&&c.dequeue(this,a)})},dequeue:function(a){return this.each(function(){c.dequeue(this,a)})},delay:function(a,b){a=c.fx?c.fx.speeds[a]||a:a;b=b||"fx";return this.queue(b,function(){var d=this;setTimeout(function(){c.dequeue(d,b)},a)})},clearQueue:function(a){return this.queue(a||"fx",[])}});var Aa=/[\n\t]/g,ca=/\s+/,Za=/\r/g,$a=/href|src|style/,ab=/(button|input)/i,bb=/(button|input|object|select|textarea)/i,
+cb=/^(a|area)$/i,Ba=/radio|checkbox/;c.fn.extend({attr:function(a,b){return X(this,a,b,true,c.attr)},removeAttr:function(a){return this.each(function(){c.attr(this,a,"");this.nodeType===1&&this.removeAttribute(a)})},addClass:function(a){if(c.isFunction(a))return this.each(function(n){var r=c(this);r.addClass(a.call(this,n,r.attr("class")))});if(a&&typeof a==="string")for(var b=(a||"").split(ca),d=0,f=this.length;d<f;d++){var e=this[d];if(e.nodeType===1)if(e.className){for(var j=" "+e.className+" ",
+i=e.className,o=0,k=b.length;o<k;o++)if(j.indexOf(" "+b[o]+" ")<0)i+=" "+b[o];e.className=c.trim(i)}else e.className=a}return this},removeClass:function(a){if(c.isFunction(a))return this.each(function(k){var n=c(this);n.removeClass(a.call(this,k,n.attr("class")))});if(a&&typeof a==="string"||a===w)for(var b=(a||"").split(ca),d=0,f=this.length;d<f;d++){var e=this[d];if(e.nodeType===1&&e.className)if(a){for(var j=(" "+e.className+" ").replace(Aa," "),i=0,o=b.length;i<o;i++)j=j.replace(" "+b[i]+" ",
+" ");e.className=c.trim(j)}else e.className=""}return this},toggleClass:function(a,b){var d=typeof a,f=typeof b==="boolean";if(c.isFunction(a))return this.each(function(e){var j=c(this);j.toggleClass(a.call(this,e,j.attr("class"),b),b)});return this.each(function(){if(d==="string")for(var e,j=0,i=c(this),o=b,k=a.split(ca);e=k[j++];){o=f?o:!i.hasClass(e);i[o?"addClass":"removeClass"](e)}else if(d==="undefined"||d==="boolean"){this.className&&c.data(this,"__className__",this.className);this.className=
+this.className||a===false?"":c.data(this,"__className__")||""}})},hasClass:function(a){a=" "+a+" ";for(var b=0,d=this.length;b<d;b++)if((" "+this[b].className+" ").replace(Aa," ").indexOf(a)>-1)return true;return false},val:function(a){if(a===w){var b=this[0];if(b){if(c.nodeName(b,"option"))return(b.attributes.value||{}).specified?b.value:b.text;if(c.nodeName(b,"select")){var d=b.selectedIndex,f=[],e=b.options;b=b.type==="select-one";if(d<0)return null;var j=b?d:0;for(d=b?d+1:e.length;j<d;j++){var i=
+e[j];if(i.selected){a=c(i).val();if(b)return a;f.push(a)}}return f}if(Ba.test(b.type)&&!c.support.checkOn)return b.getAttribute("value")===null?"on":b.value;return(b.value||"").replace(Za,"")}return w}var o=c.isFunction(a);return this.each(function(k){var n=c(this),r=a;if(this.nodeType===1){if(o)r=a.call(this,k,n.val());if(typeof r==="number")r+="";if(c.isArray(r)&&Ba.test(this.type))this.checked=c.inArray(n.val(),r)>=0;else if(c.nodeName(this,"select")){var u=c.makeArray(r);c("option",this).each(function(){this.selected=
+c.inArray(c(this).val(),u)>=0});if(!u.length)this.selectedIndex=-1}else this.value=r}})}});c.extend({attrFn:{val:true,css:true,html:true,text:true,data:true,width:true,height:true,offset:true},attr:function(a,b,d,f){if(!a||a.nodeType===3||a.nodeType===8)return w;if(f&&b in c.attrFn)return c(a)[b](d);f=a.nodeType!==1||!c.isXMLDoc(a);var e=d!==w;b=f&&c.props[b]||b;if(a.nodeType===1){var j=$a.test(b);if(b in a&&f&&!j){if(e){b==="type"&&ab.test(a.nodeName)&&a.parentNode&&c.error("type property can't be changed");
+a[b]=d}if(c.nodeName(a,"form")&&a.getAttributeNode(b))return a.getAttributeNode(b).nodeValue;if(b==="tabIndex")return(b=a.getAttributeNode("tabIndex"))&&b.specified?b.value:bb.test(a.nodeName)||cb.test(a.nodeName)&&a.href?0:w;return a[b]}if(!c.support.style&&f&&b==="style"){if(e)a.style.cssText=""+d;return a.style.cssText}e&&a.setAttribute(b,""+d);a=!c.support.hrefNormalized&&f&&j?a.getAttribute(b,2):a.getAttribute(b);return a===null?w:a}return c.style(a,b,d)}});var O=/\.(.*)$/,db=function(a){return a.replace(/[^\w\s\.\|`]/g,
+function(b){return"\\"+b})};c.event={add:function(a,b,d,f){if(!(a.nodeType===3||a.nodeType===8)){if(a.setInterval&&a!==A&&!a.frameElement)a=A;var e,j;if(d.handler){e=d;d=e.handler}if(!d.guid)d.guid=c.guid++;if(j=c.data(a)){var i=j.events=j.events||{},o=j.handle;if(!o)j.handle=o=function(){return typeof c!=="undefined"&&!c.event.triggered?c.event.handle.apply(o.elem,arguments):w};o.elem=a;b=b.split(" ");for(var k,n=0,r;k=b[n++];){j=e?c.extend({},e):{handler:d,data:f};if(k.indexOf(".")>-1){r=k.split(".");
+k=r.shift();j.namespace=r.slice(0).sort().join(".")}else{r=[];j.namespace=""}j.type=k;j.guid=d.guid;var u=i[k],z=c.event.special[k]||{};if(!u){u=i[k]=[];if(!z.setup||z.setup.call(a,f,r,o)===false)if(a.addEventListener)a.addEventListener(k,o,false);else a.attachEvent&&a.attachEvent("on"+k,o)}if(z.add){z.add.call(a,j);if(!j.handler.guid)j.handler.guid=d.guid}u.push(j);c.event.global[k]=true}a=null}}},global:{},remove:function(a,b,d,f){if(!(a.nodeType===3||a.nodeType===8)){var e,j=0,i,o,k,n,r,u,z=c.data(a),
+C=z&&z.events;if(z&&C){if(b&&b.type){d=b.handler;b=b.type}if(!b||typeof b==="string"&&b.charAt(0)==="."){b=b||"";for(e in C)c.event.remove(a,e+b)}else{for(b=b.split(" ");e=b[j++];){n=e;i=e.indexOf(".")<0;o=[];if(!i){o=e.split(".");e=o.shift();k=new RegExp("(^|\\.)"+c.map(o.slice(0).sort(),db).join("\\.(?:.*\\.)?")+"(\\.|$)")}if(r=C[e])if(d){n=c.event.special[e]||{};for(B=f||0;B<r.length;B++){u=r[B];if(d.guid===u.guid){if(i||k.test(u.namespace)){f==null&&r.splice(B--,1);n.remove&&n.remove.call(a,u)}if(f!=
+null)break}}if(r.length===0||f!=null&&r.length===1){if(!n.teardown||n.teardown.call(a,o)===false)Ca(a,e,z.handle);delete C[e]}}else for(var B=0;B<r.length;B++){u=r[B];if(i||k.test(u.namespace)){c.event.remove(a,n,u.handler,B);r.splice(B--,1)}}}if(c.isEmptyObject(C)){if(b=z.handle)b.elem=null;delete z.events;delete z.handle;c.isEmptyObject(z)&&c.removeData(a)}}}}},trigger:function(a,b,d,f){var e=a.type||a;if(!f){a=typeof a==="object"?a[G]?a:c.extend(c.Event(e),a):c.Event(e);if(e.indexOf("!")>=0){a.type=
+e=e.slice(0,-1);a.exclusive=true}if(!d){a.stopPropagation();c.event.global[e]&&c.each(c.cache,function(){this.events&&this.events[e]&&c.event.trigger(a,b,this.handle.elem)})}if(!d||d.nodeType===3||d.nodeType===8)return w;a.result=w;a.target=d;b=c.makeArray(b);b.unshift(a)}a.currentTarget=d;(f=c.data(d,"handle"))&&f.apply(d,b);f=d.parentNode||d.ownerDocument;try{if(!(d&&d.nodeName&&c.noData[d.nodeName.toLowerCase()]))if(d["on"+e]&&d["on"+e].apply(d,b)===false)a.result=false}catch(j){}if(!a.isPropagationStopped()&&
+f)c.event.trigger(a,b,f,true);else if(!a.isDefaultPrevented()){f=a.target;var i,o=c.nodeName(f,"a")&&e==="click",k=c.event.special[e]||{};if((!k._default||k._default.call(d,a)===false)&&!o&&!(f&&f.nodeName&&c.noData[f.nodeName.toLowerCase()])){try{if(f[e]){if(i=f["on"+e])f["on"+e]=null;c.event.triggered=true;f[e]()}}catch(n){}if(i)f["on"+e]=i;c.event.triggered=false}}},handle:function(a){var b,d,f,e;a=arguments[0]=c.event.fix(a||A.event);a.currentTarget=this;b=a.type.indexOf(".")<0&&!a.exclusive;
+if(!b){d=a.type.split(".");a.type=d.shift();f=new RegExp("(^|\\.)"+d.slice(0).sort().join("\\.(?:.*\\.)?")+"(\\.|$)")}e=c.data(this,"events");d=e[a.type];if(e&&d){d=d.slice(0);e=0;for(var j=d.length;e<j;e++){var i=d[e];if(b||f.test(i.namespace)){a.handler=i.handler;a.data=i.data;a.handleObj=i;i=i.handler.apply(this,arguments);if(i!==w){a.result=i;if(i===false){a.preventDefault();a.stopPropagation()}}if(a.isImmediatePropagationStopped())break}}}return a.result},props:"altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode layerX layerY metaKey newValue offsetX offsetY originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),
+fix:function(a){if(a[G])return a;var b=a;a=c.Event(b);for(var d=this.props.length,f;d;){f=this.props[--d];a[f]=b[f]}if(!a.target)a.target=a.srcElement||s;if(a.target.nodeType===3)a.target=a.target.parentNode;if(!a.relatedTarget&&a.fromElement)a.relatedTarget=a.fromElement===a.target?a.toElement:a.fromElement;if(a.pageX==null&&a.clientX!=null){b=s.documentElement;d=s.body;a.pageX=a.clientX+(b&&b.scrollLeft||d&&d.scrollLeft||0)-(b&&b.clientLeft||d&&d.clientLeft||0);a.pageY=a.clientY+(b&&b.scrollTop||
+d&&d.scrollTop||0)-(b&&b.clientTop||d&&d.clientTop||0)}if(!a.which&&(a.charCode||a.charCode===0?a.charCode:a.keyCode))a.which=a.charCode||a.keyCode;if(!a.metaKey&&a.ctrlKey)a.metaKey=a.ctrlKey;if(!a.which&&a.button!==w)a.which=a.button&1?1:a.button&2?3:a.button&4?2:0;return a},guid:1E8,proxy:c.proxy,special:{ready:{setup:c.bindReady,teardown:c.noop},live:{add:function(a){c.event.add(this,a.origType,c.extend({},a,{handler:oa}))},remove:function(a){var b=true,d=a.origType.replace(O,"");c.each(c.data(this,
+"events").live||[],function(){if(d===this.origType.replace(O,""))return b=false});b&&c.event.remove(this,a.origType,oa)}},beforeunload:{setup:function(a,b,d){if(this.setInterval)this.onbeforeunload=d;return false},teardown:function(a,b){if(this.onbeforeunload===b)this.onbeforeunload=null}}}};var Ca=s.removeEventListener?function(a,b,d){a.removeEventListener(b,d,false)}:function(a,b,d){a.detachEvent("on"+b,d)};c.Event=function(a){if(!this.preventDefault)return new c.Event(a);if(a&&a.type){this.originalEvent=
+a;this.type=a.type}else this.type=a;this.timeStamp=J();this[G]=true};c.Event.prototype={preventDefault:function(){this.isDefaultPrevented=Z;var a=this.originalEvent;if(a){a.preventDefault&&a.preventDefault();a.returnValue=false}},stopPropagation:function(){this.isPropagationStopped=Z;var a=this.originalEvent;if(a){a.stopPropagation&&a.stopPropagation();a.cancelBubble=true}},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=Z;this.stopPropagation()},isDefaultPrevented:Y,isPropagationStopped:Y,
+isImmediatePropagationStopped:Y};var Da=function(a){var b=a.relatedTarget;try{for(;b&&b!==this;)b=b.parentNode;if(b!==this){a.type=a.data;c.event.handle.apply(this,arguments)}}catch(d){}},Ea=function(a){a.type=a.data;c.event.handle.apply(this,arguments)};c.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(a,b){c.event.special[a]={setup:function(d){c.event.add(this,b,d&&d.selector?Ea:Da,a)},teardown:function(d){c.event.remove(this,b,d&&d.selector?Ea:Da)}}});if(!c.support.submitBubbles)c.event.special.submit=
+{setup:function(){if(this.nodeName.toLowerCase()!=="form"){c.event.add(this,"click.specialSubmit",function(a){var b=a.target,d=b.type;if((d==="submit"||d==="image")&&c(b).closest("form").length)return na("submit",this,arguments)});c.event.add(this,"keypress.specialSubmit",function(a){var b=a.target,d=b.type;if((d==="text"||d==="password")&&c(b).closest("form").length&&a.keyCode===13)return na("submit",this,arguments)})}else return false},teardown:function(){c.event.remove(this,".specialSubmit")}};
+if(!c.support.changeBubbles){var da=/textarea|input|select/i,ea,Fa=function(a){var b=a.type,d=a.value;if(b==="radio"||b==="checkbox")d=a.checked;else if(b==="select-multiple")d=a.selectedIndex>-1?c.map(a.options,function(f){return f.selected}).join("-"):"";else if(a.nodeName.toLowerCase()==="select")d=a.selectedIndex;return d},fa=function(a,b){var d=a.target,f,e;if(!(!da.test(d.nodeName)||d.readOnly)){f=c.data(d,"_change_data");e=Fa(d);if(a.type!=="focusout"||d.type!=="radio")c.data(d,"_change_data",
+e);if(!(f===w||e===f))if(f!=null||e){a.type="change";return c.event.trigger(a,b,d)}}};c.event.special.change={filters:{focusout:fa,click:function(a){var b=a.target,d=b.type;if(d==="radio"||d==="checkbox"||b.nodeName.toLowerCase()==="select")return fa.call(this,a)},keydown:function(a){var b=a.target,d=b.type;if(a.keyCode===13&&b.nodeName.toLowerCase()!=="textarea"||a.keyCode===32&&(d==="checkbox"||d==="radio")||d==="select-multiple")return fa.call(this,a)},beforeactivate:function(a){a=a.target;c.data(a,
+"_change_data",Fa(a))}},setup:function(){if(this.type==="file")return false;for(var a in ea)c.event.add(this,a+".specialChange",ea[a]);return da.test(this.nodeName)},teardown:function(){c.event.remove(this,".specialChange");return da.test(this.nodeName)}};ea=c.event.special.change.filters}s.addEventListener&&c.each({focus:"focusin",blur:"focusout"},function(a,b){function d(f){f=c.event.fix(f);f.type=b;return c.event.handle.call(this,f)}c.event.special[b]={setup:function(){this.addEventListener(a,
+d,true)},teardown:function(){this.removeEventListener(a,d,true)}}});c.each(["bind","one"],function(a,b){c.fn[b]=function(d,f,e){if(typeof d==="object"){for(var j in d)this[b](j,f,d[j],e);return this}if(c.isFunction(f)){e=f;f=w}var i=b==="one"?c.proxy(e,function(k){c(this).unbind(k,i);return e.apply(this,arguments)}):e;if(d==="unload"&&b!=="one")this.one(d,f,e);else{j=0;for(var o=this.length;j<o;j++)c.event.add(this[j],d,i,f)}return this}});c.fn.extend({unbind:function(a,b){if(typeof a==="object"&&
+!a.preventDefault)for(var d in a)this.unbind(d,a[d]);else{d=0;for(var f=this.length;d<f;d++)c.event.remove(this[d],a,b)}return this},delegate:function(a,b,d,f){return this.live(b,d,f,a)},undelegate:function(a,b,d){return arguments.length===0?this.unbind("live"):this.die(b,null,d,a)},trigger:function(a,b){return this.each(function(){c.event.trigger(a,b,this)})},triggerHandler:function(a,b){if(this[0]){a=c.Event(a);a.preventDefault();a.stopPropagation();c.event.trigger(a,b,this[0]);return a.result}},
+toggle:function(a){for(var b=arguments,d=1;d<b.length;)c.proxy(a,b[d++]);return this.click(c.proxy(a,function(f){var e=(c.data(this,"lastToggle"+a.guid)||0)%d;c.data(this,"lastToggle"+a.guid,e+1);f.preventDefault();return b[e].apply(this,arguments)||false}))},hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)}});var Ga={focus:"focusin",blur:"focusout",mouseenter:"mouseover",mouseleave:"mouseout"};c.each(["live","die"],function(a,b){c.fn[b]=function(d,f,e,j){var i,o=0,k,n,r=j||this.selector,
+u=j?this:c(this.context);if(c.isFunction(f)){e=f;f=w}for(d=(d||"").split(" ");(i=d[o++])!=null;){j=O.exec(i);k="";if(j){k=j[0];i=i.replace(O,"")}if(i==="hover")d.push("mouseenter"+k,"mouseleave"+k);else{n=i;if(i==="focus"||i==="blur"){d.push(Ga[i]+k);i+=k}else i=(Ga[i]||i)+k;b==="live"?u.each(function(){c.event.add(this,pa(i,r),{data:f,selector:r,handler:e,origType:i,origHandler:e,preType:n})}):u.unbind(pa(i,r),e)}}return this}});c.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error".split(" "),
+function(a,b){c.fn[b]=function(d){return d?this.bind(b,d):this.trigger(b)};if(c.attrFn)c.attrFn[b]=true});A.attachEvent&&!A.addEventListener&&A.attachEvent("onunload",function(){for(var a in c.cache)if(c.cache[a].handle)try{c.event.remove(c.cache[a].handle.elem)}catch(b){}});(function(){function a(g){for(var h="",l,m=0;g[m];m++){l=g[m];if(l.nodeType===3||l.nodeType===4)h+=l.nodeValue;else if(l.nodeType!==8)h+=a(l.childNodes)}return h}function b(g,h,l,m,q,p){q=0;for(var v=m.length;q<v;q++){var t=m[q];
+if(t){t=t[g];for(var y=false;t;){if(t.sizcache===l){y=m[t.sizset];break}if(t.nodeType===1&&!p){t.sizcache=l;t.sizset=q}if(t.nodeName.toLowerCase()===h){y=t;break}t=t[g]}m[q]=y}}}function d(g,h,l,m,q,p){q=0;for(var v=m.length;q<v;q++){var t=m[q];if(t){t=t[g];for(var y=false;t;){if(t.sizcache===l){y=m[t.sizset];break}if(t.nodeType===1){if(!p){t.sizcache=l;t.sizset=q}if(typeof h!=="string"){if(t===h){y=true;break}}else if(k.filter(h,[t]).length>0){y=t;break}}t=t[g]}m[q]=y}}}var f=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
+e=0,j=Object.prototype.toString,i=false,o=true;[0,0].sort(function(){o=false;return 0});var k=function(g,h,l,m){l=l||[];var q=h=h||s;if(h.nodeType!==1&&h.nodeType!==9)return[];if(!g||typeof g!=="string")return l;for(var p=[],v,t,y,S,H=true,M=x(h),I=g;(f.exec(""),v=f.exec(I))!==null;){I=v[3];p.push(v[1]);if(v[2]){S=v[3];break}}if(p.length>1&&r.exec(g))if(p.length===2&&n.relative[p[0]])t=ga(p[0]+p[1],h);else for(t=n.relative[p[0]]?[h]:k(p.shift(),h);p.length;){g=p.shift();if(n.relative[g])g+=p.shift();
+t=ga(g,t)}else{if(!m&&p.length>1&&h.nodeType===9&&!M&&n.match.ID.test(p[0])&&!n.match.ID.test(p[p.length-1])){v=k.find(p.shift(),h,M);h=v.expr?k.filter(v.expr,v.set)[0]:v.set[0]}if(h){v=m?{expr:p.pop(),set:z(m)}:k.find(p.pop(),p.length===1&&(p[0]==="~"||p[0]==="+")&&h.parentNode?h.parentNode:h,M);t=v.expr?k.filter(v.expr,v.set):v.set;if(p.length>0)y=z(t);else H=false;for(;p.length;){var D=p.pop();v=D;if(n.relative[D])v=p.pop();else D="";if(v==null)v=h;n.relative[D](y,v,M)}}else y=[]}y||(y=t);y||k.error(D||
+g);if(j.call(y)==="[object Array]")if(H)if(h&&h.nodeType===1)for(g=0;y[g]!=null;g++){if(y[g]&&(y[g]===true||y[g].nodeType===1&&E(h,y[g])))l.push(t[g])}else for(g=0;y[g]!=null;g++)y[g]&&y[g].nodeType===1&&l.push(t[g]);else l.push.apply(l,y);else z(y,l);if(S){k(S,q,l,m);k.uniqueSort(l)}return l};k.uniqueSort=function(g){if(B){i=o;g.sort(B);if(i)for(var h=1;h<g.length;h++)g[h]===g[h-1]&&g.splice(h--,1)}return g};k.matches=function(g,h){return k(g,null,null,h)};k.find=function(g,h,l){var m,q;if(!g)return[];
+for(var p=0,v=n.order.length;p<v;p++){var t=n.order[p];if(q=n.leftMatch[t].exec(g)){var y=q[1];q.splice(1,1);if(y.substr(y.length-1)!=="\\"){q[1]=(q[1]||"").replace(/\\/g,"");m=n.find[t](q,h,l);if(m!=null){g=g.replace(n.match[t],"");break}}}}m||(m=h.getElementsByTagName("*"));return{set:m,expr:g}};k.filter=function(g,h,l,m){for(var q=g,p=[],v=h,t,y,S=h&&h[0]&&x(h[0]);g&&h.length;){for(var H in n.filter)if((t=n.leftMatch[H].exec(g))!=null&&t[2]){var M=n.filter[H],I,D;D=t[1];y=false;t.splice(1,1);if(D.substr(D.length-
+1)!=="\\"){if(v===p)p=[];if(n.preFilter[H])if(t=n.preFilter[H](t,v,l,p,m,S)){if(t===true)continue}else y=I=true;if(t)for(var U=0;(D=v[U])!=null;U++)if(D){I=M(D,t,U,v);var Ha=m^!!I;if(l&&I!=null)if(Ha)y=true;else v[U]=false;else if(Ha){p.push(D);y=true}}if(I!==w){l||(v=p);g=g.replace(n.match[H],"");if(!y)return[];break}}}if(g===q)if(y==null)k.error(g);else break;q=g}return v};k.error=function(g){throw"Syntax error, unrecognized expression: "+g;};var n=k.selectors={order:["ID","NAME","TAG"],match:{ID:/#((?:[\w\u00c0-\uFFFF-]|\\.)+)/,
+CLASS:/\.((?:[\w\u00c0-\uFFFF-]|\\.)+)/,NAME:/\[name=['"]*((?:[\w\u00c0-\uFFFF-]|\\.)+)['"]*\]/,ATTR:/\[\s*((?:[\w\u00c0-\uFFFF-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/,TAG:/^((?:[\w\u00c0-\uFFFF\*-]|\\.)+)/,CHILD:/:(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?/,POS:/:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)/,PSEUDO:/:((?:[\w\u00c0-\uFFFF-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/},leftMatch:{},attrMap:{"class":"className","for":"htmlFor"},attrHandle:{href:function(g){return g.getAttribute("href")}},
+relative:{"+":function(g,h){var l=typeof h==="string",m=l&&!/\W/.test(h);l=l&&!m;if(m)h=h.toLowerCase();m=0;for(var q=g.length,p;m<q;m++)if(p=g[m]){for(;(p=p.previousSibling)&&p.nodeType!==1;);g[m]=l||p&&p.nodeName.toLowerCase()===h?p||false:p===h}l&&k.filter(h,g,true)},">":function(g,h){var l=typeof h==="string";if(l&&!/\W/.test(h)){h=h.toLowerCase();for(var m=0,q=g.length;m<q;m++){var p=g[m];if(p){l=p.parentNode;g[m]=l.nodeName.toLowerCase()===h?l:false}}}else{m=0;for(q=g.length;m<q;m++)if(p=g[m])g[m]=
+l?p.parentNode:p.parentNode===h;l&&k.filter(h,g,true)}},"":function(g,h,l){var m=e++,q=d;if(typeof h==="string"&&!/\W/.test(h)){var p=h=h.toLowerCase();q=b}q("parentNode",h,m,g,p,l)},"~":function(g,h,l){var m=e++,q=d;if(typeof h==="string"&&!/\W/.test(h)){var p=h=h.toLowerCase();q=b}q("previousSibling",h,m,g,p,l)}},find:{ID:function(g,h,l){if(typeof h.getElementById!=="undefined"&&!l)return(g=h.getElementById(g[1]))?[g]:[]},NAME:function(g,h){if(typeof h.getElementsByName!=="undefined"){var l=[];
+h=h.getElementsByName(g[1]);for(var m=0,q=h.length;m<q;m++)h[m].getAttribute("name")===g[1]&&l.push(h[m]);return l.length===0?null:l}},TAG:function(g,h){return h.getElementsByTagName(g[1])}},preFilter:{CLASS:function(g,h,l,m,q,p){g=" "+g[1].replace(/\\/g,"")+" ";if(p)return g;p=0;for(var v;(v=h[p])!=null;p++)if(v)if(q^(v.className&&(" "+v.className+" ").replace(/[\t\n]/g," ").indexOf(g)>=0))l||m.push(v);else if(l)h[p]=false;return false},ID:function(g){return g[1].replace(/\\/g,"")},TAG:function(g){return g[1].toLowerCase()},
+CHILD:function(g){if(g[1]==="nth"){var h=/(-?)(\d*)n((?:\+|-)?\d*)/.exec(g[2]==="even"&&"2n"||g[2]==="odd"&&"2n+1"||!/\D/.test(g[2])&&"0n+"+g[2]||g[2]);g[2]=h[1]+(h[2]||1)-0;g[3]=h[3]-0}g[0]=e++;return g},ATTR:function(g,h,l,m,q,p){h=g[1].replace(/\\/g,"");if(!p&&n.attrMap[h])g[1]=n.attrMap[h];if(g[2]==="~=")g[4]=" "+g[4]+" ";return g},PSEUDO:function(g,h,l,m,q){if(g[1]==="not")if((f.exec(g[3])||"").length>1||/^\w/.test(g[3]))g[3]=k(g[3],null,null,h);else{g=k.filter(g[3],h,l,true^q);l||m.push.apply(m,
+g);return false}else if(n.match.POS.test(g[0])||n.match.CHILD.test(g[0]))return true;return g},POS:function(g){g.unshift(true);return g}},filters:{enabled:function(g){return g.disabled===false&&g.type!=="hidden"},disabled:function(g){return g.disabled===true},checked:function(g){return g.checked===true},selected:function(g){return g.selected===true},parent:function(g){return!!g.firstChild},empty:function(g){return!g.firstChild},has:function(g,h,l){return!!k(l[3],g).length},header:function(g){return/h\d/i.test(g.nodeName)},
+text:function(g){return"text"===g.type},radio:function(g){return"radio"===g.type},checkbox:function(g){return"checkbox"===g.type},file:function(g){return"file"===g.type},password:function(g){return"password"===g.type},submit:function(g){return"submit"===g.type},image:function(g){return"image"===g.type},reset:function(g){return"reset"===g.type},button:function(g){return"button"===g.type||g.nodeName.toLowerCase()==="button"},input:function(g){return/input|select|textarea|button/i.test(g.nodeName)}},
+setFilters:{first:function(g,h){return h===0},last:function(g,h,l,m){return h===m.length-1},even:function(g,h){return h%2===0},odd:function(g,h){return h%2===1},lt:function(g,h,l){return h<l[3]-0},gt:function(g,h,l){return h>l[3]-0},nth:function(g,h,l){return l[3]-0===h},eq:function(g,h,l){return l[3]-0===h}},filter:{PSEUDO:function(g,h,l,m){var q=h[1],p=n.filters[q];if(p)return p(g,l,h,m);else if(q==="contains")return(g.textContent||g.innerText||a([g])||"").indexOf(h[3])>=0;else if(q==="not"){h=
+h[3];l=0;for(m=h.length;l<m;l++)if(h[l]===g)return false;return true}else k.error("Syntax error, unrecognized expression: "+q)},CHILD:function(g,h){var l=h[1],m=g;switch(l){case "only":case "first":for(;m=m.previousSibling;)if(m.nodeType===1)return false;if(l==="first")return true;m=g;case "last":for(;m=m.nextSibling;)if(m.nodeType===1)return false;return true;case "nth":l=h[2];var q=h[3];if(l===1&&q===0)return true;h=h[0];var p=g.parentNode;if(p&&(p.sizcache!==h||!g.nodeIndex)){var v=0;for(m=p.firstChild;m;m=
+m.nextSibling)if(m.nodeType===1)m.nodeIndex=++v;p.sizcache=h}g=g.nodeIndex-q;return l===0?g===0:g%l===0&&g/l>=0}},ID:function(g,h){return g.nodeType===1&&g.getAttribute("id")===h},TAG:function(g,h){return h==="*"&&g.nodeType===1||g.nodeName.toLowerCase()===h},CLASS:function(g,h){return(" "+(g.className||g.getAttribute("class"))+" ").indexOf(h)>-1},ATTR:function(g,h){var l=h[1];g=n.attrHandle[l]?n.attrHandle[l](g):g[l]!=null?g[l]:g.getAttribute(l);l=g+"";var m=h[2];h=h[4];return g==null?m==="!=":m===
+"="?l===h:m==="*="?l.indexOf(h)>=0:m==="~="?(" "+l+" ").indexOf(h)>=0:!h?l&&g!==false:m==="!="?l!==h:m==="^="?l.indexOf(h)===0:m==="$="?l.substr(l.length-h.length)===h:m==="|="?l===h||l.substr(0,h.length+1)===h+"-":false},POS:function(g,h,l,m){var q=n.setFilters[h[2]];if(q)return q(g,l,h,m)}}},r=n.match.POS;for(var u in n.match){n.match[u]=new RegExp(n.match[u].source+/(?![^\[]*\])(?![^\(]*\))/.source);n.leftMatch[u]=new RegExp(/(^(?:.|\r|\n)*?)/.source+n.match[u].source.replace(/\\(\d+)/g,function(g,
+h){return"\\"+(h-0+1)}))}var z=function(g,h){g=Array.prototype.slice.call(g,0);if(h){h.push.apply(h,g);return h}return g};try{Array.prototype.slice.call(s.documentElement.childNodes,0)}catch(C){z=function(g,h){h=h||[];if(j.call(g)==="[object Array]")Array.prototype.push.apply(h,g);else if(typeof g.length==="number")for(var l=0,m=g.length;l<m;l++)h.push(g[l]);else for(l=0;g[l];l++)h.push(g[l]);return h}}var B;if(s.documentElement.compareDocumentPosition)B=function(g,h){if(!g.compareDocumentPosition||
+!h.compareDocumentPosition){if(g==h)i=true;return g.compareDocumentPosition?-1:1}g=g.compareDocumentPosition(h)&4?-1:g===h?0:1;if(g===0)i=true;return g};else if("sourceIndex"in s.documentElement)B=function(g,h){if(!g.sourceIndex||!h.sourceIndex){if(g==h)i=true;return g.sourceIndex?-1:1}g=g.sourceIndex-h.sourceIndex;if(g===0)i=true;return g};else if(s.createRange)B=function(g,h){if(!g.ownerDocument||!h.ownerDocument){if(g==h)i=true;return g.ownerDocument?-1:1}var l=g.ownerDocument.createRange(),m=
+h.ownerDocument.createRange();l.setStart(g,0);l.setEnd(g,0);m.setStart(h,0);m.setEnd(h,0);g=l.compareBoundaryPoints(Range.START_TO_END,m);if(g===0)i=true;return g};(function(){var g=s.createElement("div"),h="script"+(new Date).getTime();g.innerHTML="<a name='"+h+"'/>";var l=s.documentElement;l.insertBefore(g,l.firstChild);if(s.getElementById(h)){n.find.ID=function(m,q,p){if(typeof q.getElementById!=="undefined"&&!p)return(q=q.getElementById(m[1]))?q.id===m[1]||typeof q.getAttributeNode!=="undefined"&&
+q.getAttributeNode("id").nodeValue===m[1]?[q]:w:[]};n.filter.ID=function(m,q){var p=typeof m.getAttributeNode!=="undefined"&&m.getAttributeNode("id");return m.nodeType===1&&p&&p.nodeValue===q}}l.removeChild(g);l=g=null})();(function(){var g=s.createElement("div");g.appendChild(s.createComment(""));if(g.getElementsByTagName("*").length>0)n.find.TAG=function(h,l){l=l.getElementsByTagName(h[1]);if(h[1]==="*"){h=[];for(var m=0;l[m];m++)l[m].nodeType===1&&h.push(l[m]);l=h}return l};g.innerHTML="<a href='#'></a>";
+if(g.firstChild&&typeof g.firstChild.getAttribute!=="undefined"&&g.firstChild.getAttribute("href")!=="#")n.attrHandle.href=function(h){return h.getAttribute("href",2)};g=null})();s.querySelectorAll&&function(){var g=k,h=s.createElement("div");h.innerHTML="<p class='TEST'></p>";if(!(h.querySelectorAll&&h.querySelectorAll(".TEST").length===0)){k=function(m,q,p,v){q=q||s;if(!v&&q.nodeType===9&&!x(q))try{return z(q.querySelectorAll(m),p)}catch(t){}return g(m,q,p,v)};for(var l in g)k[l]=g[l];h=null}}();
+(function(){var g=s.createElement("div");g.innerHTML="<div class='test e'></div><div class='test'></div>";if(!(!g.getElementsByClassName||g.getElementsByClassName("e").length===0)){g.lastChild.className="e";if(g.getElementsByClassName("e").length!==1){n.order.splice(1,0,"CLASS");n.find.CLASS=function(h,l,m){if(typeof l.getElementsByClassName!=="undefined"&&!m)return l.getElementsByClassName(h[1])};g=null}}})();var E=s.compareDocumentPosition?function(g,h){return!!(g.compareDocumentPosition(h)&16)}:
+function(g,h){return g!==h&&(g.contains?g.contains(h):true)},x=function(g){return(g=(g?g.ownerDocument||g:0).documentElement)?g.nodeName!=="HTML":false},ga=function(g,h){var l=[],m="",q;for(h=h.nodeType?[h]:h;q=n.match.PSEUDO.exec(g);){m+=q[0];g=g.replace(n.match.PSEUDO,"")}g=n.relative[g]?g+"*":g;q=0;for(var p=h.length;q<p;q++)k(g,h[q],l);return k.filter(m,l)};c.find=k;c.expr=k.selectors;c.expr[":"]=c.expr.filters;c.unique=k.uniqueSort;c.text=a;c.isXMLDoc=x;c.contains=E})();var eb=/Until$/,fb=/^(?:parents|prevUntil|prevAll)/,
+gb=/,/;R=Array.prototype.slice;var Ia=function(a,b,d){if(c.isFunction(b))return c.grep(a,function(e,j){return!!b.call(e,j,e)===d});else if(b.nodeType)return c.grep(a,function(e){return e===b===d});else if(typeof b==="string"){var f=c.grep(a,function(e){return e.nodeType===1});if(Ua.test(b))return c.filter(b,f,!d);else b=c.filter(b,f)}return c.grep(a,function(e){return c.inArray(e,b)>=0===d})};c.fn.extend({find:function(a){for(var b=this.pushStack("","find",a),d=0,f=0,e=this.length;f<e;f++){d=b.length;
+c.find(a,this[f],b);if(f>0)for(var j=d;j<b.length;j++)for(var i=0;i<d;i++)if(b[i]===b[j]){b.splice(j--,1);break}}return b},has:function(a){var b=c(a);return this.filter(function(){for(var d=0,f=b.length;d<f;d++)if(c.contains(this,b[d]))return true})},not:function(a){return this.pushStack(Ia(this,a,false),"not",a)},filter:function(a){return this.pushStack(Ia(this,a,true),"filter",a)},is:function(a){return!!a&&c.filter(a,this).length>0},closest:function(a,b){if(c.isArray(a)){var d=[],f=this[0],e,j=
+{},i;if(f&&a.length){e=0;for(var o=a.length;e<o;e++){i=a[e];j[i]||(j[i]=c.expr.match.POS.test(i)?c(i,b||this.context):i)}for(;f&&f.ownerDocument&&f!==b;){for(i in j){e=j[i];if(e.jquery?e.index(f)>-1:c(f).is(e)){d.push({selector:i,elem:f});delete j[i]}}f=f.parentNode}}return d}var k=c.expr.match.POS.test(a)?c(a,b||this.context):null;return this.map(function(n,r){for(;r&&r.ownerDocument&&r!==b;){if(k?k.index(r)>-1:c(r).is(a))return r;r=r.parentNode}return null})},index:function(a){if(!a||typeof a===
+"string")return c.inArray(this[0],a?c(a):this.parent().children());return c.inArray(a.jquery?a[0]:a,this)},add:function(a,b){a=typeof a==="string"?c(a,b||this.context):c.makeArray(a);b=c.merge(this.get(),a);return this.pushStack(qa(a[0])||qa(b[0])?b:c.unique(b))},andSelf:function(){return this.add(this.prevObject)}});c.each({parent:function(a){return(a=a.parentNode)&&a.nodeType!==11?a:null},parents:function(a){return c.dir(a,"parentNode")},parentsUntil:function(a,b,d){return c.dir(a,"parentNode",
+d)},next:function(a){return c.nth(a,2,"nextSibling")},prev:function(a){return c.nth(a,2,"previousSibling")},nextAll:function(a){return c.dir(a,"nextSibling")},prevAll:function(a){return c.dir(a,"previousSibling")},nextUntil:function(a,b,d){return c.dir(a,"nextSibling",d)},prevUntil:function(a,b,d){return c.dir(a,"previousSibling",d)},siblings:function(a){return c.sibling(a.parentNode.firstChild,a)},children:function(a){return c.sibling(a.firstChild)},contents:function(a){return c.nodeName(a,"iframe")?
+a.contentDocument||a.contentWindow.document:c.makeArray(a.childNodes)}},function(a,b){c.fn[a]=function(d,f){var e=c.map(this,b,d);eb.test(a)||(f=d);if(f&&typeof f==="string")e=c.filter(f,e);e=this.length>1?c.unique(e):e;if((this.length>1||gb.test(f))&&fb.test(a))e=e.reverse();return this.pushStack(e,a,R.call(arguments).join(","))}});c.extend({filter:function(a,b,d){if(d)a=":not("+a+")";return c.find.matches(a,b)},dir:function(a,b,d){var f=[];for(a=a[b];a&&a.nodeType!==9&&(d===w||a.nodeType!==1||!c(a).is(d));){a.nodeType===
+1&&f.push(a);a=a[b]}return f},nth:function(a,b,d){b=b||1;for(var f=0;a;a=a[d])if(a.nodeType===1&&++f===b)break;return a},sibling:function(a,b){for(var d=[];a;a=a.nextSibling)a.nodeType===1&&a!==b&&d.push(a);return d}});var Ja=/ jQuery\d+="(?:\d+|null)"/g,V=/^\s+/,Ka=/(<([\w:]+)[^>]*?)\/>/g,hb=/^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i,La=/<([\w:]+)/,ib=/<tbody/i,jb=/<|&#?\w+;/,ta=/<script|<object|<embed|<option|<style/i,ua=/checked\s*(?:[^=]|=\s*.checked.)/i,Ma=function(a,b,d){return hb.test(d)?
+a:b+"></"+d+">"},F={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],area:[1,"<map>","</map>"],_default:[0,"",""]};F.optgroup=F.option;F.tbody=F.tfoot=F.colgroup=F.caption=F.thead;F.th=F.td;if(!c.support.htmlSerialize)F._default=[1,"div<div>","</div>"];c.fn.extend({text:function(a){if(c.isFunction(a))return this.each(function(b){var d=
+c(this);d.text(a.call(this,b,d.text()))});if(typeof a!=="object"&&a!==w)return this.empty().append((this[0]&&this[0].ownerDocument||s).createTextNode(a));return c.text(this)},wrapAll:function(a){if(c.isFunction(a))return this.each(function(d){c(this).wrapAll(a.call(this,d))});if(this[0]){var b=c(a,this[0].ownerDocument).eq(0).clone(true);this[0].parentNode&&b.insertBefore(this[0]);b.map(function(){for(var d=this;d.firstChild&&d.firstChild.nodeType===1;)d=d.firstChild;return d}).append(this)}return this},
+wrapInner:function(a){if(c.isFunction(a))return this.each(function(b){c(this).wrapInner(a.call(this,b))});return this.each(function(){var b=c(this),d=b.contents();d.length?d.wrapAll(a):b.append(a)})},wrap:function(a){return this.each(function(){c(this).wrapAll(a)})},unwrap:function(){return this.parent().each(function(){c.nodeName(this,"body")||c(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.appendChild(a)})},
+prepend:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b,this)});else if(arguments.length){var a=c(arguments[0]);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b,
+this.nextSibling)});else if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,c(arguments[0]).toArray());return a}},remove:function(a,b){for(var d=0,f;(f=this[d])!=null;d++)if(!a||c.filter(a,[f]).length){if(!b&&f.nodeType===1){c.cleanData(f.getElementsByTagName("*"));c.cleanData([f])}f.parentNode&&f.parentNode.removeChild(f)}return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++)for(b.nodeType===1&&c.cleanData(b.getElementsByTagName("*"));b.firstChild;)b.removeChild(b.firstChild);
+return this},clone:function(a){var b=this.map(function(){if(!c.support.noCloneEvent&&!c.isXMLDoc(this)){var d=this.outerHTML,f=this.ownerDocument;if(!d){d=f.createElement("div");d.appendChild(this.cloneNode(true));d=d.innerHTML}return c.clean([d.replace(Ja,"").replace(/=([^="'>\s]+\/)>/g,'="$1">').replace(V,"")],f)[0]}else return this.cloneNode(true)});if(a===true){ra(this,b);ra(this.find("*"),b.find("*"))}return b},html:function(a){if(a===w)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(Ja,
+""):null;else if(typeof a==="string"&&!ta.test(a)&&(c.support.leadingWhitespace||!V.test(a))&&!F[(La.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(Ka,Ma);try{for(var b=0,d=this.length;b<d;b++)if(this[b].nodeType===1){c.cleanData(this[b].getElementsByTagName("*"));this[b].innerHTML=a}}catch(f){this.empty().append(a)}}else c.isFunction(a)?this.each(function(e){var j=c(this),i=j.html();j.empty().append(function(){return a.call(this,e,i)})}):this.empty().append(a);return this},replaceWith:function(a){if(this[0]&&
+this[0].parentNode){if(c.isFunction(a))return this.each(function(b){var d=c(this),f=d.html();d.replaceWith(a.call(this,b,f))});if(typeof a!=="string")a=c(a).detach();return this.each(function(){var b=this.nextSibling,d=this.parentNode;c(this).remove();b?c(b).before(a):c(d).append(a)})}else return this.pushStack(c(c.isFunction(a)?a():a),"replaceWith",a)},detach:function(a){return this.remove(a,true)},domManip:function(a,b,d){function f(u){return c.nodeName(u,"table")?u.getElementsByTagName("tbody")[0]||
+u.appendChild(u.ownerDocument.createElement("tbody")):u}var e,j,i=a[0],o=[],k;if(!c.support.checkClone&&arguments.length===3&&typeof i==="string"&&ua.test(i))return this.each(function(){c(this).domManip(a,b,d,true)});if(c.isFunction(i))return this.each(function(u){var z=c(this);a[0]=i.call(this,u,b?z.html():w);z.domManip(a,b,d)});if(this[0]){e=i&&i.parentNode;e=c.support.parentNode&&e&&e.nodeType===11&&e.childNodes.length===this.length?{fragment:e}:sa(a,this,o);k=e.fragment;if(j=k.childNodes.length===
+1?(k=k.firstChild):k.firstChild){b=b&&c.nodeName(j,"tr");for(var n=0,r=this.length;n<r;n++)d.call(b?f(this[n],j):this[n],n>0||e.cacheable||this.length>1?k.cloneNode(true):k)}o.length&&c.each(o,Qa)}return this}});c.fragments={};c.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){c.fn[a]=function(d){var f=[];d=c(d);var e=this.length===1&&this[0].parentNode;if(e&&e.nodeType===11&&e.childNodes.length===1&&d.length===1){d[b](this[0]);
+return this}else{e=0;for(var j=d.length;e<j;e++){var i=(e>0?this.clone(true):this).get();c.fn[b].apply(c(d[e]),i);f=f.concat(i)}return this.pushStack(f,a,d.selector)}}});c.extend({clean:function(a,b,d,f){b=b||s;if(typeof b.createElement==="undefined")b=b.ownerDocument||b[0]&&b[0].ownerDocument||s;for(var e=[],j=0,i;(i=a[j])!=null;j++){if(typeof i==="number")i+="";if(i){if(typeof i==="string"&&!jb.test(i))i=b.createTextNode(i);else if(typeof i==="string"){i=i.replace(Ka,Ma);var o=(La.exec(i)||["",
+""])[1].toLowerCase(),k=F[o]||F._default,n=k[0],r=b.createElement("div");for(r.innerHTML=k[1]+i+k[2];n--;)r=r.lastChild;if(!c.support.tbody){n=ib.test(i);o=o==="table"&&!n?r.firstChild&&r.firstChild.childNodes:k[1]==="<table>"&&!n?r.childNodes:[];for(k=o.length-1;k>=0;--k)c.nodeName(o[k],"tbody")&&!o[k].childNodes.length&&o[k].parentNode.removeChild(o[k])}!c.support.leadingWhitespace&&V.test(i)&&r.insertBefore(b.createTextNode(V.exec(i)[0]),r.firstChild);i=r.childNodes}if(i.nodeType)e.push(i);else e=
+c.merge(e,i)}}if(d)for(j=0;e[j];j++)if(f&&c.nodeName(e[j],"script")&&(!e[j].type||e[j].type.toLowerCase()==="text/javascript"))f.push(e[j].parentNode?e[j].parentNode.removeChild(e[j]):e[j]);else{e[j].nodeType===1&&e.splice.apply(e,[j+1,0].concat(c.makeArray(e[j].getElementsByTagName("script"))));d.appendChild(e[j])}return e},cleanData:function(a){for(var b,d,f=c.cache,e=c.event.special,j=c.support.deleteExpando,i=0,o;(o=a[i])!=null;i++)if(d=o[c.expando]){b=f[d];if(b.events)for(var k in b.events)e[k]?
+c.event.remove(o,k):Ca(o,k,b.handle);if(j)delete o[c.expando];else o.removeAttribute&&o.removeAttribute(c.expando);delete f[d]}}});var kb=/z-?index|font-?weight|opacity|zoom|line-?height/i,Na=/alpha\([^)]*\)/,Oa=/opacity=([^)]*)/,ha=/float/i,ia=/-([a-z])/ig,lb=/([A-Z])/g,mb=/^-?\d+(?:px)?$/i,nb=/^-?\d/,ob={position:"absolute",visibility:"hidden",display:"block"},pb=["Left","Right"],qb=["Top","Bottom"],rb=s.defaultView&&s.defaultView.getComputedStyle,Pa=c.support.cssFloat?"cssFloat":"styleFloat",ja=
+function(a,b){return b.toUpperCase()};c.fn.css=function(a,b){return X(this,a,b,true,function(d,f,e){if(e===w)return c.curCSS(d,f);if(typeof e==="number"&&!kb.test(f))e+="px";c.style(d,f,e)})};c.extend({style:function(a,b,d){if(!a||a.nodeType===3||a.nodeType===8)return w;if((b==="width"||b==="height")&&parseFloat(d)<0)d=w;var f=a.style||a,e=d!==w;if(!c.support.opacity&&b==="opacity"){if(e){f.zoom=1;b=parseInt(d,10)+""==="NaN"?"":"alpha(opacity="+d*100+")";a=f.filter||c.curCSS(a,"filter")||"";f.filter=
+Na.test(a)?a.replace(Na,b):b}return f.filter&&f.filter.indexOf("opacity=")>=0?parseFloat(Oa.exec(f.filter)[1])/100+"":""}if(ha.test(b))b=Pa;b=b.replace(ia,ja);if(e)f[b]=d;return f[b]},css:function(a,b,d,f){if(b==="width"||b==="height"){var e,j=b==="width"?pb:qb;function i(){e=b==="width"?a.offsetWidth:a.offsetHeight;f!=="border"&&c.each(j,function(){f||(e-=parseFloat(c.curCSS(a,"padding"+this,true))||0);if(f==="margin")e+=parseFloat(c.curCSS(a,"margin"+this,true))||0;else e-=parseFloat(c.curCSS(a,
+"border"+this+"Width",true))||0})}a.offsetWidth!==0?i():c.swap(a,ob,i);return Math.max(0,Math.round(e))}return c.curCSS(a,b,d)},curCSS:function(a,b,d){var f,e=a.style;if(!c.support.opacity&&b==="opacity"&&a.currentStyle){f=Oa.test(a.currentStyle.filter||"")?parseFloat(RegExp.$1)/100+"":"";return f===""?"1":f}if(ha.test(b))b=Pa;if(!d&&e&&e[b])f=e[b];else if(rb){if(ha.test(b))b="float";b=b.replace(lb,"-$1").toLowerCase();e=a.ownerDocument.defaultView;if(!e)return null;if(a=e.getComputedStyle(a,null))f=
+a.getPropertyValue(b);if(b==="opacity"&&f==="")f="1"}else if(a.currentStyle){d=b.replace(ia,ja);f=a.currentStyle[b]||a.currentStyle[d];if(!mb.test(f)&&nb.test(f)){b=e.left;var j=a.runtimeStyle.left;a.runtimeStyle.left=a.currentStyle.left;e.left=d==="fontSize"?"1em":f||0;f=e.pixelLeft+"px";e.left=b;a.runtimeStyle.left=j}}return f},swap:function(a,b,d){var f={};for(var e in b){f[e]=a.style[e];a.style[e]=b[e]}d.call(a);for(e in b)a.style[e]=f[e]}});if(c.expr&&c.expr.filters){c.expr.filters.hidden=function(a){var b=
+a.offsetWidth,d=a.offsetHeight,f=a.nodeName.toLowerCase()==="tr";return b===0&&d===0&&!f?true:b>0&&d>0&&!f?false:c.curCSS(a,"display")==="none"};c.expr.filters.visible=function(a){return!c.expr.filters.hidden(a)}}var sb=J(),tb=/<script(.|\s)*?\/script>/gi,ub=/select|textarea/i,vb=/color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week/i,N=/=\?(&|$)/,ka=/\?/,wb=/(\?|&)_=.*?(&|$)/,xb=/^(\w+:)?\/\/([^\/?#]+)/,yb=/%20/g,zb=c.fn.load;c.fn.extend({load:function(a,b,d){if(typeof a!==
+"string")return zb.call(this,a);else if(!this.length)return this;var f=a.indexOf(" ");if(f>=0){var e=a.slice(f,a.length);a=a.slice(0,f)}f="GET";if(b)if(c.isFunction(b)){d=b;b=null}else if(typeof b==="object"){b=c.param(b,c.ajaxSettings.traditional);f="POST"}var j=this;c.ajax({url:a,type:f,dataType:"html",data:b,complete:function(i,o){if(o==="success"||o==="notmodified")j.html(e?c("<div />").append(i.responseText.replace(tb,"")).find(e):i.responseText);d&&j.each(d,[i.responseText,o,i])}});return this},
+serialize:function(){return c.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?c.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||ub.test(this.nodeName)||vb.test(this.type))}).map(function(a,b){a=c(this).val();return a==null?null:c.isArray(a)?c.map(a,function(d){return{name:b.name,value:d}}):{name:b.name,value:a}}).get()}});c.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),
+function(a,b){c.fn[b]=function(d){return this.bind(b,d)}});c.extend({get:function(a,b,d,f){if(c.isFunction(b)){f=f||d;d=b;b=null}return c.ajax({type:"GET",url:a,data:b,success:d,dataType:f})},getScript:function(a,b){return c.get(a,null,b,"script")},getJSON:function(a,b,d){return c.get(a,b,d,"json")},post:function(a,b,d,f){if(c.isFunction(b)){f=f||d;d=b;b={}}return c.ajax({type:"POST",url:a,data:b,success:d,dataType:f})},ajaxSetup:function(a){c.extend(c.ajaxSettings,a)},ajaxSettings:{url:location.href,
+global:true,type:"GET",contentType:"application/x-www-form-urlencoded",processData:true,async:true,xhr:A.XMLHttpRequest&&(A.location.protocol!=="file:"||!A.ActiveXObject)?function(){return new A.XMLHttpRequest}:function(){try{return new A.ActiveXObject("Microsoft.XMLHTTP")}catch(a){}},accepts:{xml:"application/xml, text/xml",html:"text/html",script:"text/javascript, application/javascript",json:"application/json, text/javascript",text:"text/plain",_default:"*/*"}},lastModified:{},etag:{},ajax:function(a){function b(){e.success&&
+e.success.call(k,o,i,x);e.global&&f("ajaxSuccess",[x,e])}function d(){e.complete&&e.complete.call(k,x,i);e.global&&f("ajaxComplete",[x,e]);e.global&&!--c.active&&c.event.trigger("ajaxStop")}function f(q,p){(e.context?c(e.context):c.event).trigger(q,p)}var e=c.extend(true,{},c.ajaxSettings,a),j,i,o,k=a&&a.context||e,n=e.type.toUpperCase();if(e.data&&e.processData&&typeof e.data!=="string")e.data=c.param(e.data,e.traditional);if(e.dataType==="jsonp"){if(n==="GET")N.test(e.url)||(e.url+=(ka.test(e.url)?
+"&":"?")+(e.jsonp||"callback")+"=?");else if(!e.data||!N.test(e.data))e.data=(e.data?e.data+"&":"")+(e.jsonp||"callback")+"=?";e.dataType="json"}if(e.dataType==="json"&&(e.data&&N.test(e.data)||N.test(e.url))){j=e.jsonpCallback||"jsonp"+sb++;if(e.data)e.data=(e.data+"").replace(N,"="+j+"$1");e.url=e.url.replace(N,"="+j+"$1");e.dataType="script";A[j]=A[j]||function(q){o=q;b();d();A[j]=w;try{delete A[j]}catch(p){}z&&z.removeChild(C)}}if(e.dataType==="script"&&e.cache===null)e.cache=false;if(e.cache===
+false&&n==="GET"){var r=J(),u=e.url.replace(wb,"$1_="+r+"$2");e.url=u+(u===e.url?(ka.test(e.url)?"&":"?")+"_="+r:"")}if(e.data&&n==="GET")e.url+=(ka.test(e.url)?"&":"?")+e.data;e.global&&!c.active++&&c.event.trigger("ajaxStart");r=(r=xb.exec(e.url))&&(r[1]&&r[1]!==location.protocol||r[2]!==location.host);if(e.dataType==="script"&&n==="GET"&&r){var z=s.getElementsByTagName("head")[0]||s.documentElement,C=s.createElement("script");C.src=e.url;if(e.scriptCharset)C.charset=e.scriptCharset;if(!j){var B=
+false;C.onload=C.onreadystatechange=function(){if(!B&&(!this.readyState||this.readyState==="loaded"||this.readyState==="complete")){B=true;b();d();C.onload=C.onreadystatechange=null;z&&C.parentNode&&z.removeChild(C)}}}z.insertBefore(C,z.firstChild);return w}var E=false,x=e.xhr();if(x){e.username?x.open(n,e.url,e.async,e.username,e.password):x.open(n,e.url,e.async);try{if(e.data||a&&a.contentType)x.setRequestHeader("Content-Type",e.contentType);if(e.ifModified){c.lastModified[e.url]&&x.setRequestHeader("If-Modified-Since",
+c.lastModified[e.url]);c.etag[e.url]&&x.setRequestHeader("If-None-Match",c.etag[e.url])}r||x.setRequestHeader("X-Requested-With","XMLHttpRequest");x.setRequestHeader("Accept",e.dataType&&e.accepts[e.dataType]?e.accepts[e.dataType]+", */*":e.accepts._default)}catch(ga){}if(e.beforeSend&&e.beforeSend.call(k,x,e)===false){e.global&&!--c.active&&c.event.trigger("ajaxStop");x.abort();return false}e.global&&f("ajaxSend",[x,e]);var g=x.onreadystatechange=function(q){if(!x||x.readyState===0||q==="abort"){E||
+d();E=true;if(x)x.onreadystatechange=c.noop}else if(!E&&x&&(x.readyState===4||q==="timeout")){E=true;x.onreadystatechange=c.noop;i=q==="timeout"?"timeout":!c.httpSuccess(x)?"error":e.ifModified&&c.httpNotModified(x,e.url)?"notmodified":"success";var p;if(i==="success")try{o=c.httpData(x,e.dataType,e)}catch(v){i="parsererror";p=v}if(i==="success"||i==="notmodified")j||b();else c.handleError(e,x,i,p);d();q==="timeout"&&x.abort();if(e.async)x=null}};try{var h=x.abort;x.abort=function(){x&&h.call(x);
+g("abort")}}catch(l){}e.async&&e.timeout>0&&setTimeout(function(){x&&!E&&g("timeout")},e.timeout);try{x.send(n==="POST"||n==="PUT"||n==="DELETE"?e.data:null)}catch(m){c.handleError(e,x,null,m);d()}e.async||g();return x}},handleError:function(a,b,d,f){if(a.error)a.error.call(a.context||a,b,d,f);if(a.global)(a.context?c(a.context):c.event).trigger("ajaxError",[b,a,f])},active:0,httpSuccess:function(a){try{return!a.status&&location.protocol==="file:"||a.status>=200&&a.status<300||a.status===304||a.status===
+1223||a.status===0}catch(b){}return false},httpNotModified:function(a,b){var d=a.getResponseHeader("Last-Modified"),f=a.getResponseHeader("Etag");if(d)c.lastModified[b]=d;if(f)c.etag[b]=f;return a.status===304||a.status===0},httpData:function(a,b,d){var f=a.getResponseHeader("content-type")||"",e=b==="xml"||!b&&f.indexOf("xml")>=0;a=e?a.responseXML:a.responseText;e&&a.documentElement.nodeName==="parsererror"&&c.error("parsererror");if(d&&d.dataFilter)a=d.dataFilter(a,b);if(typeof a==="string")if(b===
+"json"||!b&&f.indexOf("json")>=0)a=c.parseJSON(a);else if(b==="script"||!b&&f.indexOf("javascript")>=0)c.globalEval(a);return a},param:function(a,b){function d(i,o){if(c.isArray(o))c.each(o,function(k,n){b||/\[\]$/.test(i)?f(i,n):d(i+"["+(typeof n==="object"||c.isArray(n)?k:"")+"]",n)});else!b&&o!=null&&typeof o==="object"?c.each(o,function(k,n){d(i+"["+k+"]",n)}):f(i,o)}function f(i,o){o=c.isFunction(o)?o():o;e[e.length]=encodeURIComponent(i)+"="+encodeURIComponent(o)}var e=[];if(b===w)b=c.ajaxSettings.traditional;
+if(c.isArray(a)||a.jquery)c.each(a,function(){f(this.name,this.value)});else for(var j in a)d(j,a[j]);return e.join("&").replace(yb,"+")}});var la={},Ab=/toggle|show|hide/,Bb=/^([+-]=)?([\d+-.]+)(.*)$/,W,va=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]];c.fn.extend({show:function(a,b){if(a||a===0)return this.animate(K("show",3),a,b);else{a=0;for(b=this.length;a<b;a++){var d=c.data(this[a],"olddisplay");
+this[a].style.display=d||"";if(c.css(this[a],"display")==="none"){d=this[a].nodeName;var f;if(la[d])f=la[d];else{var e=c("<"+d+" />").appendTo("body");f=e.css("display");if(f==="none")f="block";e.remove();la[d]=f}c.data(this[a],"olddisplay",f)}}a=0;for(b=this.length;a<b;a++)this[a].style.display=c.data(this[a],"olddisplay")||"";return this}},hide:function(a,b){if(a||a===0)return this.animate(K("hide",3),a,b);else{a=0;for(b=this.length;a<b;a++){var d=c.data(this[a],"olddisplay");!d&&d!=="none"&&c.data(this[a],
+"olddisplay",c.css(this[a],"display"))}a=0;for(b=this.length;a<b;a++)this[a].style.display="none";return this}},_toggle:c.fn.toggle,toggle:function(a,b){var d=typeof a==="boolean";if(c.isFunction(a)&&c.isFunction(b))this._toggle.apply(this,arguments);else a==null||d?this.each(function(){var f=d?a:c(this).is(":hidden");c(this)[f?"show":"hide"]()}):this.animate(K("toggle",3),a,b);return this},fadeTo:function(a,b,d){return this.filter(":hidden").css("opacity",0).show().end().animate({opacity:b},a,d)},
+animate:function(a,b,d,f){var e=c.speed(b,d,f);if(c.isEmptyObject(a))return this.each(e.complete);return this[e.queue===false?"each":"queue"](function(){var j=c.extend({},e),i,o=this.nodeType===1&&c(this).is(":hidden"),k=this;for(i in a){var n=i.replace(ia,ja);if(i!==n){a[n]=a[i];delete a[i];i=n}if(a[i]==="hide"&&o||a[i]==="show"&&!o)return j.complete.call(this);if((i==="height"||i==="width")&&this.style){j.display=c.css(this,"display");j.overflow=this.style.overflow}if(c.isArray(a[i])){(j.specialEasing=
+j.specialEasing||{})[i]=a[i][1];a[i]=a[i][0]}}if(j.overflow!=null)this.style.overflow="hidden";j.curAnim=c.extend({},a);c.each(a,function(r,u){var z=new c.fx(k,j,r);if(Ab.test(u))z[u==="toggle"?o?"show":"hide":u](a);else{var C=Bb.exec(u),B=z.cur(true)||0;if(C){u=parseFloat(C[2]);var E=C[3]||"px";if(E!=="px"){k.style[r]=(u||1)+E;B=(u||1)/z.cur(true)*B;k.style[r]=B+E}if(C[1])u=(C[1]==="-="?-1:1)*u+B;z.custom(B,u,E)}else z.custom(B,u,"")}});return true})},stop:function(a,b){var d=c.timers;a&&this.queue([]);
+this.each(function(){for(var f=d.length-1;f>=0;f--)if(d[f].elem===this){b&&d[f](true);d.splice(f,1)}});b||this.dequeue();return this}});c.each({slideDown:K("show",1),slideUp:K("hide",1),slideToggle:K("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"}},function(a,b){c.fn[a]=function(d,f){return this.animate(b,d,f)}});c.extend({speed:function(a,b,d){var f=a&&typeof a==="object"?a:{complete:d||!d&&b||c.isFunction(a)&&a,duration:a,easing:d&&b||b&&!c.isFunction(b)&&b};f.duration=c.fx.off?0:typeof f.duration===
+"number"?f.duration:c.fx.speeds[f.duration]||c.fx.speeds._default;f.old=f.complete;f.complete=function(){f.queue!==false&&c(this).dequeue();c.isFunction(f.old)&&f.old.call(this)};return f},easing:{linear:function(a,b,d,f){return d+f*a},swing:function(a,b,d,f){return(-Math.cos(a*Math.PI)/2+0.5)*f+d}},timers:[],fx:function(a,b,d){this.options=b;this.elem=a;this.prop=d;if(!b.orig)b.orig={}}});c.fx.prototype={update:function(){this.options.step&&this.options.step.call(this.elem,this.now,this);(c.fx.step[this.prop]||
+c.fx.step._default)(this);if((this.prop==="height"||this.prop==="width")&&this.elem.style)this.elem.style.display="block"},cur:function(a){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null))return this.elem[this.prop];return(a=parseFloat(c.css(this.elem,this.prop,a)))&&a>-10000?a:parseFloat(c.curCSS(this.elem,this.prop))||0},custom:function(a,b,d){function f(j){return e.step(j)}this.startTime=J();this.start=a;this.end=b;this.unit=d||this.unit||"px";this.now=this.start;
+this.pos=this.state=0;var e=this;f.elem=this.elem;if(f()&&c.timers.push(f)&&!W)W=setInterval(c.fx.tick,13)},show:function(){this.options.orig[this.prop]=c.style(this.elem,this.prop);this.options.show=true;this.custom(this.prop==="width"||this.prop==="height"?1:0,this.cur());c(this.elem).show()},hide:function(){this.options.orig[this.prop]=c.style(this.elem,this.prop);this.options.hide=true;this.custom(this.cur(),0)},step:function(a){var b=J(),d=true;if(a||b>=this.options.duration+this.startTime){this.now=
+this.end;this.pos=this.state=1;this.update();this.options.curAnim[this.prop]=true;for(var f in this.options.curAnim)if(this.options.curAnim[f]!==true)d=false;if(d){if(this.options.display!=null){this.elem.style.overflow=this.options.overflow;a=c.data(this.elem,"olddisplay");this.elem.style.display=a?a:this.options.display;if(c.css(this.elem,"display")==="none")this.elem.style.display="block"}this.options.hide&&c(this.elem).hide();if(this.options.hide||this.options.show)for(var e in this.options.curAnim)c.style(this.elem,
+e,this.options.orig[e]);this.options.complete.call(this.elem)}return false}else{e=b-this.startTime;this.state=e/this.options.duration;a=this.options.easing||(c.easing.swing?"swing":"linear");this.pos=c.easing[this.options.specialEasing&&this.options.specialEasing[this.prop]||a](this.state,e,0,1,this.options.duration);this.now=this.start+(this.end-this.start)*this.pos;this.update()}return true}};c.extend(c.fx,{tick:function(){for(var a=c.timers,b=0;b<a.length;b++)a[b]()||a.splice(b--,1);a.length||
+c.fx.stop()},stop:function(){clearInterval(W);W=null},speeds:{slow:600,fast:200,_default:400},step:{opacity:function(a){c.style(a.elem,"opacity",a.now)},_default:function(a){if(a.elem.style&&a.elem.style[a.prop]!=null)a.elem.style[a.prop]=(a.prop==="width"||a.prop==="height"?Math.max(0,a.now):a.now)+a.unit;else a.elem[a.prop]=a.now}}});if(c.expr&&c.expr.filters)c.expr.filters.animated=function(a){return c.grep(c.timers,function(b){return a===b.elem}).length};c.fn.offset="getBoundingClientRect"in s.documentElement?
+function(a){var b=this[0];if(a)return this.each(function(e){c.offset.setOffset(this,a,e)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return c.offset.bodyOffset(b);var d=b.getBoundingClientRect(),f=b.ownerDocument;b=f.body;f=f.documentElement;return{top:d.top+(self.pageYOffset||c.support.boxModel&&f.scrollTop||b.scrollTop)-(f.clientTop||b.clientTop||0),left:d.left+(self.pageXOffset||c.support.boxModel&&f.scrollLeft||b.scrollLeft)-(f.clientLeft||b.clientLeft||0)}}:function(a){var b=
+this[0];if(a)return this.each(function(r){c.offset.setOffset(this,a,r)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return c.offset.bodyOffset(b);c.offset.initialize();var d=b.offsetParent,f=b,e=b.ownerDocument,j,i=e.documentElement,o=e.body;f=(e=e.defaultView)?e.getComputedStyle(b,null):b.currentStyle;for(var k=b.offsetTop,n=b.offsetLeft;(b=b.parentNode)&&b!==o&&b!==i;){if(c.offset.supportsFixedPosition&&f.position==="fixed")break;j=e?e.getComputedStyle(b,null):b.currentStyle;
+k-=b.scrollTop;n-=b.scrollLeft;if(b===d){k+=b.offsetTop;n+=b.offsetLeft;if(c.offset.doesNotAddBorder&&!(c.offset.doesAddBorderForTableAndCells&&/^t(able|d|h)$/i.test(b.nodeName))){k+=parseFloat(j.borderTopWidth)||0;n+=parseFloat(j.borderLeftWidth)||0}f=d;d=b.offsetParent}if(c.offset.subtractsBorderForOverflowNotVisible&&j.overflow!=="visible"){k+=parseFloat(j.borderTopWidth)||0;n+=parseFloat(j.borderLeftWidth)||0}f=j}if(f.position==="relative"||f.position==="static"){k+=o.offsetTop;n+=o.offsetLeft}if(c.offset.supportsFixedPosition&&
+f.position==="fixed"){k+=Math.max(i.scrollTop,o.scrollTop);n+=Math.max(i.scrollLeft,o.scrollLeft)}return{top:k,left:n}};c.offset={initialize:function(){var a=s.body,b=s.createElement("div"),d,f,e,j=parseFloat(c.curCSS(a,"marginTop",true))||0;c.extend(b.style,{position:"absolute",top:0,left:0,margin:0,border:0,width:"1px",height:"1px",visibility:"hidden"});b.innerHTML="<div style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;'><div></div></div><table style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;' cellpadding='0' cellspacing='0'><tr><td></td></tr></table>";
+a.insertBefore(b,a.firstChild);d=b.firstChild;f=d.firstChild;e=d.nextSibling.firstChild.firstChild;this.doesNotAddBorder=f.offsetTop!==5;this.doesAddBorderForTableAndCells=e.offsetTop===5;f.style.position="fixed";f.style.top="20px";this.supportsFixedPosition=f.offsetTop===20||f.offsetTop===15;f.style.position=f.style.top="";d.style.overflow="hidden";d.style.position="relative";this.subtractsBorderForOverflowNotVisible=f.offsetTop===-5;this.doesNotIncludeMarginInBodyOffset=a.offsetTop!==j;a.removeChild(b);
+c.offset.initialize=c.noop},bodyOffset:function(a){var b=a.offsetTop,d=a.offsetLeft;c.offset.initialize();if(c.offset.doesNotIncludeMarginInBodyOffset){b+=parseFloat(c.curCSS(a,"marginTop",true))||0;d+=parseFloat(c.curCSS(a,"marginLeft",true))||0}return{top:b,left:d}},setOffset:function(a,b,d){if(/static/.test(c.curCSS(a,"position")))a.style.position="relative";var f=c(a),e=f.offset(),j=parseInt(c.curCSS(a,"top",true),10)||0,i=parseInt(c.curCSS(a,"left",true),10)||0;if(c.isFunction(b))b=b.call(a,
+d,e);d={top:b.top-e.top+j,left:b.left-e.left+i};"using"in b?b.using.call(a,d):f.css(d)}};c.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),d=this.offset(),f=/^body|html$/i.test(b[0].nodeName)?{top:0,left:0}:b.offset();d.top-=parseFloat(c.curCSS(a,"marginTop",true))||0;d.left-=parseFloat(c.curCSS(a,"marginLeft",true))||0;f.top+=parseFloat(c.curCSS(b[0],"borderTopWidth",true))||0;f.left+=parseFloat(c.curCSS(b[0],"borderLeftWidth",true))||0;return{top:d.top-
+f.top,left:d.left-f.left}},offsetParent:function(){return this.map(function(){for(var a=this.offsetParent||s.body;a&&!/^body|html$/i.test(a.nodeName)&&c.css(a,"position")==="static";)a=a.offsetParent;return a})}});c.each(["Left","Top"],function(a,b){var d="scroll"+b;c.fn[d]=function(f){var e=this[0],j;if(!e)return null;if(f!==w)return this.each(function(){if(j=wa(this))j.scrollTo(!a?f:c(j).scrollLeft(),a?f:c(j).scrollTop());else this[d]=f});else return(j=wa(e))?"pageXOffset"in j?j[a?"pageYOffset":
+"pageXOffset"]:c.support.boxModel&&j.document.documentElement[d]||j.document.body[d]:e[d]}});c.each(["Height","Width"],function(a,b){var d=b.toLowerCase();c.fn["inner"+b]=function(){return this[0]?c.css(this[0],d,false,"padding"):null};c.fn["outer"+b]=function(f){return this[0]?c.css(this[0],d,false,f?"margin":"border"):null};c.fn[d]=function(f){var e=this[0];if(!e)return f==null?null:this;if(c.isFunction(f))return this.each(function(j){var i=c(this);i[d](f.call(this,j,i[d]()))});return"scrollTo"in
+e&&e.document?e.document.compatMode==="CSS1Compat"&&e.document.documentElement["client"+b]||e.document.body["client"+b]:e.nodeType===9?Math.max(e.documentElement["client"+b],e.body["scroll"+b],e.documentElement["scroll"+b],e.body["offset"+b],e.documentElement["offset"+b]):f===w?c.css(e,d):this.css(d,typeof f==="string"?f:f+"px")}});A.jQuery=A.$=c})(window);
diff --git a/tools/addon-sdk-1.7/examples/annotator/data/list/annotation-list.css b/tools/addon-sdk-1.7/examples/annotator/data/list/annotation-list.css
new file mode 100644
index 0000000..9063682
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/annotator/data/list/annotation-list.css
@@ -0,0 +1,40 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#annotation-list .annotation-details
+ {
+ padding: 10px;
+ margin: 10px;
+ border: solid 3px #EEE;
+ background-color: white;
+ }
+
+#annotation-list .url, .selection-text, .annotation-text
+ {
+ padding: 5px;
+ margin: 5px;
+ }
+
+#annotation-list .selection-text,#annotation-list .annotation-text
+ {
+ border: solid 1px #EEE;
+ }
+
+#annotation-list .annotation-text
+ {
+ font-style: italic;
+ }
+
+body
+ {
+ background-color: #F5F5F5;
+ font: 100% arial, helvetica, sans-serif;
+ }
+
+h1
+ {
+ font-family: georgia,serif;
+ font-size: 1.5em;
+ text-align:center;
+ }
diff --git a/tools/addon-sdk-1.7/examples/annotator/data/list/annotation-list.html b/tools/addon-sdk-1.7/examples/annotator/data/list/annotation-list.html
new file mode 100644
index 0000000..32a5409
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/annotator/data/list/annotation-list.html
@@ -0,0 +1,26 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<html>
+<head>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+ <title>Saved annotations</title>
+ <link rel="stylesheet" type="text/css" href="annotation-list.css" />
+</head>
+<body>
+
+<div id="annotation-list">
+</div>
+
+<div id="template">
+ <div class="annotation-details">
+ <a class="url"></a>
+ <div class="selection-text"></div>
+ <div class="annotation-text"></div>
+ </div>
+</div>
+
+</body>
+
+</html>
diff --git a/tools/addon-sdk-1.7/examples/annotator/data/list/annotation-list.js b/tools/addon-sdk-1.7/examples/annotator/data/list/annotation-list.js
new file mode 100644
index 0000000..5653ba5
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/annotator/data/list/annotation-list.js
@@ -0,0 +1,31 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+Construct the HTML for the annotation list.
+
+Bind a function to click events on the link that send a message back to
+the add-on code, so it can open the link in the main browser.
+*/
+
+self.on("message", function onMessage(storedAnnotations) {
+ var annotationList = $('#annotation-list');
+ annotationList.empty();
+ storedAnnotations.forEach(
+ function(storedAnnotation) {
+ var annotationHtml = $('#template .annotation-details').clone();
+ annotationHtml.find('.url').text(storedAnnotation.url)
+ .attr('href', storedAnnotation.url);
+ annotationHtml.find('.url').bind('click', function(event) {
+ event.stopPropagation();
+ event.preventDefault();
+ self.postMessage(storedAnnotation.url);
+ });
+ annotationHtml.find('.selection-text')
+ .text(storedAnnotation.anchorText);
+ annotationHtml.find('.annotation-text')
+ .text(storedAnnotation.annotationText);
+ annotationList.append(annotationHtml);
+ });
+});
diff --git a/tools/addon-sdk-1.7/examples/annotator/data/matcher.js b/tools/addon-sdk-1.7/examples/annotator/data/matcher.js
new file mode 100644
index 0000000..86d6bc7
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/annotator/data/matcher.js
@@ -0,0 +1,50 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+Locate anchors for annotations and prepare to display the annotations.
+
+For each annotation, if its URL matches this page,
+- get the ancestor whose ID matches the ID in the anchor
+- look for a <p> element whose content contains the anchor text
+
+That's considered a match. Then we:
+- highlight the anchor element
+- add an 'annotated' class to tell the selector to skip this element
+- embed the annottion text as a new attribute
+
+For all annotated elements:
+- bind 'mouseenter' and 'mouseleave' events to the element, to send 'show'
+ and 'hide' messages back to the add-on.
+*/
+
+self.on('message', function onMessage(annotations) {
+ annotations.forEach(
+ function(annotation) {
+ if(annotation.url == document.location.toString()) {
+ createAnchor(annotation);
+ }
+ });
+
+ $('.annotated').css('border', 'solid 3px yellow');
+
+ $('.annotated').bind('mouseenter', function(event) {
+ self.port.emit('show', $(this).attr('annotation'));
+ event.stopPropagation();
+ event.preventDefault();
+ });
+
+ $('.annotated').bind('mouseleave', function() {
+ self.port.emit('hide');
+ });
+});
+
+
+function createAnchor(annotation) {
+ annotationAnchorAncestor = $('#' + annotation.ancestorId)[0] || document.body;
+ annotationAnchor = $(annotationAnchorAncestor).parent().find(
+ ':contains("' + annotation.anchorText + '")').last();
+ annotationAnchor.addClass('annotated');
+ annotationAnchor.attr('annotation', annotation.annotationText);
+}
diff --git a/tools/addon-sdk-1.7/examples/annotator/data/selector.js b/tools/addon-sdk-1.7/examples/annotator/data/selector.js
new file mode 100644
index 0000000..f42dbfa
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/annotator/data/selector.js
@@ -0,0 +1,73 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+The selector locates elements that are suitable for annotation and enables
+the user to select them.
+
+On 'mouseenter' events associated with <p> elements:
+- if the selector is active and the element is not already annotated
+- find the nearest ancestor which has an id attribute: this is supposed to
+make identification of this element more accurate
+- highlight the element
+- bind 'click' for the element to send a message back to the add-on, including
+all the information associated with the anchor.
+*/
+
+var matchedElement = null;
+var originalBgColor = null;
+var active = false;
+
+function resetMatchedElement() {
+ if (matchedElement) {
+ matchedElement.css('background-color', originalBgColor);
+ matchedElement.unbind('click.annotator');
+ }
+}
+
+self.on('message', function onMessage(activation) {
+ active = activation;
+ if (!active) {
+ resetMatchedElement();
+ }
+});
+
+function getInnerText(element) {
+ // jQuery.text() returns content of <script> tags, we need to ignore those
+ var list = [];
+ element.find("*").andSelf().contents()
+ .filter(function () {
+ return this.nodeType == 3 && this.parentNode.tagName != "SCRIPT";
+ })
+ .each(function () {
+ list.push(this.nodeValue);
+ });
+ return list.join("");
+}
+
+$('*').mouseenter(function() {
+ if (!active || $(this).hasClass('annotated')) {
+ return;
+ }
+ resetMatchedElement();
+ ancestor = $(this).closest("[id]");
+ matchedElement = $(this).first();
+ originalBgColor = matchedElement.css('background-color');
+ matchedElement.css('background-color', 'yellow');
+ matchedElement.bind('click.annotator', function(event) {
+ event.stopPropagation();
+ event.preventDefault();
+ self.port.emit('show',
+ [
+ document.location.toString(),
+ ancestor.attr("id"),
+ getInnerText(matchedElement)
+ ]
+ );
+ });
+});
+
+$('*').mouseout(function() {
+ resetMatchedElement();
+});
diff --git a/tools/addon-sdk-1.7/examples/annotator/data/widget/pencil-off.png b/tools/addon-sdk-1.7/examples/annotator/data/widget/pencil-off.png
new file mode 100644
index 0000000..b14d961
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/annotator/data/widget/pencil-off.png
Binary files differ
diff --git a/tools/addon-sdk-1.7/examples/annotator/data/widget/pencil-on.png b/tools/addon-sdk-1.7/examples/annotator/data/widget/pencil-on.png
new file mode 100644
index 0000000..71a609f
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/annotator/data/widget/pencil-on.png
Binary files differ
diff --git a/tools/addon-sdk-1.7/examples/annotator/data/widget/widget.js b/tools/addon-sdk-1.7/examples/annotator/data/widget/widget.js
new file mode 100644
index 0000000..1efb914
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/annotator/data/widget/widget.js
@@ -0,0 +1,17 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+Listen for left and right click events and send the corresponding message
+to the content script.
+*/
+
+this.addEventListener('click', function(event) {
+ if(event.button == 0 && event.shiftKey == false)
+ self.port.emit('left-click');
+
+ if(event.button == 2 || (event.button == 0 && event.shiftKey == true))
+ self.port.emit('right-click');
+ event.preventDefault();
+}, true);
diff --git a/tools/addon-sdk-1.7/examples/annotator/lib/main.js b/tools/addon-sdk-1.7/examples/annotator/lib/main.js
new file mode 100644
index 0000000..a21320a
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/annotator/lib/main.js
@@ -0,0 +1,294 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var widgets = require('widget');
+var pageMod = require('page-mod');
+var data = require('self').data;
+var panels = require('panel');
+var simpleStorage = require('simple-storage');
+var notifications = require("notifications");
+var privateBrowsing = require('private-browsing');
+
+/*
+Global variables
+* Boolean to indicate whether the add-on is switched on or not
+* Array for all workers associated with the 'selector' page mod
+* Array for all workers associated with the 'matcher' page mod
+*/
+var annotatorIsOn = false;
+var selectors = [];
+var matchers = [];
+
+if (!simpleStorage.storage.annotations)
+ simpleStorage.storage.annotations = [];
+
+/*
+Update the matchers: call this whenever the set of annotations changes
+*/
+function updateMatchers() {
+ matchers.forEach(function (matcher) {
+ matcher.postMessage(simpleStorage.storage.annotations);
+ });
+}
+
+/*
+You can add annotations iff the add-on is on AND private browsing is off
+*/
+function canEnterAnnotations() {
+ return (annotatorIsOn && !privateBrowsing.isActive);
+}
+
+/*
+Constructor for an Annotation object
+*/
+function Annotation(annotationText, anchor) {
+ this.annotationText = annotationText;
+ this.url = anchor[0];
+ this.ancestorId = anchor[1];
+ this.anchorText = anchor[2];
+}
+
+/*
+Function to deal with a new annotation.
+Create a new annotation object, store it, and
+notify all the annotators of the change.
+*/
+function handleNewAnnotation(annotationText, anchor) {
+ var newAnnotation = new Annotation(annotationText, anchor);
+ simpleStorage.storage.annotations.push(newAnnotation);
+ updateMatchers();
+}
+
+/*
+Function to tell the selector page mod that the add-on has become (in)active
+*/
+function activateSelectors() {
+ selectors.forEach(
+ function (selector) {
+ selector.postMessage(canEnterAnnotations());
+ });
+}
+
+/*
+Toggle activation: update the on/off state and notify the selectors.
+Toggling activation is disabled when private browsing is on.
+*/
+function toggleActivation() {
+ if (privateBrowsing.isActive) {
+ return false;
+ }
+ annotatorIsOn = !annotatorIsOn;
+ activateSelectors();
+ return canEnterAnnotations();
+}
+
+function detachWorker(worker, workerArray) {
+ var index = workerArray.indexOf(worker);
+ if(index != -1) {
+ workerArray.splice(index, 1);
+ }
+}
+
+exports.main = function() {
+
+/*
+The widget provides a mechanism to switch the selector on or off, and to
+view the list of annotations.
+
+The selector is switched on/off with a left-click, and the list of annotations
+is displayed on a right-click.
+*/
+ var widget = widgets.Widget({
+ id: 'toggle-switch',
+ label: 'Annotator',
+ contentURL: data.url('widget/pencil-off.png'),
+ contentScriptWhen: 'ready',
+ contentScriptFile: data.url('widget/widget.js')
+ });
+
+ widget.port.on('left-click', function() {
+ console.log('activate/deactivate');
+ widget.contentURL = toggleActivation() ?
+ data.url('widget/pencil-on.png') :
+ data.url('widget/pencil-off.png');
+ });
+
+ widget.port.on('right-click', function() {
+ console.log('show annotation list');
+ annotationList.show();
+ });
+
+/*
+The selector page-mod enables the user to select page elements to annotate.
+
+It is attached to all pages but only operates if the add-on is active.
+
+The content script highlights any page elements which can be annotated. If the
+user clicks a highlighted element it sends a message to the add-on containing
+information about the element clicked, which is called the anchor of the
+annotation.
+
+When we receive this message we assign the anchor to the annotationEditor and
+display it.
+*/
+ var selector = pageMod.PageMod({
+ include: ['*'],
+ contentScriptWhen: 'ready',
+ contentScriptFile: [data.url('jquery-1.4.2.min.js'),
+ data.url('selector.js')],
+ onAttach: function(worker) {
+ worker.postMessage(canEnterAnnotations());
+ selectors.push(worker);
+ worker.port.on('show', function(data) {
+ annotationEditor.annotationAnchor = data;
+ annotationEditor.show();
+ });
+ worker.on('detach', function () {
+ detachWorker(this, selectors);
+ });
+ }
+ });
+
+/*
+The annotationEditor panel is the UI component used for creating
+new annotations. It contains a text area for the user to
+enter the annotation.
+
+When we are ready to display the editor we assign its 'anchor' property
+and call its show() method.
+
+Its content script sends the content of the text area to the add-on
+when the user presses the return key.
+
+When we receives this message we create a new annotation using the anchor
+and the text the user entered, store it, and hide the panel.
+*/
+ var annotationEditor = panels.Panel({
+ width: 220,
+ height: 220,
+ contentURL: data.url('editor/annotation-editor.html'),
+ contentScriptFile: data.url('editor/annotation-editor.js'),
+ onMessage: function(annotationText) {
+ if (annotationText)
+ handleNewAnnotation(annotationText, this.annotationAnchor);
+ annotationEditor.hide();
+ },
+ onShow: function() {
+ this.postMessage('focus');
+ }
+ });
+
+/*
+The annotationList panel is the UI component that lists all the annotations
+the user has entered.
+
+On its 'show' event we pass it the array of annotations.
+
+The content script creates the HTML elements for the annotations, and
+intercepts clicks on the links, passing them back to the add-on to open them
+in the browser.
+*/
+ var annotationList = panels.Panel({
+ width: 420,
+ height: 200,
+ contentURL: data.url('list/annotation-list.html'),
+ contentScriptFile: [data.url('jquery-1.4.2.min.js'),
+ data.url('list/annotation-list.js')],
+ contentScriptWhen: 'ready',
+ onShow: function() {
+ this.postMessage(simpleStorage.storage.annotations);
+ },
+ onMessage: function(message) {
+ require('tabs').open(message);
+ }
+ });
+
+/*
+We listen for the OverQuota event from simple-storage.
+If it fires we just notify the user and delete the most
+recent annotations until we are back in quota.
+*/
+ simpleStorage.on("OverQuota", function () {
+ notifications.notify({
+ title: 'Storage space exceeded',
+ text: 'Removing recent annotations'});
+ while (simpleStorage.quotaUsage > 1)
+ simpleStorage.storage.annotations.pop();
+ });
+
+/*
+We listen for private browsing start/stop events to change the widget icon
+and to notify the selectors of the change in state.
+*/
+ privateBrowsing.on('start', function() {
+ widget.contentURL = data.url('widget/pencil-off.png');
+ activateSelectors();
+ });
+
+ privateBrowsing.on('stop', function() {
+ if (canEnterAnnotations()) {
+ widget.contentURL = data.url('widget/pencil-on.png');
+ activateSelectors();
+ }
+ });
+
+/*
+The matcher page-mod locates anchors on web pages and prepares for the
+annotation to be displayed.
+
+It is attached to all pages, and when it is attached we pass it the complete
+list of annotations. It looks for anchors in its page. If it finds one it
+highlights the anchor and binds mouseenter/mouseout events to 'show' and 'hide'
+messages to the add-on.
+
+When the add-on receives the 'show' message it assigns the annotation text to
+the annotation panel and shows it.
+
+Note that the matcher is active whether or not the add-on is active:
+'inactive' only means that the user can't create new add-ons, they can still
+see old ones.
+*/
+ var matcher = pageMod.PageMod({
+ include: ['*'],
+ contentScriptWhen: 'ready',
+ contentScriptFile: [data.url('jquery-1.4.2.min.js'),
+ data.url('matcher.js')],
+ onAttach: function(worker) {
+ if(simpleStorage.storage.annotations) {
+ worker.postMessage(simpleStorage.storage.annotations);
+ }
+ worker.port.on('show', function(data) {
+ annotation.content = data;
+ annotation.show();
+ });
+ worker.port.on('hide', function() {
+ annotation.content = null;
+ annotation.hide();
+ });
+ worker.on('detach', function () {
+ detachWorker(this, matchers);
+ });
+ matchers.push(worker);
+ }
+ });
+
+/*
+The annotation panel is the UI component that displays an annotation.
+
+When we are ready to show it we assign its 'content' attribute to contain
+the annotation text, and that gets sent to the content process in onShow().
+*/
+ var annotation = panels.Panel({
+ width: 200,
+ height: 180,
+ contentURL: data.url('annotation/annotation.html'),
+ contentScriptFile: [data.url('jquery-1.4.2.min.js'),
+ data.url('annotation/annotation.js')],
+ contentScriptWhen: 'ready',
+ onShow: function() {
+ this.postMessage(this.content);
+ }
+ });
+
+}
diff --git a/tools/addon-sdk-1.7/examples/annotator/package.json b/tools/addon-sdk-1.7/examples/annotator/package.json
new file mode 100644
index 0000000..3870710
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/annotator/package.json
@@ -0,0 +1,9 @@
+{
+ "license": "MPL 2.0",
+ "name": "annotator",
+ "contributors": [],
+ "author": "Will Bamberg",
+ "keywords": [],
+ "id": "anonid0-annotator",
+ "description": "Add notes to Web pages"
+}
diff --git a/tools/addon-sdk-1.7/examples/annotator/tests/test-main.js b/tools/addon-sdk-1.7/examples/annotator/tests/test-main.js
new file mode 100644
index 0000000..72fedf4
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/annotator/tests/test-main.js
@@ -0,0 +1,7 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.testMain = function(test) {
+ test.pass("TODO: Write some tests.");
+};
diff --git a/tools/addon-sdk-1.7/examples/library-detector/README.md b/tools/addon-sdk-1.7/examples/library-detector/README.md
new file mode 100755
index 0000000..72285ac
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/library-detector/README.md
@@ -0,0 +1,13 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+This is a port to the SDK of the
+[Library Detector add-on](https://addons.mozilla.org/en-US/firefox/addon/library-detector/).
+The original Library Detector is written by
+[Paul Bakaus](http://paulbakaus.com/) and made available under the
+[MIT License](http://www.opensource.org/licenses/mit-license.php).
+
+It only recognizes a subset of the libraries recognized by the original,
+just to keep the SDK download package size and on-disk footprint as small
+as possible.
diff --git a/tools/addon-sdk-1.7/examples/library-detector/data/icons/closure.ico b/tools/addon-sdk-1.7/examples/library-detector/data/icons/closure.ico
new file mode 100755
index 0000000..a8c91a0
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/library-detector/data/icons/closure.ico
Binary files differ
diff --git a/tools/addon-sdk-1.7/examples/library-detector/data/icons/jquery.ico b/tools/addon-sdk-1.7/examples/library-detector/data/icons/jquery.ico
new file mode 100755
index 0000000..8df8f38
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/library-detector/data/icons/jquery.ico
Binary files differ
diff --git a/tools/addon-sdk-1.7/examples/library-detector/data/icons/jquery_ui.ico b/tools/addon-sdk-1.7/examples/library-detector/data/icons/jquery_ui.ico
new file mode 100755
index 0000000..77e3bd2
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/library-detector/data/icons/jquery_ui.ico
Binary files differ
diff --git a/tools/addon-sdk-1.7/examples/library-detector/data/icons/modernizr.ico b/tools/addon-sdk-1.7/examples/library-detector/data/icons/modernizr.ico
new file mode 100755
index 0000000..c37d438
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/library-detector/data/icons/modernizr.ico
Binary files differ
diff --git a/tools/addon-sdk-1.7/examples/library-detector/data/icons/mootools.png b/tools/addon-sdk-1.7/examples/library-detector/data/icons/mootools.png
new file mode 100755
index 0000000..2a5df7d
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/library-detector/data/icons/mootools.png
Binary files differ
diff --git a/tools/addon-sdk-1.7/examples/library-detector/data/icons/yui.ico b/tools/addon-sdk-1.7/examples/library-detector/data/icons/yui.ico
new file mode 100755
index 0000000..06acd8a
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/library-detector/data/icons/yui.ico
Binary files differ
diff --git a/tools/addon-sdk-1.7/examples/library-detector/data/library-detector.js b/tools/addon-sdk-1.7/examples/library-detector/data/library-detector.js
new file mode 100755
index 0000000..af3a88e
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/library-detector/data/library-detector.js
@@ -0,0 +1,97 @@
+/*
+The code in this file is adapted from the original
+Library Detector add-on
+(https://addons.mozilla.org/en-US/firefox/addon/library-detector/) written by
+Paul Bakaus (http://paulbakaus.com/) and made available under the
+MIT License (http://www.opensource.org/licenses/mit-license.php).
+*/
+
+var LD_tests = {
+
+ 'jQuery': {
+ test: function(win) {
+ var jq = win.jQuery || win.$ || win.$jq || win.$j;
+ if(jq && jq.fn && jq.fn.jquery) {
+ return { version: jq.fn.jquery };
+ } else {
+ return false;
+ }
+ }
+ },
+
+ 'jQuery UI': {
+ //phonehome: 'http://jqueryui.com/phone_home',
+ test: function(win) {
+
+ var jq = win.jQuery || win.$ || win.$jq || win.$j;
+ if(jq && jq.fn && jq.fn.jquery && jq.ui) {
+
+ var plugins = 'accordion,datepicker,dialog,draggable,droppable,progressbar,resizable,selectable,slider,menu,grid,tabs'.split(','), concat = [];
+ for (var i=0; i < plugins.length; i++) { if(jq.ui[plugins[i]]) concat.push(plugins[i].substr(0,1).toUpperCase() + plugins[i].substr(1)); };
+
+ return { version: jq.ui.version, details: concat.length ? 'Plugins used: '+concat.join(',') : '' };
+ } else {
+ return false;
+ }
+
+ }
+ },
+
+ 'MooTools': {
+ test: function(win) {
+ if(win.MooTools && win.MooTools.version) {
+ return { version: win.MooTools.version };
+ } else {
+ return false;
+ }
+ }
+ },
+
+ 'YUI': {
+ test: function(win) {
+ if(win.YAHOO && win.YAHOO.VERSION) {
+ return { version: win.YAHOO.VERSION };
+ } else {
+ return false;
+ }
+ }
+ },
+
+ 'Closure': {
+ test: function(win) {
+ if(win.goog) {
+ return { version: '2.0' };
+ }
+ return false;
+ }
+ },
+
+ 'Modernizr': {
+ test: function(win) {
+ if(win.Modernizr) {
+ return { version: win.Modernizr._version };
+ }
+ return false;
+ }
+ },
+
+
+};
+
+function testLibraries() {
+ var win = unsafeWindow;
+ var libraryList = [];
+ for(var i in LD_tests) {
+ var passed = LD_tests[i].test(win);
+ if (passed) {
+ let libraryInfo = {
+ name: i,
+ version: passed.version
+ };
+ libraryList.push(libraryInfo);
+ }
+ }
+ self.postMessage(libraryList);
+}
+
+testLibraries(); \ No newline at end of file
diff --git a/tools/addon-sdk-1.7/examples/library-detector/data/widget.js b/tools/addon-sdk-1.7/examples/library-detector/data/widget.js
new file mode 100755
index 0000000..293537e
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/library-detector/data/widget.js
@@ -0,0 +1,14 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+function setLibraryInfo(element) {
+ self.port.emit('setLibraryInfo', element.target.title);
+}
+
+var elements = document.getElementsByTagName('img');
+
+for (var i = 0; i < elements.length; i++) {
+ elements[i].addEventListener('mouseover', setLibraryInfo, false);
+}
diff --git a/tools/addon-sdk-1.7/examples/library-detector/lib/main.js b/tools/addon-sdk-1.7/examples/library-detector/lib/main.js
new file mode 100755
index 0000000..4380c6f
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/library-detector/lib/main.js
@@ -0,0 +1,107 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const tabs = require('tabs');
+const widgets = require('widget');
+const data = require('self').data;
+const pageMod = require('page-mod');
+const panel = require('panel');
+
+const htmlContentPreamble =
+ '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"' +
+ ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' +
+ ' <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">' +
+ ' <head>' +
+ ' <style type="text/css" media="all">' +
+ ' img {display: inline;}' +
+ ' </style>' +
+ ' </head>' +
+ ' <body>'
+
+const htmlContentPostamble =
+ ' </body>' +
+ '</html>'
+
+const icons = {
+ 'jQuery' : 'jquery.ico',
+ 'jQuery UI' : 'jquery_ui.ico',
+ 'MooTools' : 'mootools.png',
+ 'YUI' : 'yui.ico',
+ 'Closure' : 'closure.ico',
+ 'Modernizr': 'modernizr.ico',
+}
+
+const ICON_WIDTH = 32;
+
+function buildIconHtml(imageName, libraryInfo) {
+ return '<img src="' + data.url("icons/" + imageName) + '" title="' + libraryInfo + '">';
+}
+
+function buildWidgetViewContent(libraryList) {
+ widgetContent = htmlContentPreamble;
+ libraryList.forEach(function(library) {
+ widgetContent += buildIconHtml(icons[library.name], library.name + "<br>Version: " + library.version);
+ });
+ widgetContent += htmlContentPostamble;
+ return widgetContent;
+}
+
+function updateWidgetView(tab) {
+ let widgetView = widget.getView(tab.window);
+ if (!tab.libraries) {
+ tab.libraries = [];
+ }
+ widgetView.content = buildWidgetViewContent(tab.libraries);
+ widgetView.width = tab.libraries.length * ICON_WIDTH;
+}
+
+var widget = widgets.Widget({
+ id: "library-detector",
+ label: "Library Detector",
+ content: "<html></html>",
+ contentScriptFile: data.url("widget.js"),
+ panel: panel.Panel({
+ width: 240,
+ height: 60,
+ contentScript: 'self.on("message", function(libraryInfo) {' +
+ ' window.document.body.innerHTML = libraryInfo;' +
+ '});'
+ }),
+});
+
+widget.port.on('setLibraryInfo', function(libraryInfo) {
+ widget.panel.postMessage(libraryInfo);
+});
+
+pageMod.PageMod({
+ include: "*",
+ contentScriptWhen: 'end',
+ contentScriptFile: (data.url('library-detector.js')),
+ onAttach: function(worker) {
+ worker.on('message', function(libraryList) {
+ if (!worker.tab.libraries) {
+ worker.tab.libraries = [];
+ }
+ libraryList.forEach(function(library) {
+ if (worker.tab.libraries.indexOf(library) == -1) {
+ worker.tab.libraries.push(library);
+ }
+ });
+ if (worker.tab == tabs.activeTab) {
+ updateWidgetView(worker.tab);
+ }
+ });
+ }
+});
+
+tabs.on('activate', function(tab) {
+ updateWidgetView(tab);
+});
+
+/*
+For change of location
+*/
+tabs.on('ready', function(tab) {
+ tab.libraries = [];
+}); \ No newline at end of file
diff --git a/tools/addon-sdk-1.7/examples/library-detector/package.json b/tools/addon-sdk-1.7/examples/library-detector/package.json
new file mode 100755
index 0000000..6d868ff
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/library-detector/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "library-detector-sdk",
+ "license": "MPL 2.0",
+ "author": "",
+ "version": "0.1",
+ "fullName": "library-detector-sdk",
+ "id": "jid1-R4rSVNkBANnvGQ",
+ "description": "a basic add-on"
+}
diff --git a/tools/addon-sdk-1.7/examples/library-detector/test/test-main.js b/tools/addon-sdk-1.7/examples/library-detector/test/test-main.js
new file mode 100644
index 0000000..72fedf4
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/library-detector/test/test-main.js
@@ -0,0 +1,7 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.testMain = function(test) {
+ test.pass("TODO: Write some tests.");
+};
diff --git a/tools/addon-sdk-1.7/examples/reading-data/data/mom.png b/tools/addon-sdk-1.7/examples/reading-data/data/mom.png
new file mode 100644
index 0000000..4ba89a2
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/reading-data/data/mom.png
Binary files differ
diff --git a/tools/addon-sdk-1.7/examples/reading-data/data/sample.html b/tools/addon-sdk-1.7/examples/reading-data/data/sample.html
new file mode 100644
index 0000000..c7c09cb
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/reading-data/data/sample.html
@@ -0,0 +1,7 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<html><body>
+<h1>Hello World</h1>
+</body></html>
diff --git a/tools/addon-sdk-1.7/examples/reading-data/lib/main.js b/tools/addon-sdk-1.7/examples/reading-data/lib/main.js
new file mode 100644
index 0000000..89a62a2
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/reading-data/lib/main.js
@@ -0,0 +1,44 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var self = require("self");
+var panels = require("addon-kit/panel");
+var widgets = require("addon-kit/widget");
+
+function replaceMom(html) {
+ return html.replace("World", "Mom");
+}
+exports.replaceMom = replaceMom;
+
+exports.main = function(options, callbacks) {
+ console.log("My ID is " + self.id);
+
+ // Load the sample HTML into a string.
+ var helloHTML = self.data.load("sample.html");
+
+ // Let's now modify it...
+ helloHTML = replaceMom(helloHTML);
+
+ // ... and then create a panel that displays it.
+ var myPanel = panels.Panel({
+ contentURL: "data:text/html," + helloHTML
+ });
+
+ // Load the URL of the sample image.
+ var iconURL = self.data.url("mom.png");
+
+ // Create a widget that displays the image. We'll attach the panel to it.
+ // When you click the widget, the panel will pop up.
+ widgets.Widget({
+ id: "test-widget",
+ label: "Mom",
+ contentURL: iconURL,
+ panel: myPanel
+ });
+
+ // If you run cfx with --static-args='{"quitWhenDone":true}' this program
+ // will automatically quit Firefox when it's done.
+ if (options.staticArgs.quitWhenDone)
+ callbacks.quit();
+}
diff --git a/tools/addon-sdk-1.7/examples/reading-data/package.json b/tools/addon-sdk-1.7/examples/reading-data/package.json
new file mode 100644
index 0000000..5fc6b2b
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/reading-data/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "reading-data",
+ "description": "A demonstration of reading bundled data.",
+ "keywords": [],
+ "author": "Brian Warner",
+ "contributors": [],
+ "license": "MPL 2.0",
+ "id": "reading-data-example@jetpack.mozillalabs.com"
+}
diff --git a/tools/addon-sdk-1.7/examples/reading-data/tests/test-main.js b/tools/addon-sdk-1.7/examples/reading-data/tests/test-main.js
new file mode 100644
index 0000000..1a455fd
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/reading-data/tests/test-main.js
@@ -0,0 +1,24 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var m = require("main");
+var self = require("self");
+
+exports.testReplace = function(test) {
+ var input = "Hello World";
+ var output = m.replaceMom(input);
+ test.assertEqual(output, "Hello Mom");
+ var callbacks = { quit: function() {} };
+
+ // Make sure it doesn't crash...
+ m.main({ staticArgs: {} }, callbacks);
+};
+
+exports.testID = function(test) {
+ // The ID is randomly generated during tests, so we cannot compare it against
+ // anything in particular. Just assert that it is not empty.
+ test.assert(self.id.length > 0);
+ test.assertEqual(self.data.url("sample.html"),
+ "resource://reading-data-example-at-jetpack-dot-mozillalabs-dot-com/reading-data/data/sample.html");
+};
diff --git a/tools/addon-sdk-1.7/examples/reddit-panel/README.md b/tools/addon-sdk-1.7/examples/reddit-panel/README.md
new file mode 100644
index 0000000..5edfb70
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/reddit-panel/README.md
@@ -0,0 +1,14 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+The Reddit Panel example add-on displays Reddit in a panel you open
+by clicking a widget in the add-on bar. When you click a Reddit story
+in the panel, the story opens in a new tab.
+
+The add-on demonstrates the Panel and Widget APIs as well as content scripts
+and using jQuery as a content script.
+
+Due to a bug in Firefox 4.0b7, this example doesn't work in that version
+of Firefox and requires a recent Firefox 4.0b8pre nightly build, Firefox 4.0b8
+itself, or a newer version of Firefox.
diff --git a/tools/addon-sdk-1.7/examples/reddit-panel/data/jquery-1.4.4.min.js b/tools/addon-sdk-1.7/examples/reddit-panel/data/jquery-1.4.4.min.js
new file mode 100644
index 0000000..8f3ca2e
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/reddit-panel/data/jquery-1.4.4.min.js
@@ -0,0 +1,167 @@
+/*!
+ * jQuery JavaScript Library v1.4.4
+ * http://jquery.com/
+ *
+ * Copyright 2010, John Resig
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://jquery.org/license
+ *
+ * Includes Sizzle.js
+ * http://sizzlejs.com/
+ * Copyright 2010, The Dojo Foundation
+ * Released under the MIT, BSD, and GPL Licenses.
+ *
+ * Date: Thu Nov 11 19:04:53 2010 -0500
+ */
+(function(E,B){function ka(a,b,d){if(d===B&&a.nodeType===1){d=a.getAttribute("data-"+b);if(typeof d==="string"){try{d=d==="true"?true:d==="false"?false:d==="null"?null:!c.isNaN(d)?parseFloat(d):Ja.test(d)?c.parseJSON(d):d}catch(e){}c.data(a,b,d)}else d=B}return d}function U(){return false}function ca(){return true}function la(a,b,d){d[0].type=a;return c.event.handle.apply(b,d)}function Ka(a){var b,d,e,f,h,l,k,o,x,r,A,C=[];f=[];h=c.data(this,this.nodeType?"events":"__events__");if(typeof h==="function")h=
+h.events;if(!(a.liveFired===this||!h||!h.live||a.button&&a.type==="click")){if(a.namespace)A=RegExp("(^|\\.)"+a.namespace.split(".").join("\\.(?:.*\\.)?")+"(\\.|$)");a.liveFired=this;var J=h.live.slice(0);for(k=0;k<J.length;k++){h=J[k];h.origType.replace(X,"")===a.type?f.push(h.selector):J.splice(k--,1)}f=c(a.target).closest(f,a.currentTarget);o=0;for(x=f.length;o<x;o++){r=f[o];for(k=0;k<J.length;k++){h=J[k];if(r.selector===h.selector&&(!A||A.test(h.namespace))){l=r.elem;e=null;if(h.preType==="mouseenter"||
+h.preType==="mouseleave"){a.type=h.preType;e=c(a.relatedTarget).closest(h.selector)[0]}if(!e||e!==l)C.push({elem:l,handleObj:h,level:r.level})}}}o=0;for(x=C.length;o<x;o++){f=C[o];if(d&&f.level>d)break;a.currentTarget=f.elem;a.data=f.handleObj.data;a.handleObj=f.handleObj;A=f.handleObj.origHandler.apply(f.elem,arguments);if(A===false||a.isPropagationStopped()){d=f.level;if(A===false)b=false;if(a.isImmediatePropagationStopped())break}}return b}}function Y(a,b){return(a&&a!=="*"?a+".":"")+b.replace(La,
+"`").replace(Ma,"&")}function ma(a,b,d){if(c.isFunction(b))return c.grep(a,function(f,h){return!!b.call(f,h,f)===d});else if(b.nodeType)return c.grep(a,function(f){return f===b===d});else if(typeof b==="string"){var e=c.grep(a,function(f){return f.nodeType===1});if(Na.test(b))return c.filter(b,e,!d);else b=c.filter(b,e)}return c.grep(a,function(f){return c.inArray(f,b)>=0===d})}function na(a,b){var d=0;b.each(function(){if(this.nodeName===(a[d]&&a[d].nodeName)){var e=c.data(a[d++]),f=c.data(this,
+e);if(e=e&&e.events){delete f.handle;f.events={};for(var h in e)for(var l in e[h])c.event.add(this,h,e[h][l],e[h][l].data)}}})}function Oa(a,b){b.src?c.ajax({url:b.src,async:false,dataType:"script"}):c.globalEval(b.text||b.textContent||b.innerHTML||"");b.parentNode&&b.parentNode.removeChild(b)}function oa(a,b,d){var e=b==="width"?a.offsetWidth:a.offsetHeight;if(d==="border")return e;c.each(b==="width"?Pa:Qa,function(){d||(e-=parseFloat(c.css(a,"padding"+this))||0);if(d==="margin")e+=parseFloat(c.css(a,
+"margin"+this))||0;else e-=parseFloat(c.css(a,"border"+this+"Width"))||0});return e}function da(a,b,d,e){if(c.isArray(b)&&b.length)c.each(b,function(f,h){d||Ra.test(a)?e(a,h):da(a+"["+(typeof h==="object"||c.isArray(h)?f:"")+"]",h,d,e)});else if(!d&&b!=null&&typeof b==="object")c.isEmptyObject(b)?e(a,""):c.each(b,function(f,h){da(a+"["+f+"]",h,d,e)});else e(a,b)}function S(a,b){var d={};c.each(pa.concat.apply([],pa.slice(0,b)),function(){d[this]=a});return d}function qa(a){if(!ea[a]){var b=c("<"+
+a+">").appendTo("body"),d=b.css("display");b.remove();if(d==="none"||d==="")d="block";ea[a]=d}return ea[a]}function fa(a){return c.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:false}var t=E.document,c=function(){function a(){if(!b.isReady){try{t.documentElement.doScroll("left")}catch(j){setTimeout(a,1);return}b.ready()}}var b=function(j,s){return new b.fn.init(j,s)},d=E.jQuery,e=E.$,f,h=/^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]+)$)/,l=/\S/,k=/^\s+/,o=/\s+$/,x=/\W/,r=/\d/,A=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,
+C=/^[\],:{}\s]*$/,J=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,w=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,I=/(?:^|:|,)(?:\s*\[)+/g,L=/(webkit)[ \/]([\w.]+)/,g=/(opera)(?:.*version)?[ \/]([\w.]+)/,i=/(msie) ([\w.]+)/,n=/(mozilla)(?:.*? rv:([\w.]+))?/,m=navigator.userAgent,p=false,q=[],u,y=Object.prototype.toString,F=Object.prototype.hasOwnProperty,M=Array.prototype.push,N=Array.prototype.slice,O=String.prototype.trim,D=Array.prototype.indexOf,R={};b.fn=b.prototype={init:function(j,
+s){var v,z,H;if(!j)return this;if(j.nodeType){this.context=this[0]=j;this.length=1;return this}if(j==="body"&&!s&&t.body){this.context=t;this[0]=t.body;this.selector="body";this.length=1;return this}if(typeof j==="string")if((v=h.exec(j))&&(v[1]||!s))if(v[1]){H=s?s.ownerDocument||s:t;if(z=A.exec(j))if(b.isPlainObject(s)){j=[t.createElement(z[1])];b.fn.attr.call(j,s,true)}else j=[H.createElement(z[1])];else{z=b.buildFragment([v[1]],[H]);j=(z.cacheable?z.fragment.cloneNode(true):z.fragment).childNodes}return b.merge(this,
+j)}else{if((z=t.getElementById(v[2]))&&z.parentNode){if(z.id!==v[2])return f.find(j);this.length=1;this[0]=z}this.context=t;this.selector=j;return this}else if(!s&&!x.test(j)){this.selector=j;this.context=t;j=t.getElementsByTagName(j);return b.merge(this,j)}else return!s||s.jquery?(s||f).find(j):b(s).find(j);else if(b.isFunction(j))return f.ready(j);if(j.selector!==B){this.selector=j.selector;this.context=j.context}return b.makeArray(j,this)},selector:"",jquery:"1.4.4",length:0,size:function(){return this.length},
+toArray:function(){return N.call(this,0)},get:function(j){return j==null?this.toArray():j<0?this.slice(j)[0]:this[j]},pushStack:function(j,s,v){var z=b();b.isArray(j)?M.apply(z,j):b.merge(z,j);z.prevObject=this;z.context=this.context;if(s==="find")z.selector=this.selector+(this.selector?" ":"")+v;else if(s)z.selector=this.selector+"."+s+"("+v+")";return z},each:function(j,s){return b.each(this,j,s)},ready:function(j){b.bindReady();if(b.isReady)j.call(t,b);else q&&q.push(j);return this},eq:function(j){return j===
+-1?this.slice(j):this.slice(j,+j+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(N.apply(this,arguments),"slice",N.call(arguments).join(","))},map:function(j){return this.pushStack(b.map(this,function(s,v){return j.call(s,v,s)}))},end:function(){return this.prevObject||b(null)},push:M,sort:[].sort,splice:[].splice};b.fn.init.prototype=b.fn;b.extend=b.fn.extend=function(){var j,s,v,z,H,G=arguments[0]||{},K=1,Q=arguments.length,ga=false;
+if(typeof G==="boolean"){ga=G;G=arguments[1]||{};K=2}if(typeof G!=="object"&&!b.isFunction(G))G={};if(Q===K){G=this;--K}for(;K<Q;K++)if((j=arguments[K])!=null)for(s in j){v=G[s];z=j[s];if(G!==z)if(ga&&z&&(b.isPlainObject(z)||(H=b.isArray(z)))){if(H){H=false;v=v&&b.isArray(v)?v:[]}else v=v&&b.isPlainObject(v)?v:{};G[s]=b.extend(ga,v,z)}else if(z!==B)G[s]=z}return G};b.extend({noConflict:function(j){E.$=e;if(j)E.jQuery=d;return b},isReady:false,readyWait:1,ready:function(j){j===true&&b.readyWait--;
+if(!b.readyWait||j!==true&&!b.isReady){if(!t.body)return setTimeout(b.ready,1);b.isReady=true;if(!(j!==true&&--b.readyWait>0))if(q){var s=0,v=q;for(q=null;j=v[s++];)j.call(t,b);b.fn.trigger&&b(t).trigger("ready").unbind("ready")}}},bindReady:function(){if(!p){p=true;if(t.readyState==="complete")return setTimeout(b.ready,1);if(t.addEventListener){t.addEventListener("DOMContentLoaded",u,false);E.addEventListener("load",b.ready,false)}else if(t.attachEvent){t.attachEvent("onreadystatechange",u);E.attachEvent("onload",
+b.ready);var j=false;try{j=E.frameElement==null}catch(s){}t.documentElement.doScroll&&j&&a()}}},isFunction:function(j){return b.type(j)==="function"},isArray:Array.isArray||function(j){return b.type(j)==="array"},isWindow:function(j){return j&&typeof j==="object"&&"setInterval"in j},isNaN:function(j){return j==null||!r.test(j)||isNaN(j)},type:function(j){return j==null?String(j):R[y.call(j)]||"object"},isPlainObject:function(j){if(!j||b.type(j)!=="object"||j.nodeType||b.isWindow(j))return false;if(j.constructor&&
+!F.call(j,"constructor")&&!F.call(j.constructor.prototype,"isPrototypeOf"))return false;for(var s in j);return s===B||F.call(j,s)},isEmptyObject:function(j){for(var s in j)return false;return true},error:function(j){throw j;},parseJSON:function(j){if(typeof j!=="string"||!j)return null;j=b.trim(j);if(C.test(j.replace(J,"@").replace(w,"]").replace(I,"")))return E.JSON&&E.JSON.parse?E.JSON.parse(j):(new Function("return "+j))();else b.error("Invalid JSON: "+j)},noop:function(){},globalEval:function(j){if(j&&
+l.test(j)){var s=t.getElementsByTagName("head")[0]||t.documentElement,v=t.createElement("script");v.type="text/javascript";if(b.support.scriptEval)v.appendChild(t.createTextNode(j));else v.text=j;s.insertBefore(v,s.firstChild);s.removeChild(v)}},nodeName:function(j,s){return j.nodeName&&j.nodeName.toUpperCase()===s.toUpperCase()},each:function(j,s,v){var z,H=0,G=j.length,K=G===B||b.isFunction(j);if(v)if(K)for(z in j){if(s.apply(j[z],v)===false)break}else for(;H<G;){if(s.apply(j[H++],v)===false)break}else if(K)for(z in j){if(s.call(j[z],
+z,j[z])===false)break}else for(v=j[0];H<G&&s.call(v,H,v)!==false;v=j[++H]);return j},trim:O?function(j){return j==null?"":O.call(j)}:function(j){return j==null?"":j.toString().replace(k,"").replace(o,"")},makeArray:function(j,s){var v=s||[];if(j!=null){var z=b.type(j);j.length==null||z==="string"||z==="function"||z==="regexp"||b.isWindow(j)?M.call(v,j):b.merge(v,j)}return v},inArray:function(j,s){if(s.indexOf)return s.indexOf(j);for(var v=0,z=s.length;v<z;v++)if(s[v]===j)return v;return-1},merge:function(j,
+s){var v=j.length,z=0;if(typeof s.length==="number")for(var H=s.length;z<H;z++)j[v++]=s[z];else for(;s[z]!==B;)j[v++]=s[z++];j.length=v;return j},grep:function(j,s,v){var z=[],H;v=!!v;for(var G=0,K=j.length;G<K;G++){H=!!s(j[G],G);v!==H&&z.push(j[G])}return z},map:function(j,s,v){for(var z=[],H,G=0,K=j.length;G<K;G++){H=s(j[G],G,v);if(H!=null)z[z.length]=H}return z.concat.apply([],z)},guid:1,proxy:function(j,s,v){if(arguments.length===2)if(typeof s==="string"){v=j;j=v[s];s=B}else if(s&&!b.isFunction(s)){v=
+s;s=B}if(!s&&j)s=function(){return j.apply(v||this,arguments)};if(j)s.guid=j.guid=j.guid||s.guid||b.guid++;return s},access:function(j,s,v,z,H,G){var K=j.length;if(typeof s==="object"){for(var Q in s)b.access(j,Q,s[Q],z,H,v);return j}if(v!==B){z=!G&&z&&b.isFunction(v);for(Q=0;Q<K;Q++)H(j[Q],s,z?v.call(j[Q],Q,H(j[Q],s)):v,G);return j}return K?H(j[0],s):B},now:function(){return(new Date).getTime()},uaMatch:function(j){j=j.toLowerCase();j=L.exec(j)||g.exec(j)||i.exec(j)||j.indexOf("compatible")<0&&n.exec(j)||
+[];return{browser:j[1]||"",version:j[2]||"0"}},browser:{}});b.each("Boolean Number String Function Array Date RegExp Object".split(" "),function(j,s){R["[object "+s+"]"]=s.toLowerCase()});m=b.uaMatch(m);if(m.browser){b.browser[m.browser]=true;b.browser.version=m.version}if(b.browser.webkit)b.browser.safari=true;if(D)b.inArray=function(j,s){return D.call(s,j)};if(!/\s/.test("\u00a0")){k=/^[\s\xA0]+/;o=/[\s\xA0]+$/}f=b(t);if(t.addEventListener)u=function(){t.removeEventListener("DOMContentLoaded",u,
+false);b.ready()};else if(t.attachEvent)u=function(){if(t.readyState==="complete"){t.detachEvent("onreadystatechange",u);b.ready()}};return E.jQuery=E.$=b}();(function(){c.support={};var a=t.documentElement,b=t.createElement("script"),d=t.createElement("div"),e="script"+c.now();d.style.display="none";d.innerHTML=" <link/><table></table><a href='/a' style='color:red;float:left;opacity:.55;'>a</a><input type='checkbox'/>";var f=d.getElementsByTagName("*"),h=d.getElementsByTagName("a")[0],l=t.createElement("select"),
+k=l.appendChild(t.createElement("option"));if(!(!f||!f.length||!h)){c.support={leadingWhitespace:d.firstChild.nodeType===3,tbody:!d.getElementsByTagName("tbody").length,htmlSerialize:!!d.getElementsByTagName("link").length,style:/red/.test(h.getAttribute("style")),hrefNormalized:h.getAttribute("href")==="/a",opacity:/^0.55$/.test(h.style.opacity),cssFloat:!!h.style.cssFloat,checkOn:d.getElementsByTagName("input")[0].value==="on",optSelected:k.selected,deleteExpando:true,optDisabled:false,checkClone:false,
+scriptEval:false,noCloneEvent:true,boxModel:null,inlineBlockNeedsLayout:false,shrinkWrapBlocks:false,reliableHiddenOffsets:true};l.disabled=true;c.support.optDisabled=!k.disabled;b.type="text/javascript";try{b.appendChild(t.createTextNode("window."+e+"=1;"))}catch(o){}a.insertBefore(b,a.firstChild);if(E[e]){c.support.scriptEval=true;delete E[e]}try{delete b.test}catch(x){c.support.deleteExpando=false}a.removeChild(b);if(d.attachEvent&&d.fireEvent){d.attachEvent("onclick",function r(){c.support.noCloneEvent=
+false;d.detachEvent("onclick",r)});d.cloneNode(true).fireEvent("onclick")}d=t.createElement("div");d.innerHTML="<input type='radio' name='radiotest' checked='checked'/>";a=t.createDocumentFragment();a.appendChild(d.firstChild);c.support.checkClone=a.cloneNode(true).cloneNode(true).lastChild.checked;c(function(){var r=t.createElement("div");r.style.width=r.style.paddingLeft="1px";t.body.appendChild(r);c.boxModel=c.support.boxModel=r.offsetWidth===2;if("zoom"in r.style){r.style.display="inline";r.style.zoom=
+1;c.support.inlineBlockNeedsLayout=r.offsetWidth===2;r.style.display="";r.innerHTML="<div style='width:4px;'></div>";c.support.shrinkWrapBlocks=r.offsetWidth!==2}r.innerHTML="<table><tr><td style='padding:0;display:none'></td><td>t</td></tr></table>";var A=r.getElementsByTagName("td");c.support.reliableHiddenOffsets=A[0].offsetHeight===0;A[0].style.display="";A[1].style.display="none";c.support.reliableHiddenOffsets=c.support.reliableHiddenOffsets&&A[0].offsetHeight===0;r.innerHTML="";t.body.removeChild(r).style.display=
+"none"});a=function(r){var A=t.createElement("div");r="on"+r;var C=r in A;if(!C){A.setAttribute(r,"return;");C=typeof A[r]==="function"}return C};c.support.submitBubbles=a("submit");c.support.changeBubbles=a("change");a=b=d=f=h=null}})();var ra={},Ja=/^(?:\{.*\}|\[.*\])$/;c.extend({cache:{},uuid:0,expando:"jQuery"+c.now(),noData:{embed:true,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:true},data:function(a,b,d){if(c.acceptData(a)){a=a==E?ra:a;var e=a.nodeType,f=e?a[c.expando]:null,h=
+c.cache;if(!(e&&!f&&typeof b==="string"&&d===B)){if(e)f||(a[c.expando]=f=++c.uuid);else h=a;if(typeof b==="object")if(e)h[f]=c.extend(h[f],b);else c.extend(h,b);else if(e&&!h[f])h[f]={};a=e?h[f]:h;if(d!==B)a[b]=d;return typeof b==="string"?a[b]:a}}},removeData:function(a,b){if(c.acceptData(a)){a=a==E?ra:a;var d=a.nodeType,e=d?a[c.expando]:a,f=c.cache,h=d?f[e]:e;if(b){if(h){delete h[b];d&&c.isEmptyObject(h)&&c.removeData(a)}}else if(d&&c.support.deleteExpando)delete a[c.expando];else if(a.removeAttribute)a.removeAttribute(c.expando);
+else if(d)delete f[e];else for(var l in a)delete a[l]}},acceptData:function(a){if(a.nodeName){var b=c.noData[a.nodeName.toLowerCase()];if(b)return!(b===true||a.getAttribute("classid")!==b)}return true}});c.fn.extend({data:function(a,b){var d=null;if(typeof a==="undefined"){if(this.length){var e=this[0].attributes,f;d=c.data(this[0]);for(var h=0,l=e.length;h<l;h++){f=e[h].name;if(f.indexOf("data-")===0){f=f.substr(5);ka(this[0],f,d[f])}}}return d}else if(typeof a==="object")return this.each(function(){c.data(this,
+a)});var k=a.split(".");k[1]=k[1]?"."+k[1]:"";if(b===B){d=this.triggerHandler("getData"+k[1]+"!",[k[0]]);if(d===B&&this.length){d=c.data(this[0],a);d=ka(this[0],a,d)}return d===B&&k[1]?this.data(k[0]):d}else return this.each(function(){var o=c(this),x=[k[0],b];o.triggerHandler("setData"+k[1]+"!",x);c.data(this,a,b);o.triggerHandler("changeData"+k[1]+"!",x)})},removeData:function(a){return this.each(function(){c.removeData(this,a)})}});c.extend({queue:function(a,b,d){if(a){b=(b||"fx")+"queue";var e=
+c.data(a,b);if(!d)return e||[];if(!e||c.isArray(d))e=c.data(a,b,c.makeArray(d));else e.push(d);return e}},dequeue:function(a,b){b=b||"fx";var d=c.queue(a,b),e=d.shift();if(e==="inprogress")e=d.shift();if(e){b==="fx"&&d.unshift("inprogress");e.call(a,function(){c.dequeue(a,b)})}}});c.fn.extend({queue:function(a,b){if(typeof a!=="string"){b=a;a="fx"}if(b===B)return c.queue(this[0],a);return this.each(function(){var d=c.queue(this,a,b);a==="fx"&&d[0]!=="inprogress"&&c.dequeue(this,a)})},dequeue:function(a){return this.each(function(){c.dequeue(this,
+a)})},delay:function(a,b){a=c.fx?c.fx.speeds[a]||a:a;b=b||"fx";return this.queue(b,function(){var d=this;setTimeout(function(){c.dequeue(d,b)},a)})},clearQueue:function(a){return this.queue(a||"fx",[])}});var sa=/[\n\t]/g,ha=/\s+/,Sa=/\r/g,Ta=/^(?:href|src|style)$/,Ua=/^(?:button|input)$/i,Va=/^(?:button|input|object|select|textarea)$/i,Wa=/^a(?:rea)?$/i,ta=/^(?:radio|checkbox)$/i;c.props={"for":"htmlFor","class":"className",readonly:"readOnly",maxlength:"maxLength",cellspacing:"cellSpacing",rowspan:"rowSpan",
+colspan:"colSpan",tabindex:"tabIndex",usemap:"useMap",frameborder:"frameBorder"};c.fn.extend({attr:function(a,b){return c.access(this,a,b,true,c.attr)},removeAttr:function(a){return this.each(function(){c.attr(this,a,"");this.nodeType===1&&this.removeAttribute(a)})},addClass:function(a){if(c.isFunction(a))return this.each(function(x){var r=c(this);r.addClass(a.call(this,x,r.attr("class")))});if(a&&typeof a==="string")for(var b=(a||"").split(ha),d=0,e=this.length;d<e;d++){var f=this[d];if(f.nodeType===
+1)if(f.className){for(var h=" "+f.className+" ",l=f.className,k=0,o=b.length;k<o;k++)if(h.indexOf(" "+b[k]+" ")<0)l+=" "+b[k];f.className=c.trim(l)}else f.className=a}return this},removeClass:function(a){if(c.isFunction(a))return this.each(function(o){var x=c(this);x.removeClass(a.call(this,o,x.attr("class")))});if(a&&typeof a==="string"||a===B)for(var b=(a||"").split(ha),d=0,e=this.length;d<e;d++){var f=this[d];if(f.nodeType===1&&f.className)if(a){for(var h=(" "+f.className+" ").replace(sa," "),
+l=0,k=b.length;l<k;l++)h=h.replace(" "+b[l]+" "," ");f.className=c.trim(h)}else f.className=""}return this},toggleClass:function(a,b){var d=typeof a,e=typeof b==="boolean";if(c.isFunction(a))return this.each(function(f){var h=c(this);h.toggleClass(a.call(this,f,h.attr("class"),b),b)});return this.each(function(){if(d==="string")for(var f,h=0,l=c(this),k=b,o=a.split(ha);f=o[h++];){k=e?k:!l.hasClass(f);l[k?"addClass":"removeClass"](f)}else if(d==="undefined"||d==="boolean"){this.className&&c.data(this,
+"__className__",this.className);this.className=this.className||a===false?"":c.data(this,"__className__")||""}})},hasClass:function(a){a=" "+a+" ";for(var b=0,d=this.length;b<d;b++)if((" "+this[b].className+" ").replace(sa," ").indexOf(a)>-1)return true;return false},val:function(a){if(!arguments.length){var b=this[0];if(b){if(c.nodeName(b,"option")){var d=b.attributes.value;return!d||d.specified?b.value:b.text}if(c.nodeName(b,"select")){var e=b.selectedIndex;d=[];var f=b.options;b=b.type==="select-one";
+if(e<0)return null;var h=b?e:0;for(e=b?e+1:f.length;h<e;h++){var l=f[h];if(l.selected&&(c.support.optDisabled?!l.disabled:l.getAttribute("disabled")===null)&&(!l.parentNode.disabled||!c.nodeName(l.parentNode,"optgroup"))){a=c(l).val();if(b)return a;d.push(a)}}return d}if(ta.test(b.type)&&!c.support.checkOn)return b.getAttribute("value")===null?"on":b.value;return(b.value||"").replace(Sa,"")}return B}var k=c.isFunction(a);return this.each(function(o){var x=c(this),r=a;if(this.nodeType===1){if(k)r=
+a.call(this,o,x.val());if(r==null)r="";else if(typeof r==="number")r+="";else if(c.isArray(r))r=c.map(r,function(C){return C==null?"":C+""});if(c.isArray(r)&&ta.test(this.type))this.checked=c.inArray(x.val(),r)>=0;else if(c.nodeName(this,"select")){var A=c.makeArray(r);c("option",this).each(function(){this.selected=c.inArray(c(this).val(),A)>=0});if(!A.length)this.selectedIndex=-1}else this.value=r}})}});c.extend({attrFn:{val:true,css:true,html:true,text:true,data:true,width:true,height:true,offset:true},
+attr:function(a,b,d,e){if(!a||a.nodeType===3||a.nodeType===8)return B;if(e&&b in c.attrFn)return c(a)[b](d);e=a.nodeType!==1||!c.isXMLDoc(a);var f=d!==B;b=e&&c.props[b]||b;var h=Ta.test(b);if((b in a||a[b]!==B)&&e&&!h){if(f){b==="type"&&Ua.test(a.nodeName)&&a.parentNode&&c.error("type property can't be changed");if(d===null)a.nodeType===1&&a.removeAttribute(b);else a[b]=d}if(c.nodeName(a,"form")&&a.getAttributeNode(b))return a.getAttributeNode(b).nodeValue;if(b==="tabIndex")return(b=a.getAttributeNode("tabIndex"))&&
+b.specified?b.value:Va.test(a.nodeName)||Wa.test(a.nodeName)&&a.href?0:B;return a[b]}if(!c.support.style&&e&&b==="style"){if(f)a.style.cssText=""+d;return a.style.cssText}f&&a.setAttribute(b,""+d);if(!a.attributes[b]&&a.hasAttribute&&!a.hasAttribute(b))return B;a=!c.support.hrefNormalized&&e&&h?a.getAttribute(b,2):a.getAttribute(b);return a===null?B:a}});var X=/\.(.*)$/,ia=/^(?:textarea|input|select)$/i,La=/\./g,Ma=/ /g,Xa=/[^\w\s.|`]/g,Ya=function(a){return a.replace(Xa,"\\$&")},ua={focusin:0,focusout:0};
+c.event={add:function(a,b,d,e){if(!(a.nodeType===3||a.nodeType===8)){if(c.isWindow(a)&&a!==E&&!a.frameElement)a=E;if(d===false)d=U;else if(!d)return;var f,h;if(d.handler){f=d;d=f.handler}if(!d.guid)d.guid=c.guid++;if(h=c.data(a)){var l=a.nodeType?"events":"__events__",k=h[l],o=h.handle;if(typeof k==="function"){o=k.handle;k=k.events}else if(!k){a.nodeType||(h[l]=h=function(){});h.events=k={}}if(!o)h.handle=o=function(){return typeof c!=="undefined"&&!c.event.triggered?c.event.handle.apply(o.elem,
+arguments):B};o.elem=a;b=b.split(" ");for(var x=0,r;l=b[x++];){h=f?c.extend({},f):{handler:d,data:e};if(l.indexOf(".")>-1){r=l.split(".");l=r.shift();h.namespace=r.slice(0).sort().join(".")}else{r=[];h.namespace=""}h.type=l;if(!h.guid)h.guid=d.guid;var A=k[l],C=c.event.special[l]||{};if(!A){A=k[l]=[];if(!C.setup||C.setup.call(a,e,r,o)===false)if(a.addEventListener)a.addEventListener(l,o,false);else a.attachEvent&&a.attachEvent("on"+l,o)}if(C.add){C.add.call(a,h);if(!h.handler.guid)h.handler.guid=
+d.guid}A.push(h);c.event.global[l]=true}a=null}}},global:{},remove:function(a,b,d,e){if(!(a.nodeType===3||a.nodeType===8)){if(d===false)d=U;var f,h,l=0,k,o,x,r,A,C,J=a.nodeType?"events":"__events__",w=c.data(a),I=w&&w[J];if(w&&I){if(typeof I==="function"){w=I;I=I.events}if(b&&b.type){d=b.handler;b=b.type}if(!b||typeof b==="string"&&b.charAt(0)==="."){b=b||"";for(f in I)c.event.remove(a,f+b)}else{for(b=b.split(" ");f=b[l++];){r=f;k=f.indexOf(".")<0;o=[];if(!k){o=f.split(".");f=o.shift();x=RegExp("(^|\\.)"+
+c.map(o.slice(0).sort(),Ya).join("\\.(?:.*\\.)?")+"(\\.|$)")}if(A=I[f])if(d){r=c.event.special[f]||{};for(h=e||0;h<A.length;h++){C=A[h];if(d.guid===C.guid){if(k||x.test(C.namespace)){e==null&&A.splice(h--,1);r.remove&&r.remove.call(a,C)}if(e!=null)break}}if(A.length===0||e!=null&&A.length===1){if(!r.teardown||r.teardown.call(a,o)===false)c.removeEvent(a,f,w.handle);delete I[f]}}else for(h=0;h<A.length;h++){C=A[h];if(k||x.test(C.namespace)){c.event.remove(a,r,C.handler,h);A.splice(h--,1)}}}if(c.isEmptyObject(I)){if(b=
+w.handle)b.elem=null;delete w.events;delete w.handle;if(typeof w==="function")c.removeData(a,J);else c.isEmptyObject(w)&&c.removeData(a)}}}}},trigger:function(a,b,d,e){var f=a.type||a;if(!e){a=typeof a==="object"?a[c.expando]?a:c.extend(c.Event(f),a):c.Event(f);if(f.indexOf("!")>=0){a.type=f=f.slice(0,-1);a.exclusive=true}if(!d){a.stopPropagation();c.event.global[f]&&c.each(c.cache,function(){this.events&&this.events[f]&&c.event.trigger(a,b,this.handle.elem)})}if(!d||d.nodeType===3||d.nodeType===
+8)return B;a.result=B;a.target=d;b=c.makeArray(b);b.unshift(a)}a.currentTarget=d;(e=d.nodeType?c.data(d,"handle"):(c.data(d,"__events__")||{}).handle)&&e.apply(d,b);e=d.parentNode||d.ownerDocument;try{if(!(d&&d.nodeName&&c.noData[d.nodeName.toLowerCase()]))if(d["on"+f]&&d["on"+f].apply(d,b)===false){a.result=false;a.preventDefault()}}catch(h){}if(!a.isPropagationStopped()&&e)c.event.trigger(a,b,e,true);else if(!a.isDefaultPrevented()){var l;e=a.target;var k=f.replace(X,""),o=c.nodeName(e,"a")&&k===
+"click",x=c.event.special[k]||{};if((!x._default||x._default.call(d,a)===false)&&!o&&!(e&&e.nodeName&&c.noData[e.nodeName.toLowerCase()])){try{if(e[k]){if(l=e["on"+k])e["on"+k]=null;c.event.triggered=true;e[k]()}}catch(r){}if(l)e["on"+k]=l;c.event.triggered=false}}},handle:function(a){var b,d,e,f;d=[];var h=c.makeArray(arguments);a=h[0]=c.event.fix(a||E.event);a.currentTarget=this;b=a.type.indexOf(".")<0&&!a.exclusive;if(!b){e=a.type.split(".");a.type=e.shift();d=e.slice(0).sort();e=RegExp("(^|\\.)"+
+d.join("\\.(?:.*\\.)?")+"(\\.|$)")}a.namespace=a.namespace||d.join(".");f=c.data(this,this.nodeType?"events":"__events__");if(typeof f==="function")f=f.events;d=(f||{})[a.type];if(f&&d){d=d.slice(0);f=0;for(var l=d.length;f<l;f++){var k=d[f];if(b||e.test(k.namespace)){a.handler=k.handler;a.data=k.data;a.handleObj=k;k=k.handler.apply(this,h);if(k!==B){a.result=k;if(k===false){a.preventDefault();a.stopPropagation()}}if(a.isImmediatePropagationStopped())break}}}return a.result},props:"altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode layerX layerY metaKey newValue offsetX offsetY pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),
+fix:function(a){if(a[c.expando])return a;var b=a;a=c.Event(b);for(var d=this.props.length,e;d;){e=this.props[--d];a[e]=b[e]}if(!a.target)a.target=a.srcElement||t;if(a.target.nodeType===3)a.target=a.target.parentNode;if(!a.relatedTarget&&a.fromElement)a.relatedTarget=a.fromElement===a.target?a.toElement:a.fromElement;if(a.pageX==null&&a.clientX!=null){b=t.documentElement;d=t.body;a.pageX=a.clientX+(b&&b.scrollLeft||d&&d.scrollLeft||0)-(b&&b.clientLeft||d&&d.clientLeft||0);a.pageY=a.clientY+(b&&b.scrollTop||
+d&&d.scrollTop||0)-(b&&b.clientTop||d&&d.clientTop||0)}if(a.which==null&&(a.charCode!=null||a.keyCode!=null))a.which=a.charCode!=null?a.charCode:a.keyCode;if(!a.metaKey&&a.ctrlKey)a.metaKey=a.ctrlKey;if(!a.which&&a.button!==B)a.which=a.button&1?1:a.button&2?3:a.button&4?2:0;return a},guid:1E8,proxy:c.proxy,special:{ready:{setup:c.bindReady,teardown:c.noop},live:{add:function(a){c.event.add(this,Y(a.origType,a.selector),c.extend({},a,{handler:Ka,guid:a.handler.guid}))},remove:function(a){c.event.remove(this,
+Y(a.origType,a.selector),a)}},beforeunload:{setup:function(a,b,d){if(c.isWindow(this))this.onbeforeunload=d},teardown:function(a,b){if(this.onbeforeunload===b)this.onbeforeunload=null}}}};c.removeEvent=t.removeEventListener?function(a,b,d){a.removeEventListener&&a.removeEventListener(b,d,false)}:function(a,b,d){a.detachEvent&&a.detachEvent("on"+b,d)};c.Event=function(a){if(!this.preventDefault)return new c.Event(a);if(a&&a.type){this.originalEvent=a;this.type=a.type}else this.type=a;this.timeStamp=
+c.now();this[c.expando]=true};c.Event.prototype={preventDefault:function(){this.isDefaultPrevented=ca;var a=this.originalEvent;if(a)if(a.preventDefault)a.preventDefault();else a.returnValue=false},stopPropagation:function(){this.isPropagationStopped=ca;var a=this.originalEvent;if(a){a.stopPropagation&&a.stopPropagation();a.cancelBubble=true}},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=ca;this.stopPropagation()},isDefaultPrevented:U,isPropagationStopped:U,isImmediatePropagationStopped:U};
+var va=function(a){var b=a.relatedTarget;try{for(;b&&b!==this;)b=b.parentNode;if(b!==this){a.type=a.data;c.event.handle.apply(this,arguments)}}catch(d){}},wa=function(a){a.type=a.data;c.event.handle.apply(this,arguments)};c.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(a,b){c.event.special[a]={setup:function(d){c.event.add(this,b,d&&d.selector?wa:va,a)},teardown:function(d){c.event.remove(this,b,d&&d.selector?wa:va)}}});if(!c.support.submitBubbles)c.event.special.submit={setup:function(){if(this.nodeName.toLowerCase()!==
+"form"){c.event.add(this,"click.specialSubmit",function(a){var b=a.target,d=b.type;if((d==="submit"||d==="image")&&c(b).closest("form").length){a.liveFired=B;return la("submit",this,arguments)}});c.event.add(this,"keypress.specialSubmit",function(a){var b=a.target,d=b.type;if((d==="text"||d==="password")&&c(b).closest("form").length&&a.keyCode===13){a.liveFired=B;return la("submit",this,arguments)}})}else return false},teardown:function(){c.event.remove(this,".specialSubmit")}};if(!c.support.changeBubbles){var V,
+xa=function(a){var b=a.type,d=a.value;if(b==="radio"||b==="checkbox")d=a.checked;else if(b==="select-multiple")d=a.selectedIndex>-1?c.map(a.options,function(e){return e.selected}).join("-"):"";else if(a.nodeName.toLowerCase()==="select")d=a.selectedIndex;return d},Z=function(a,b){var d=a.target,e,f;if(!(!ia.test(d.nodeName)||d.readOnly)){e=c.data(d,"_change_data");f=xa(d);if(a.type!=="focusout"||d.type!=="radio")c.data(d,"_change_data",f);if(!(e===B||f===e))if(e!=null||f){a.type="change";a.liveFired=
+B;return c.event.trigger(a,b,d)}}};c.event.special.change={filters:{focusout:Z,beforedeactivate:Z,click:function(a){var b=a.target,d=b.type;if(d==="radio"||d==="checkbox"||b.nodeName.toLowerCase()==="select")return Z.call(this,a)},keydown:function(a){var b=a.target,d=b.type;if(a.keyCode===13&&b.nodeName.toLowerCase()!=="textarea"||a.keyCode===32&&(d==="checkbox"||d==="radio")||d==="select-multiple")return Z.call(this,a)},beforeactivate:function(a){a=a.target;c.data(a,"_change_data",xa(a))}},setup:function(){if(this.type===
+"file")return false;for(var a in V)c.event.add(this,a+".specialChange",V[a]);return ia.test(this.nodeName)},teardown:function(){c.event.remove(this,".specialChange");return ia.test(this.nodeName)}};V=c.event.special.change.filters;V.focus=V.beforeactivate}t.addEventListener&&c.each({focus:"focusin",blur:"focusout"},function(a,b){function d(e){e=c.event.fix(e);e.type=b;return c.event.trigger(e,null,e.target)}c.event.special[b]={setup:function(){ua[b]++===0&&t.addEventListener(a,d,true)},teardown:function(){--ua[b]===
+0&&t.removeEventListener(a,d,true)}}});c.each(["bind","one"],function(a,b){c.fn[b]=function(d,e,f){if(typeof d==="object"){for(var h in d)this[b](h,e,d[h],f);return this}if(c.isFunction(e)||e===false){f=e;e=B}var l=b==="one"?c.proxy(f,function(o){c(this).unbind(o,l);return f.apply(this,arguments)}):f;if(d==="unload"&&b!=="one")this.one(d,e,f);else{h=0;for(var k=this.length;h<k;h++)c.event.add(this[h],d,l,e)}return this}});c.fn.extend({unbind:function(a,b){if(typeof a==="object"&&!a.preventDefault)for(var d in a)this.unbind(d,
+a[d]);else{d=0;for(var e=this.length;d<e;d++)c.event.remove(this[d],a,b)}return this},delegate:function(a,b,d,e){return this.live(b,d,e,a)},undelegate:function(a,b,d){return arguments.length===0?this.unbind("live"):this.die(b,null,d,a)},trigger:function(a,b){return this.each(function(){c.event.trigger(a,b,this)})},triggerHandler:function(a,b){if(this[0]){var d=c.Event(a);d.preventDefault();d.stopPropagation();c.event.trigger(d,b,this[0]);return d.result}},toggle:function(a){for(var b=arguments,d=
+1;d<b.length;)c.proxy(a,b[d++]);return this.click(c.proxy(a,function(e){var f=(c.data(this,"lastToggle"+a.guid)||0)%d;c.data(this,"lastToggle"+a.guid,f+1);e.preventDefault();return b[f].apply(this,arguments)||false}))},hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)}});var ya={focus:"focusin",blur:"focusout",mouseenter:"mouseover",mouseleave:"mouseout"};c.each(["live","die"],function(a,b){c.fn[b]=function(d,e,f,h){var l,k=0,o,x,r=h||this.selector;h=h?this:c(this.context);if(typeof d===
+"object"&&!d.preventDefault){for(l in d)h[b](l,e,d[l],r);return this}if(c.isFunction(e)){f=e;e=B}for(d=(d||"").split(" ");(l=d[k++])!=null;){o=X.exec(l);x="";if(o){x=o[0];l=l.replace(X,"")}if(l==="hover")d.push("mouseenter"+x,"mouseleave"+x);else{o=l;if(l==="focus"||l==="blur"){d.push(ya[l]+x);l+=x}else l=(ya[l]||l)+x;if(b==="live"){x=0;for(var A=h.length;x<A;x++)c.event.add(h[x],"live."+Y(l,r),{data:e,selector:r,handler:f,origType:l,origHandler:f,preType:o})}else h.unbind("live."+Y(l,r),f)}}return this}});
+c.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error".split(" "),function(a,b){c.fn[b]=function(d,e){if(e==null){e=d;d=null}return arguments.length>0?this.bind(b,d,e):this.trigger(b)};if(c.attrFn)c.attrFn[b]=true});E.attachEvent&&!E.addEventListener&&c(E).bind("unload",function(){for(var a in c.cache)if(c.cache[a].handle)try{c.event.remove(c.cache[a].handle.elem)}catch(b){}});
+(function(){function a(g,i,n,m,p,q){p=0;for(var u=m.length;p<u;p++){var y=m[p];if(y){var F=false;for(y=y[g];y;){if(y.sizcache===n){F=m[y.sizset];break}if(y.nodeType===1&&!q){y.sizcache=n;y.sizset=p}if(y.nodeName.toLowerCase()===i){F=y;break}y=y[g]}m[p]=F}}}function b(g,i,n,m,p,q){p=0;for(var u=m.length;p<u;p++){var y=m[p];if(y){var F=false;for(y=y[g];y;){if(y.sizcache===n){F=m[y.sizset];break}if(y.nodeType===1){if(!q){y.sizcache=n;y.sizset=p}if(typeof i!=="string"){if(y===i){F=true;break}}else if(k.filter(i,
+[y]).length>0){F=y;break}}y=y[g]}m[p]=F}}}var d=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,e=0,f=Object.prototype.toString,h=false,l=true;[0,0].sort(function(){l=false;return 0});var k=function(g,i,n,m){n=n||[];var p=i=i||t;if(i.nodeType!==1&&i.nodeType!==9)return[];if(!g||typeof g!=="string")return n;var q,u,y,F,M,N=true,O=k.isXML(i),D=[],R=g;do{d.exec("");if(q=d.exec(R)){R=q[3];D.push(q[1]);if(q[2]){F=q[3];
+break}}}while(q);if(D.length>1&&x.exec(g))if(D.length===2&&o.relative[D[0]])u=L(D[0]+D[1],i);else for(u=o.relative[D[0]]?[i]:k(D.shift(),i);D.length;){g=D.shift();if(o.relative[g])g+=D.shift();u=L(g,u)}else{if(!m&&D.length>1&&i.nodeType===9&&!O&&o.match.ID.test(D[0])&&!o.match.ID.test(D[D.length-1])){q=k.find(D.shift(),i,O);i=q.expr?k.filter(q.expr,q.set)[0]:q.set[0]}if(i){q=m?{expr:D.pop(),set:C(m)}:k.find(D.pop(),D.length===1&&(D[0]==="~"||D[0]==="+")&&i.parentNode?i.parentNode:i,O);u=q.expr?k.filter(q.expr,
+q.set):q.set;if(D.length>0)y=C(u);else N=false;for(;D.length;){q=M=D.pop();if(o.relative[M])q=D.pop();else M="";if(q==null)q=i;o.relative[M](y,q,O)}}else y=[]}y||(y=u);y||k.error(M||g);if(f.call(y)==="[object Array]")if(N)if(i&&i.nodeType===1)for(g=0;y[g]!=null;g++){if(y[g]&&(y[g]===true||y[g].nodeType===1&&k.contains(i,y[g])))n.push(u[g])}else for(g=0;y[g]!=null;g++)y[g]&&y[g].nodeType===1&&n.push(u[g]);else n.push.apply(n,y);else C(y,n);if(F){k(F,p,n,m);k.uniqueSort(n)}return n};k.uniqueSort=function(g){if(w){h=
+l;g.sort(w);if(h)for(var i=1;i<g.length;i++)g[i]===g[i-1]&&g.splice(i--,1)}return g};k.matches=function(g,i){return k(g,null,null,i)};k.matchesSelector=function(g,i){return k(i,null,null,[g]).length>0};k.find=function(g,i,n){var m;if(!g)return[];for(var p=0,q=o.order.length;p<q;p++){var u,y=o.order[p];if(u=o.leftMatch[y].exec(g)){var F=u[1];u.splice(1,1);if(F.substr(F.length-1)!=="\\"){u[1]=(u[1]||"").replace(/\\/g,"");m=o.find[y](u,i,n);if(m!=null){g=g.replace(o.match[y],"");break}}}}m||(m=i.getElementsByTagName("*"));
+return{set:m,expr:g}};k.filter=function(g,i,n,m){for(var p,q,u=g,y=[],F=i,M=i&&i[0]&&k.isXML(i[0]);g&&i.length;){for(var N in o.filter)if((p=o.leftMatch[N].exec(g))!=null&&p[2]){var O,D,R=o.filter[N];D=p[1];q=false;p.splice(1,1);if(D.substr(D.length-1)!=="\\"){if(F===y)y=[];if(o.preFilter[N])if(p=o.preFilter[N](p,F,n,y,m,M)){if(p===true)continue}else q=O=true;if(p)for(var j=0;(D=F[j])!=null;j++)if(D){O=R(D,p,j,F);var s=m^!!O;if(n&&O!=null)if(s)q=true;else F[j]=false;else if(s){y.push(D);q=true}}if(O!==
+B){n||(F=y);g=g.replace(o.match[N],"");if(!q)return[];break}}}if(g===u)if(q==null)k.error(g);else break;u=g}return F};k.error=function(g){throw"Syntax error, unrecognized expression: "+g;};var o=k.selectors={order:["ID","NAME","TAG"],match:{ID:/#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,CLASS:/\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,NAME:/\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,ATTR:/\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/,TAG:/^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,CHILD:/:(only|nth|last|first)-child(?:\((even|odd|[\dn+\-]*)\))?/,
+POS:/:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,PSEUDO:/:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/},leftMatch:{},attrMap:{"class":"className","for":"htmlFor"},attrHandle:{href:function(g){return g.getAttribute("href")}},relative:{"+":function(g,i){var n=typeof i==="string",m=n&&!/\W/.test(i);n=n&&!m;if(m)i=i.toLowerCase();m=0;for(var p=g.length,q;m<p;m++)if(q=g[m]){for(;(q=q.previousSibling)&&q.nodeType!==1;);g[m]=n||q&&q.nodeName.toLowerCase()===
+i?q||false:q===i}n&&k.filter(i,g,true)},">":function(g,i){var n,m=typeof i==="string",p=0,q=g.length;if(m&&!/\W/.test(i))for(i=i.toLowerCase();p<q;p++){if(n=g[p]){n=n.parentNode;g[p]=n.nodeName.toLowerCase()===i?n:false}}else{for(;p<q;p++)if(n=g[p])g[p]=m?n.parentNode:n.parentNode===i;m&&k.filter(i,g,true)}},"":function(g,i,n){var m,p=e++,q=b;if(typeof i==="string"&&!/\W/.test(i)){m=i=i.toLowerCase();q=a}q("parentNode",i,p,g,m,n)},"~":function(g,i,n){var m,p=e++,q=b;if(typeof i==="string"&&!/\W/.test(i)){m=
+i=i.toLowerCase();q=a}q("previousSibling",i,p,g,m,n)}},find:{ID:function(g,i,n){if(typeof i.getElementById!=="undefined"&&!n)return(g=i.getElementById(g[1]))&&g.parentNode?[g]:[]},NAME:function(g,i){if(typeof i.getElementsByName!=="undefined"){for(var n=[],m=i.getElementsByName(g[1]),p=0,q=m.length;p<q;p++)m[p].getAttribute("name")===g[1]&&n.push(m[p]);return n.length===0?null:n}},TAG:function(g,i){return i.getElementsByTagName(g[1])}},preFilter:{CLASS:function(g,i,n,m,p,q){g=" "+g[1].replace(/\\/g,
+"")+" ";if(q)return g;q=0;for(var u;(u=i[q])!=null;q++)if(u)if(p^(u.className&&(" "+u.className+" ").replace(/[\t\n]/g," ").indexOf(g)>=0))n||m.push(u);else if(n)i[q]=false;return false},ID:function(g){return g[1].replace(/\\/g,"")},TAG:function(g){return g[1].toLowerCase()},CHILD:function(g){if(g[1]==="nth"){var i=/(-?)(\d*)n((?:\+|-)?\d*)/.exec(g[2]==="even"&&"2n"||g[2]==="odd"&&"2n+1"||!/\D/.test(g[2])&&"0n+"+g[2]||g[2]);g[2]=i[1]+(i[2]||1)-0;g[3]=i[3]-0}g[0]=e++;return g},ATTR:function(g,i,n,
+m,p,q){i=g[1].replace(/\\/g,"");if(!q&&o.attrMap[i])g[1]=o.attrMap[i];if(g[2]==="~=")g[4]=" "+g[4]+" ";return g},PSEUDO:function(g,i,n,m,p){if(g[1]==="not")if((d.exec(g[3])||"").length>1||/^\w/.test(g[3]))g[3]=k(g[3],null,null,i);else{g=k.filter(g[3],i,n,true^p);n||m.push.apply(m,g);return false}else if(o.match.POS.test(g[0])||o.match.CHILD.test(g[0]))return true;return g},POS:function(g){g.unshift(true);return g}},filters:{enabled:function(g){return g.disabled===false&&g.type!=="hidden"},disabled:function(g){return g.disabled===
+true},checked:function(g){return g.checked===true},selected:function(g){return g.selected===true},parent:function(g){return!!g.firstChild},empty:function(g){return!g.firstChild},has:function(g,i,n){return!!k(n[3],g).length},header:function(g){return/h\d/i.test(g.nodeName)},text:function(g){return"text"===g.type},radio:function(g){return"radio"===g.type},checkbox:function(g){return"checkbox"===g.type},file:function(g){return"file"===g.type},password:function(g){return"password"===g.type},submit:function(g){return"submit"===
+g.type},image:function(g){return"image"===g.type},reset:function(g){return"reset"===g.type},button:function(g){return"button"===g.type||g.nodeName.toLowerCase()==="button"},input:function(g){return/input|select|textarea|button/i.test(g.nodeName)}},setFilters:{first:function(g,i){return i===0},last:function(g,i,n,m){return i===m.length-1},even:function(g,i){return i%2===0},odd:function(g,i){return i%2===1},lt:function(g,i,n){return i<n[3]-0},gt:function(g,i,n){return i>n[3]-0},nth:function(g,i,n){return n[3]-
+0===i},eq:function(g,i,n){return n[3]-0===i}},filter:{PSEUDO:function(g,i,n,m){var p=i[1],q=o.filters[p];if(q)return q(g,n,i,m);else if(p==="contains")return(g.textContent||g.innerText||k.getText([g])||"").indexOf(i[3])>=0;else if(p==="not"){i=i[3];n=0;for(m=i.length;n<m;n++)if(i[n]===g)return false;return true}else k.error("Syntax error, unrecognized expression: "+p)},CHILD:function(g,i){var n=i[1],m=g;switch(n){case "only":case "first":for(;m=m.previousSibling;)if(m.nodeType===1)return false;if(n===
+"first")return true;m=g;case "last":for(;m=m.nextSibling;)if(m.nodeType===1)return false;return true;case "nth":n=i[2];var p=i[3];if(n===1&&p===0)return true;var q=i[0],u=g.parentNode;if(u&&(u.sizcache!==q||!g.nodeIndex)){var y=0;for(m=u.firstChild;m;m=m.nextSibling)if(m.nodeType===1)m.nodeIndex=++y;u.sizcache=q}m=g.nodeIndex-p;return n===0?m===0:m%n===0&&m/n>=0}},ID:function(g,i){return g.nodeType===1&&g.getAttribute("id")===i},TAG:function(g,i){return i==="*"&&g.nodeType===1||g.nodeName.toLowerCase()===
+i},CLASS:function(g,i){return(" "+(g.className||g.getAttribute("class"))+" ").indexOf(i)>-1},ATTR:function(g,i){var n=i[1];n=o.attrHandle[n]?o.attrHandle[n](g):g[n]!=null?g[n]:g.getAttribute(n);var m=n+"",p=i[2],q=i[4];return n==null?p==="!=":p==="="?m===q:p==="*="?m.indexOf(q)>=0:p==="~="?(" "+m+" ").indexOf(q)>=0:!q?m&&n!==false:p==="!="?m!==q:p==="^="?m.indexOf(q)===0:p==="$="?m.substr(m.length-q.length)===q:p==="|="?m===q||m.substr(0,q.length+1)===q+"-":false},POS:function(g,i,n,m){var p=o.setFilters[i[2]];
+if(p)return p(g,n,i,m)}}},x=o.match.POS,r=function(g,i){return"\\"+(i-0+1)},A;for(A in o.match){o.match[A]=RegExp(o.match[A].source+/(?![^\[]*\])(?![^\(]*\))/.source);o.leftMatch[A]=RegExp(/(^(?:.|\r|\n)*?)/.source+o.match[A].source.replace(/\\(\d+)/g,r))}var C=function(g,i){g=Array.prototype.slice.call(g,0);if(i){i.push.apply(i,g);return i}return g};try{Array.prototype.slice.call(t.documentElement.childNodes,0)}catch(J){C=function(g,i){var n=0,m=i||[];if(f.call(g)==="[object Array]")Array.prototype.push.apply(m,
+g);else if(typeof g.length==="number")for(var p=g.length;n<p;n++)m.push(g[n]);else for(;g[n];n++)m.push(g[n]);return m}}var w,I;if(t.documentElement.compareDocumentPosition)w=function(g,i){if(g===i){h=true;return 0}if(!g.compareDocumentPosition||!i.compareDocumentPosition)return g.compareDocumentPosition?-1:1;return g.compareDocumentPosition(i)&4?-1:1};else{w=function(g,i){var n,m,p=[],q=[];n=g.parentNode;m=i.parentNode;var u=n;if(g===i){h=true;return 0}else if(n===m)return I(g,i);else if(n){if(!m)return 1}else return-1;
+for(;u;){p.unshift(u);u=u.parentNode}for(u=m;u;){q.unshift(u);u=u.parentNode}n=p.length;m=q.length;for(u=0;u<n&&u<m;u++)if(p[u]!==q[u])return I(p[u],q[u]);return u===n?I(g,q[u],-1):I(p[u],i,1)};I=function(g,i,n){if(g===i)return n;for(g=g.nextSibling;g;){if(g===i)return-1;g=g.nextSibling}return 1}}k.getText=function(g){for(var i="",n,m=0;g[m];m++){n=g[m];if(n.nodeType===3||n.nodeType===4)i+=n.nodeValue;else if(n.nodeType!==8)i+=k.getText(n.childNodes)}return i};(function(){var g=t.createElement("div"),
+i="script"+(new Date).getTime(),n=t.documentElement;g.innerHTML="<a name='"+i+"'/>";n.insertBefore(g,n.firstChild);if(t.getElementById(i)){o.find.ID=function(m,p,q){if(typeof p.getElementById!=="undefined"&&!q)return(p=p.getElementById(m[1]))?p.id===m[1]||typeof p.getAttributeNode!=="undefined"&&p.getAttributeNode("id").nodeValue===m[1]?[p]:B:[]};o.filter.ID=function(m,p){var q=typeof m.getAttributeNode!=="undefined"&&m.getAttributeNode("id");return m.nodeType===1&&q&&q.nodeValue===p}}n.removeChild(g);
+n=g=null})();(function(){var g=t.createElement("div");g.appendChild(t.createComment(""));if(g.getElementsByTagName("*").length>0)o.find.TAG=function(i,n){var m=n.getElementsByTagName(i[1]);if(i[1]==="*"){for(var p=[],q=0;m[q];q++)m[q].nodeType===1&&p.push(m[q]);m=p}return m};g.innerHTML="<a href='#'></a>";if(g.firstChild&&typeof g.firstChild.getAttribute!=="undefined"&&g.firstChild.getAttribute("href")!=="#")o.attrHandle.href=function(i){return i.getAttribute("href",2)};g=null})();t.querySelectorAll&&
+function(){var g=k,i=t.createElement("div");i.innerHTML="<p class='TEST'></p>";if(!(i.querySelectorAll&&i.querySelectorAll(".TEST").length===0)){k=function(m,p,q,u){p=p||t;m=m.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!u&&!k.isXML(p))if(p.nodeType===9)try{return C(p.querySelectorAll(m),q)}catch(y){}else if(p.nodeType===1&&p.nodeName.toLowerCase()!=="object"){var F=p.getAttribute("id"),M=F||"__sizzle__";F||p.setAttribute("id",M);try{return C(p.querySelectorAll("#"+M+" "+m),q)}catch(N){}finally{F||
+p.removeAttribute("id")}}return g(m,p,q,u)};for(var n in g)k[n]=g[n];i=null}}();(function(){var g=t.documentElement,i=g.matchesSelector||g.mozMatchesSelector||g.webkitMatchesSelector||g.msMatchesSelector,n=false;try{i.call(t.documentElement,"[test!='']:sizzle")}catch(m){n=true}if(i)k.matchesSelector=function(p,q){q=q.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!k.isXML(p))try{if(n||!o.match.PSEUDO.test(q)&&!/!=/.test(q))return i.call(p,q)}catch(u){}return k(q,null,null,[p]).length>0}})();(function(){var g=
+t.createElement("div");g.innerHTML="<div class='test e'></div><div class='test'></div>";if(!(!g.getElementsByClassName||g.getElementsByClassName("e").length===0)){g.lastChild.className="e";if(g.getElementsByClassName("e").length!==1){o.order.splice(1,0,"CLASS");o.find.CLASS=function(i,n,m){if(typeof n.getElementsByClassName!=="undefined"&&!m)return n.getElementsByClassName(i[1])};g=null}}})();k.contains=t.documentElement.contains?function(g,i){return g!==i&&(g.contains?g.contains(i):true)}:t.documentElement.compareDocumentPosition?
+function(g,i){return!!(g.compareDocumentPosition(i)&16)}:function(){return false};k.isXML=function(g){return(g=(g?g.ownerDocument||g:0).documentElement)?g.nodeName!=="HTML":false};var L=function(g,i){for(var n,m=[],p="",q=i.nodeType?[i]:i;n=o.match.PSEUDO.exec(g);){p+=n[0];g=g.replace(o.match.PSEUDO,"")}g=o.relative[g]?g+"*":g;n=0;for(var u=q.length;n<u;n++)k(g,q[n],m);return k.filter(p,m)};c.find=k;c.expr=k.selectors;c.expr[":"]=c.expr.filters;c.unique=k.uniqueSort;c.text=k.getText;c.isXMLDoc=k.isXML;
+c.contains=k.contains})();var Za=/Until$/,$a=/^(?:parents|prevUntil|prevAll)/,ab=/,/,Na=/^.[^:#\[\.,]*$/,bb=Array.prototype.slice,cb=c.expr.match.POS;c.fn.extend({find:function(a){for(var b=this.pushStack("","find",a),d=0,e=0,f=this.length;e<f;e++){d=b.length;c.find(a,this[e],b);if(e>0)for(var h=d;h<b.length;h++)for(var l=0;l<d;l++)if(b[l]===b[h]){b.splice(h--,1);break}}return b},has:function(a){var b=c(a);return this.filter(function(){for(var d=0,e=b.length;d<e;d++)if(c.contains(this,b[d]))return true})},
+not:function(a){return this.pushStack(ma(this,a,false),"not",a)},filter:function(a){return this.pushStack(ma(this,a,true),"filter",a)},is:function(a){return!!a&&c.filter(a,this).length>0},closest:function(a,b){var d=[],e,f,h=this[0];if(c.isArray(a)){var l,k={},o=1;if(h&&a.length){e=0;for(f=a.length;e<f;e++){l=a[e];k[l]||(k[l]=c.expr.match.POS.test(l)?c(l,b||this.context):l)}for(;h&&h.ownerDocument&&h!==b;){for(l in k){e=k[l];if(e.jquery?e.index(h)>-1:c(h).is(e))d.push({selector:l,elem:h,level:o})}h=
+h.parentNode;o++}}return d}l=cb.test(a)?c(a,b||this.context):null;e=0;for(f=this.length;e<f;e++)for(h=this[e];h;)if(l?l.index(h)>-1:c.find.matchesSelector(h,a)){d.push(h);break}else{h=h.parentNode;if(!h||!h.ownerDocument||h===b)break}d=d.length>1?c.unique(d):d;return this.pushStack(d,"closest",a)},index:function(a){if(!a||typeof a==="string")return c.inArray(this[0],a?c(a):this.parent().children());return c.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var d=typeof a==="string"?c(a,b||this.context):
+c.makeArray(a),e=c.merge(this.get(),d);return this.pushStack(!d[0]||!d[0].parentNode||d[0].parentNode.nodeType===11||!e[0]||!e[0].parentNode||e[0].parentNode.nodeType===11?e:c.unique(e))},andSelf:function(){return this.add(this.prevObject)}});c.each({parent:function(a){return(a=a.parentNode)&&a.nodeType!==11?a:null},parents:function(a){return c.dir(a,"parentNode")},parentsUntil:function(a,b,d){return c.dir(a,"parentNode",d)},next:function(a){return c.nth(a,2,"nextSibling")},prev:function(a){return c.nth(a,
+2,"previousSibling")},nextAll:function(a){return c.dir(a,"nextSibling")},prevAll:function(a){return c.dir(a,"previousSibling")},nextUntil:function(a,b,d){return c.dir(a,"nextSibling",d)},prevUntil:function(a,b,d){return c.dir(a,"previousSibling",d)},siblings:function(a){return c.sibling(a.parentNode.firstChild,a)},children:function(a){return c.sibling(a.firstChild)},contents:function(a){return c.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:c.makeArray(a.childNodes)}},function(a,
+b){c.fn[a]=function(d,e){var f=c.map(this,b,d);Za.test(a)||(e=d);if(e&&typeof e==="string")f=c.filter(e,f);f=this.length>1?c.unique(f):f;if((this.length>1||ab.test(e))&&$a.test(a))f=f.reverse();return this.pushStack(f,a,bb.call(arguments).join(","))}});c.extend({filter:function(a,b,d){if(d)a=":not("+a+")";return b.length===1?c.find.matchesSelector(b[0],a)?[b[0]]:[]:c.find.matches(a,b)},dir:function(a,b,d){var e=[];for(a=a[b];a&&a.nodeType!==9&&(d===B||a.nodeType!==1||!c(a).is(d));){a.nodeType===1&&
+e.push(a);a=a[b]}return e},nth:function(a,b,d){b=b||1;for(var e=0;a;a=a[d])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){for(var d=[];a;a=a.nextSibling)a.nodeType===1&&a!==b&&d.push(a);return d}});var za=/ jQuery\d+="(?:\d+|null)"/g,$=/^\s+/,Aa=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,Ba=/<([\w:]+)/,db=/<tbody/i,eb=/<|&#?\w+;/,Ca=/<(?:script|object|embed|option|style)/i,Da=/checked\s*(?:[^=]|=\s*.checked.)/i,fb=/\=([^="'>\s]+\/)>/g,P={option:[1,
+"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],area:[1,"<map>","</map>"],_default:[0,"",""]};P.optgroup=P.option;P.tbody=P.tfoot=P.colgroup=P.caption=P.thead;P.th=P.td;if(!c.support.htmlSerialize)P._default=[1,"div<div>","</div>"];c.fn.extend({text:function(a){if(c.isFunction(a))return this.each(function(b){var d=
+c(this);d.text(a.call(this,b,d.text()))});if(typeof a!=="object"&&a!==B)return this.empty().append((this[0]&&this[0].ownerDocument||t).createTextNode(a));return c.text(this)},wrapAll:function(a){if(c.isFunction(a))return this.each(function(d){c(this).wrapAll(a.call(this,d))});if(this[0]){var b=c(a,this[0].ownerDocument).eq(0).clone(true);this[0].parentNode&&b.insertBefore(this[0]);b.map(function(){for(var d=this;d.firstChild&&d.firstChild.nodeType===1;)d=d.firstChild;return d}).append(this)}return this},
+wrapInner:function(a){if(c.isFunction(a))return this.each(function(b){c(this).wrapInner(a.call(this,b))});return this.each(function(){var b=c(this),d=b.contents();d.length?d.wrapAll(a):b.append(a)})},wrap:function(a){return this.each(function(){c(this).wrapAll(a)})},unwrap:function(){return this.parent().each(function(){c.nodeName(this,"body")||c(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.appendChild(a)})},
+prepend:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b,this)});else if(arguments.length){var a=c(arguments[0]);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b,
+this.nextSibling)});else if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,c(arguments[0]).toArray());return a}},remove:function(a,b){for(var d=0,e;(e=this[d])!=null;d++)if(!a||c.filter(a,[e]).length){if(!b&&e.nodeType===1){c.cleanData(e.getElementsByTagName("*"));c.cleanData([e])}e.parentNode&&e.parentNode.removeChild(e)}return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++)for(b.nodeType===1&&c.cleanData(b.getElementsByTagName("*"));b.firstChild;)b.removeChild(b.firstChild);
+return this},clone:function(a){var b=this.map(function(){if(!c.support.noCloneEvent&&!c.isXMLDoc(this)){var d=this.outerHTML,e=this.ownerDocument;if(!d){d=e.createElement("div");d.appendChild(this.cloneNode(true));d=d.innerHTML}return c.clean([d.replace(za,"").replace(fb,'="$1">').replace($,"")],e)[0]}else return this.cloneNode(true)});if(a===true){na(this,b);na(this.find("*"),b.find("*"))}return b},html:function(a){if(a===B)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(za,""):null;
+else if(typeof a==="string"&&!Ca.test(a)&&(c.support.leadingWhitespace||!$.test(a))&&!P[(Ba.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(Aa,"<$1></$2>");try{for(var b=0,d=this.length;b<d;b++)if(this[b].nodeType===1){c.cleanData(this[b].getElementsByTagName("*"));this[b].innerHTML=a}}catch(e){this.empty().append(a)}}else c.isFunction(a)?this.each(function(f){var h=c(this);h.html(a.call(this,f,h.html()))}):this.empty().append(a);return this},replaceWith:function(a){if(this[0]&&this[0].parentNode){if(c.isFunction(a))return this.each(function(b){var d=
+c(this),e=d.html();d.replaceWith(a.call(this,b,e))});if(typeof a!=="string")a=c(a).detach();return this.each(function(){var b=this.nextSibling,d=this.parentNode;c(this).remove();b?c(b).before(a):c(d).append(a)})}else return this.pushStack(c(c.isFunction(a)?a():a),"replaceWith",a)},detach:function(a){return this.remove(a,true)},domManip:function(a,b,d){var e,f,h,l=a[0],k=[];if(!c.support.checkClone&&arguments.length===3&&typeof l==="string"&&Da.test(l))return this.each(function(){c(this).domManip(a,
+b,d,true)});if(c.isFunction(l))return this.each(function(x){var r=c(this);a[0]=l.call(this,x,b?r.html():B);r.domManip(a,b,d)});if(this[0]){e=l&&l.parentNode;e=c.support.parentNode&&e&&e.nodeType===11&&e.childNodes.length===this.length?{fragment:e}:c.buildFragment(a,this,k);h=e.fragment;if(f=h.childNodes.length===1?h=h.firstChild:h.firstChild){b=b&&c.nodeName(f,"tr");f=0;for(var o=this.length;f<o;f++)d.call(b?c.nodeName(this[f],"table")?this[f].getElementsByTagName("tbody")[0]||this[f].appendChild(this[f].ownerDocument.createElement("tbody")):
+this[f]:this[f],f>0||e.cacheable||this.length>1?h.cloneNode(true):h)}k.length&&c.each(k,Oa)}return this}});c.buildFragment=function(a,b,d){var e,f,h;b=b&&b[0]?b[0].ownerDocument||b[0]:t;if(a.length===1&&typeof a[0]==="string"&&a[0].length<512&&b===t&&!Ca.test(a[0])&&(c.support.checkClone||!Da.test(a[0]))){f=true;if(h=c.fragments[a[0]])if(h!==1)e=h}if(!e){e=b.createDocumentFragment();c.clean(a,b,e,d)}if(f)c.fragments[a[0]]=h?e:1;return{fragment:e,cacheable:f}};c.fragments={};c.each({appendTo:"append",
+prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){c.fn[a]=function(d){var e=[];d=c(d);var f=this.length===1&&this[0].parentNode;if(f&&f.nodeType===11&&f.childNodes.length===1&&d.length===1){d[b](this[0]);return this}else{f=0;for(var h=d.length;f<h;f++){var l=(f>0?this.clone(true):this).get();c(d[f])[b](l);e=e.concat(l)}return this.pushStack(e,a,d.selector)}}});c.extend({clean:function(a,b,d,e){b=b||t;if(typeof b.createElement==="undefined")b=b.ownerDocument||
+b[0]&&b[0].ownerDocument||t;for(var f=[],h=0,l;(l=a[h])!=null;h++){if(typeof l==="number")l+="";if(l){if(typeof l==="string"&&!eb.test(l))l=b.createTextNode(l);else if(typeof l==="string"){l=l.replace(Aa,"<$1></$2>");var k=(Ba.exec(l)||["",""])[1].toLowerCase(),o=P[k]||P._default,x=o[0],r=b.createElement("div");for(r.innerHTML=o[1]+l+o[2];x--;)r=r.lastChild;if(!c.support.tbody){x=db.test(l);k=k==="table"&&!x?r.firstChild&&r.firstChild.childNodes:o[1]==="<table>"&&!x?r.childNodes:[];for(o=k.length-
+1;o>=0;--o)c.nodeName(k[o],"tbody")&&!k[o].childNodes.length&&k[o].parentNode.removeChild(k[o])}!c.support.leadingWhitespace&&$.test(l)&&r.insertBefore(b.createTextNode($.exec(l)[0]),r.firstChild);l=r.childNodes}if(l.nodeType)f.push(l);else f=c.merge(f,l)}}if(d)for(h=0;f[h];h++)if(e&&c.nodeName(f[h],"script")&&(!f[h].type||f[h].type.toLowerCase()==="text/javascript"))e.push(f[h].parentNode?f[h].parentNode.removeChild(f[h]):f[h]);else{f[h].nodeType===1&&f.splice.apply(f,[h+1,0].concat(c.makeArray(f[h].getElementsByTagName("script"))));
+d.appendChild(f[h])}return f},cleanData:function(a){for(var b,d,e=c.cache,f=c.event.special,h=c.support.deleteExpando,l=0,k;(k=a[l])!=null;l++)if(!(k.nodeName&&c.noData[k.nodeName.toLowerCase()]))if(d=k[c.expando]){if((b=e[d])&&b.events)for(var o in b.events)f[o]?c.event.remove(k,o):c.removeEvent(k,o,b.handle);if(h)delete k[c.expando];else k.removeAttribute&&k.removeAttribute(c.expando);delete e[d]}}});var Ea=/alpha\([^)]*\)/i,gb=/opacity=([^)]*)/,hb=/-([a-z])/ig,ib=/([A-Z])/g,Fa=/^-?\d+(?:px)?$/i,
+jb=/^-?\d/,kb={position:"absolute",visibility:"hidden",display:"block"},Pa=["Left","Right"],Qa=["Top","Bottom"],W,Ga,aa,lb=function(a,b){return b.toUpperCase()};c.fn.css=function(a,b){if(arguments.length===2&&b===B)return this;return c.access(this,a,b,true,function(d,e,f){return f!==B?c.style(d,e,f):c.css(d,e)})};c.extend({cssHooks:{opacity:{get:function(a,b){if(b){var d=W(a,"opacity","opacity");return d===""?"1":d}else return a.style.opacity}}},cssNumber:{zIndex:true,fontWeight:true,opacity:true,
+zoom:true,lineHeight:true},cssProps:{"float":c.support.cssFloat?"cssFloat":"styleFloat"},style:function(a,b,d,e){if(!(!a||a.nodeType===3||a.nodeType===8||!a.style)){var f,h=c.camelCase(b),l=a.style,k=c.cssHooks[h];b=c.cssProps[h]||h;if(d!==B){if(!(typeof d==="number"&&isNaN(d)||d==null)){if(typeof d==="number"&&!c.cssNumber[h])d+="px";if(!k||!("set"in k)||(d=k.set(a,d))!==B)try{l[b]=d}catch(o){}}}else{if(k&&"get"in k&&(f=k.get(a,false,e))!==B)return f;return l[b]}}},css:function(a,b,d){var e,f=c.camelCase(b),
+h=c.cssHooks[f];b=c.cssProps[f]||f;if(h&&"get"in h&&(e=h.get(a,true,d))!==B)return e;else if(W)return W(a,b,f)},swap:function(a,b,d){var e={},f;for(f in b){e[f]=a.style[f];a.style[f]=b[f]}d.call(a);for(f in b)a.style[f]=e[f]},camelCase:function(a){return a.replace(hb,lb)}});c.curCSS=c.css;c.each(["height","width"],function(a,b){c.cssHooks[b]={get:function(d,e,f){var h;if(e){if(d.offsetWidth!==0)h=oa(d,b,f);else c.swap(d,kb,function(){h=oa(d,b,f)});if(h<=0){h=W(d,b,b);if(h==="0px"&&aa)h=aa(d,b,b);
+if(h!=null)return h===""||h==="auto"?"0px":h}if(h<0||h==null){h=d.style[b];return h===""||h==="auto"?"0px":h}return typeof h==="string"?h:h+"px"}},set:function(d,e){if(Fa.test(e)){e=parseFloat(e);if(e>=0)return e+"px"}else return e}}});if(!c.support.opacity)c.cssHooks.opacity={get:function(a,b){return gb.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"":b?"1":""},set:function(a,b){var d=a.style;d.zoom=1;var e=c.isNaN(b)?"":"alpha(opacity="+b*100+")",f=
+d.filter||"";d.filter=Ea.test(f)?f.replace(Ea,e):d.filter+" "+e}};if(t.defaultView&&t.defaultView.getComputedStyle)Ga=function(a,b,d){var e;d=d.replace(ib,"-$1").toLowerCase();if(!(b=a.ownerDocument.defaultView))return B;if(b=b.getComputedStyle(a,null)){e=b.getPropertyValue(d);if(e===""&&!c.contains(a.ownerDocument.documentElement,a))e=c.style(a,d)}return e};if(t.documentElement.currentStyle)aa=function(a,b){var d,e,f=a.currentStyle&&a.currentStyle[b],h=a.style;if(!Fa.test(f)&&jb.test(f)){d=h.left;
+e=a.runtimeStyle.left;a.runtimeStyle.left=a.currentStyle.left;h.left=b==="fontSize"?"1em":f||0;f=h.pixelLeft+"px";h.left=d;a.runtimeStyle.left=e}return f===""?"auto":f};W=Ga||aa;if(c.expr&&c.expr.filters){c.expr.filters.hidden=function(a){var b=a.offsetHeight;return a.offsetWidth===0&&b===0||!c.support.reliableHiddenOffsets&&(a.style.display||c.css(a,"display"))==="none"};c.expr.filters.visible=function(a){return!c.expr.filters.hidden(a)}}var mb=c.now(),nb=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
+ob=/^(?:select|textarea)/i,pb=/^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,qb=/^(?:GET|HEAD)$/,Ra=/\[\]$/,T=/\=\?(&|$)/,ja=/\?/,rb=/([?&])_=[^&]*/,sb=/^(\w+:)?\/\/([^\/?#]+)/,tb=/%20/g,ub=/#.*$/,Ha=c.fn.load;c.fn.extend({load:function(a,b,d){if(typeof a!=="string"&&Ha)return Ha.apply(this,arguments);else if(!this.length)return this;var e=a.indexOf(" ");if(e>=0){var f=a.slice(e,a.length);a=a.slice(0,e)}e="GET";if(b)if(c.isFunction(b)){d=b;b=null}else if(typeof b===
+"object"){b=c.param(b,c.ajaxSettings.traditional);e="POST"}var h=this;c.ajax({url:a,type:e,dataType:"html",data:b,complete:function(l,k){if(k==="success"||k==="notmodified")h.html(f?c("<div>").append(l.responseText.replace(nb,"")).find(f):l.responseText);d&&h.each(d,[l.responseText,k,l])}});return this},serialize:function(){return c.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?c.makeArray(this.elements):this}).filter(function(){return this.name&&
+!this.disabled&&(this.checked||ob.test(this.nodeName)||pb.test(this.type))}).map(function(a,b){var d=c(this).val();return d==null?null:c.isArray(d)?c.map(d,function(e){return{name:b.name,value:e}}):{name:b.name,value:d}}).get()}});c.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){c.fn[b]=function(d){return this.bind(b,d)}});c.extend({get:function(a,b,d,e){if(c.isFunction(b)){e=e||d;d=b;b=null}return c.ajax({type:"GET",url:a,data:b,success:d,dataType:e})},
+getScript:function(a,b){return c.get(a,null,b,"script")},getJSON:function(a,b,d){return c.get(a,b,d,"json")},post:function(a,b,d,e){if(c.isFunction(b)){e=e||d;d=b;b={}}return c.ajax({type:"POST",url:a,data:b,success:d,dataType:e})},ajaxSetup:function(a){c.extend(c.ajaxSettings,a)},ajaxSettings:{url:location.href,global:true,type:"GET",contentType:"application/x-www-form-urlencoded",processData:true,async:true,xhr:function(){return new E.XMLHttpRequest},accepts:{xml:"application/xml, text/xml",html:"text/html",
+script:"text/javascript, application/javascript",json:"application/json, text/javascript",text:"text/plain",_default:"*/*"}},ajax:function(a){var b=c.extend(true,{},c.ajaxSettings,a),d,e,f,h=b.type.toUpperCase(),l=qb.test(h);b.url=b.url.replace(ub,"");b.context=a&&a.context!=null?a.context:b;if(b.data&&b.processData&&typeof b.data!=="string")b.data=c.param(b.data,b.traditional);if(b.dataType==="jsonp"){if(h==="GET")T.test(b.url)||(b.url+=(ja.test(b.url)?"&":"?")+(b.jsonp||"callback")+"=?");else if(!b.data||
+!T.test(b.data))b.data=(b.data?b.data+"&":"")+(b.jsonp||"callback")+"=?";b.dataType="json"}if(b.dataType==="json"&&(b.data&&T.test(b.data)||T.test(b.url))){d=b.jsonpCallback||"jsonp"+mb++;if(b.data)b.data=(b.data+"").replace(T,"="+d+"$1");b.url=b.url.replace(T,"="+d+"$1");b.dataType="script";var k=E[d];E[d]=function(m){if(c.isFunction(k))k(m);else{E[d]=B;try{delete E[d]}catch(p){}}f=m;c.handleSuccess(b,w,e,f);c.handleComplete(b,w,e,f);r&&r.removeChild(A)}}if(b.dataType==="script"&&b.cache===null)b.cache=
+false;if(b.cache===false&&l){var o=c.now(),x=b.url.replace(rb,"$1_="+o);b.url=x+(x===b.url?(ja.test(b.url)?"&":"?")+"_="+o:"")}if(b.data&&l)b.url+=(ja.test(b.url)?"&":"?")+b.data;b.global&&c.active++===0&&c.event.trigger("ajaxStart");o=(o=sb.exec(b.url))&&(o[1]&&o[1].toLowerCase()!==location.protocol||o[2].toLowerCase()!==location.host);if(b.dataType==="script"&&h==="GET"&&o){var r=t.getElementsByTagName("head")[0]||t.documentElement,A=t.createElement("script");if(b.scriptCharset)A.charset=b.scriptCharset;
+A.src=b.url;if(!d){var C=false;A.onload=A.onreadystatechange=function(){if(!C&&(!this.readyState||this.readyState==="loaded"||this.readyState==="complete")){C=true;c.handleSuccess(b,w,e,f);c.handleComplete(b,w,e,f);A.onload=A.onreadystatechange=null;r&&A.parentNode&&r.removeChild(A)}}}r.insertBefore(A,r.firstChild);return B}var J=false,w=b.xhr();if(w){b.username?w.open(h,b.url,b.async,b.username,b.password):w.open(h,b.url,b.async);try{if(b.data!=null&&!l||a&&a.contentType)w.setRequestHeader("Content-Type",
+b.contentType);if(b.ifModified){c.lastModified[b.url]&&w.setRequestHeader("If-Modified-Since",c.lastModified[b.url]);c.etag[b.url]&&w.setRequestHeader("If-None-Match",c.etag[b.url])}o||w.setRequestHeader("X-Requested-With","XMLHttpRequest");w.setRequestHeader("Accept",b.dataType&&b.accepts[b.dataType]?b.accepts[b.dataType]+", */*; q=0.01":b.accepts._default)}catch(I){}if(b.beforeSend&&b.beforeSend.call(b.context,w,b)===false){b.global&&c.active--===1&&c.event.trigger("ajaxStop");w.abort();return false}b.global&&
+c.triggerGlobal(b,"ajaxSend",[w,b]);var L=w.onreadystatechange=function(m){if(!w||w.readyState===0||m==="abort"){J||c.handleComplete(b,w,e,f);J=true;if(w)w.onreadystatechange=c.noop}else if(!J&&w&&(w.readyState===4||m==="timeout")){J=true;w.onreadystatechange=c.noop;e=m==="timeout"?"timeout":!c.httpSuccess(w)?"error":b.ifModified&&c.httpNotModified(w,b.url)?"notmodified":"success";var p;if(e==="success")try{f=c.httpData(w,b.dataType,b)}catch(q){e="parsererror";p=q}if(e==="success"||e==="notmodified")d||
+c.handleSuccess(b,w,e,f);else c.handleError(b,w,e,p);d||c.handleComplete(b,w,e,f);m==="timeout"&&w.abort();if(b.async)w=null}};try{var g=w.abort;w.abort=function(){w&&Function.prototype.call.call(g,w);L("abort")}}catch(i){}b.async&&b.timeout>0&&setTimeout(function(){w&&!J&&L("timeout")},b.timeout);try{w.send(l||b.data==null?null:b.data)}catch(n){c.handleError(b,w,null,n);c.handleComplete(b,w,e,f)}b.async||L();return w}},param:function(a,b){var d=[],e=function(h,l){l=c.isFunction(l)?l():l;d[d.length]=
+encodeURIComponent(h)+"="+encodeURIComponent(l)};if(b===B)b=c.ajaxSettings.traditional;if(c.isArray(a)||a.jquery)c.each(a,function(){e(this.name,this.value)});else for(var f in a)da(f,a[f],b,e);return d.join("&").replace(tb,"+")}});c.extend({active:0,lastModified:{},etag:{},handleError:function(a,b,d,e){a.error&&a.error.call(a.context,b,d,e);a.global&&c.triggerGlobal(a,"ajaxError",[b,a,e])},handleSuccess:function(a,b,d,e){a.success&&a.success.call(a.context,e,d,b);a.global&&c.triggerGlobal(a,"ajaxSuccess",
+[b,a])},handleComplete:function(a,b,d){a.complete&&a.complete.call(a.context,b,d);a.global&&c.triggerGlobal(a,"ajaxComplete",[b,a]);a.global&&c.active--===1&&c.event.trigger("ajaxStop")},triggerGlobal:function(a,b,d){(a.context&&a.context.url==null?c(a.context):c.event).trigger(b,d)},httpSuccess:function(a){try{return!a.status&&location.protocol==="file:"||a.status>=200&&a.status<300||a.status===304||a.status===1223}catch(b){}return false},httpNotModified:function(a,b){var d=a.getResponseHeader("Last-Modified"),
+e=a.getResponseHeader("Etag");if(d)c.lastModified[b]=d;if(e)c.etag[b]=e;return a.status===304},httpData:function(a,b,d){var e=a.getResponseHeader("content-type")||"",f=b==="xml"||!b&&e.indexOf("xml")>=0;a=f?a.responseXML:a.responseText;f&&a.documentElement.nodeName==="parsererror"&&c.error("parsererror");if(d&&d.dataFilter)a=d.dataFilter(a,b);if(typeof a==="string")if(b==="json"||!b&&e.indexOf("json")>=0)a=c.parseJSON(a);else if(b==="script"||!b&&e.indexOf("javascript")>=0)c.globalEval(a);return a}});
+if(E.ActiveXObject)c.ajaxSettings.xhr=function(){if(E.location.protocol!=="file:")try{return new E.XMLHttpRequest}catch(a){}try{return new E.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}};c.support.ajax=!!c.ajaxSettings.xhr();var ea={},vb=/^(?:toggle|show|hide)$/,wb=/^([+\-]=)?([\d+.\-]+)(.*)$/,ba,pa=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]];c.fn.extend({show:function(a,b,d){if(a||a===0)return this.animate(S("show",
+3),a,b,d);else{d=0;for(var e=this.length;d<e;d++){a=this[d];b=a.style.display;if(!c.data(a,"olddisplay")&&b==="none")b=a.style.display="";b===""&&c.css(a,"display")==="none"&&c.data(a,"olddisplay",qa(a.nodeName))}for(d=0;d<e;d++){a=this[d];b=a.style.display;if(b===""||b==="none")a.style.display=c.data(a,"olddisplay")||""}return this}},hide:function(a,b,d){if(a||a===0)return this.animate(S("hide",3),a,b,d);else{a=0;for(b=this.length;a<b;a++){d=c.css(this[a],"display");d!=="none"&&c.data(this[a],"olddisplay",
+d)}for(a=0;a<b;a++)this[a].style.display="none";return this}},_toggle:c.fn.toggle,toggle:function(a,b,d){var e=typeof a==="boolean";if(c.isFunction(a)&&c.isFunction(b))this._toggle.apply(this,arguments);else a==null||e?this.each(function(){var f=e?a:c(this).is(":hidden");c(this)[f?"show":"hide"]()}):this.animate(S("toggle",3),a,b,d);return this},fadeTo:function(a,b,d,e){return this.filter(":hidden").css("opacity",0).show().end().animate({opacity:b},a,d,e)},animate:function(a,b,d,e){var f=c.speed(b,
+d,e);if(c.isEmptyObject(a))return this.each(f.complete);return this[f.queue===false?"each":"queue"](function(){var h=c.extend({},f),l,k=this.nodeType===1,o=k&&c(this).is(":hidden"),x=this;for(l in a){var r=c.camelCase(l);if(l!==r){a[r]=a[l];delete a[l];l=r}if(a[l]==="hide"&&o||a[l]==="show"&&!o)return h.complete.call(this);if(k&&(l==="height"||l==="width")){h.overflow=[this.style.overflow,this.style.overflowX,this.style.overflowY];if(c.css(this,"display")==="inline"&&c.css(this,"float")==="none")if(c.support.inlineBlockNeedsLayout)if(qa(this.nodeName)===
+"inline")this.style.display="inline-block";else{this.style.display="inline";this.style.zoom=1}else this.style.display="inline-block"}if(c.isArray(a[l])){(h.specialEasing=h.specialEasing||{})[l]=a[l][1];a[l]=a[l][0]}}if(h.overflow!=null)this.style.overflow="hidden";h.curAnim=c.extend({},a);c.each(a,function(A,C){var J=new c.fx(x,h,A);if(vb.test(C))J[C==="toggle"?o?"show":"hide":C](a);else{var w=wb.exec(C),I=J.cur()||0;if(w){var L=parseFloat(w[2]),g=w[3]||"px";if(g!=="px"){c.style(x,A,(L||1)+g);I=(L||
+1)/J.cur()*I;c.style(x,A,I+g)}if(w[1])L=(w[1]==="-="?-1:1)*L+I;J.custom(I,L,g)}else J.custom(I,C,"")}});return true})},stop:function(a,b){var d=c.timers;a&&this.queue([]);this.each(function(){for(var e=d.length-1;e>=0;e--)if(d[e].elem===this){b&&d[e](true);d.splice(e,1)}});b||this.dequeue();return this}});c.each({slideDown:S("show",1),slideUp:S("hide",1),slideToggle:S("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){c.fn[a]=function(d,e,f){return this.animate(b,
+d,e,f)}});c.extend({speed:function(a,b,d){var e=a&&typeof a==="object"?c.extend({},a):{complete:d||!d&&b||c.isFunction(a)&&a,duration:a,easing:d&&b||b&&!c.isFunction(b)&&b};e.duration=c.fx.off?0:typeof e.duration==="number"?e.duration:e.duration in c.fx.speeds?c.fx.speeds[e.duration]:c.fx.speeds._default;e.old=e.complete;e.complete=function(){e.queue!==false&&c(this).dequeue();c.isFunction(e.old)&&e.old.call(this)};return e},easing:{linear:function(a,b,d,e){return d+e*a},swing:function(a,b,d,e){return(-Math.cos(a*
+Math.PI)/2+0.5)*e+d}},timers:[],fx:function(a,b,d){this.options=b;this.elem=a;this.prop=d;if(!b.orig)b.orig={}}});c.fx.prototype={update:function(){this.options.step&&this.options.step.call(this.elem,this.now,this);(c.fx.step[this.prop]||c.fx.step._default)(this)},cur:function(){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null))return this.elem[this.prop];var a=parseFloat(c.css(this.elem,this.prop));return a&&a>-1E4?a:0},custom:function(a,b,d){function e(l){return f.step(l)}
+var f=this,h=c.fx;this.startTime=c.now();this.start=a;this.end=b;this.unit=d||this.unit||"px";this.now=this.start;this.pos=this.state=0;e.elem=this.elem;if(e()&&c.timers.push(e)&&!ba)ba=setInterval(h.tick,h.interval)},show:function(){this.options.orig[this.prop]=c.style(this.elem,this.prop);this.options.show=true;this.custom(this.prop==="width"||this.prop==="height"?1:0,this.cur());c(this.elem).show()},hide:function(){this.options.orig[this.prop]=c.style(this.elem,this.prop);this.options.hide=true;
+this.custom(this.cur(),0)},step:function(a){var b=c.now(),d=true;if(a||b>=this.options.duration+this.startTime){this.now=this.end;this.pos=this.state=1;this.update();this.options.curAnim[this.prop]=true;for(var e in this.options.curAnim)if(this.options.curAnim[e]!==true)d=false;if(d){if(this.options.overflow!=null&&!c.support.shrinkWrapBlocks){var f=this.elem,h=this.options;c.each(["","X","Y"],function(k,o){f.style["overflow"+o]=h.overflow[k]})}this.options.hide&&c(this.elem).hide();if(this.options.hide||
+this.options.show)for(var l in this.options.curAnim)c.style(this.elem,l,this.options.orig[l]);this.options.complete.call(this.elem)}return false}else{a=b-this.startTime;this.state=a/this.options.duration;b=this.options.easing||(c.easing.swing?"swing":"linear");this.pos=c.easing[this.options.specialEasing&&this.options.specialEasing[this.prop]||b](this.state,a,0,1,this.options.duration);this.now=this.start+(this.end-this.start)*this.pos;this.update()}return true}};c.extend(c.fx,{tick:function(){for(var a=
+c.timers,b=0;b<a.length;b++)a[b]()||a.splice(b--,1);a.length||c.fx.stop()},interval:13,stop:function(){clearInterval(ba);ba=null},speeds:{slow:600,fast:200,_default:400},step:{opacity:function(a){c.style(a.elem,"opacity",a.now)},_default:function(a){if(a.elem.style&&a.elem.style[a.prop]!=null)a.elem.style[a.prop]=(a.prop==="width"||a.prop==="height"?Math.max(0,a.now):a.now)+a.unit;else a.elem[a.prop]=a.now}}});if(c.expr&&c.expr.filters)c.expr.filters.animated=function(a){return c.grep(c.timers,function(b){return a===
+b.elem}).length};var xb=/^t(?:able|d|h)$/i,Ia=/^(?:body|html)$/i;c.fn.offset="getBoundingClientRect"in t.documentElement?function(a){var b=this[0],d;if(a)return this.each(function(l){c.offset.setOffset(this,a,l)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return c.offset.bodyOffset(b);try{d=b.getBoundingClientRect()}catch(e){}var f=b.ownerDocument,h=f.documentElement;if(!d||!c.contains(h,b))return d||{top:0,left:0};b=f.body;f=fa(f);return{top:d.top+(f.pageYOffset||c.support.boxModel&&
+h.scrollTop||b.scrollTop)-(h.clientTop||b.clientTop||0),left:d.left+(f.pageXOffset||c.support.boxModel&&h.scrollLeft||b.scrollLeft)-(h.clientLeft||b.clientLeft||0)}}:function(a){var b=this[0];if(a)return this.each(function(x){c.offset.setOffset(this,a,x)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return c.offset.bodyOffset(b);c.offset.initialize();var d,e=b.offsetParent,f=b.ownerDocument,h=f.documentElement,l=f.body;d=(f=f.defaultView)?f.getComputedStyle(b,null):b.currentStyle;
+for(var k=b.offsetTop,o=b.offsetLeft;(b=b.parentNode)&&b!==l&&b!==h;){if(c.offset.supportsFixedPosition&&d.position==="fixed")break;d=f?f.getComputedStyle(b,null):b.currentStyle;k-=b.scrollTop;o-=b.scrollLeft;if(b===e){k+=b.offsetTop;o+=b.offsetLeft;if(c.offset.doesNotAddBorder&&!(c.offset.doesAddBorderForTableAndCells&&xb.test(b.nodeName))){k+=parseFloat(d.borderTopWidth)||0;o+=parseFloat(d.borderLeftWidth)||0}e=b.offsetParent}if(c.offset.subtractsBorderForOverflowNotVisible&&d.overflow!=="visible"){k+=
+parseFloat(d.borderTopWidth)||0;o+=parseFloat(d.borderLeftWidth)||0}d=d}if(d.position==="relative"||d.position==="static"){k+=l.offsetTop;o+=l.offsetLeft}if(c.offset.supportsFixedPosition&&d.position==="fixed"){k+=Math.max(h.scrollTop,l.scrollTop);o+=Math.max(h.scrollLeft,l.scrollLeft)}return{top:k,left:o}};c.offset={initialize:function(){var a=t.body,b=t.createElement("div"),d,e,f,h=parseFloat(c.css(a,"marginTop"))||0;c.extend(b.style,{position:"absolute",top:0,left:0,margin:0,border:0,width:"1px",
+height:"1px",visibility:"hidden"});b.innerHTML="<div style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;'><div></div></div><table style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;' cellpadding='0' cellspacing='0'><tr><td></td></tr></table>";a.insertBefore(b,a.firstChild);d=b.firstChild;e=d.firstChild;f=d.nextSibling.firstChild.firstChild;this.doesNotAddBorder=e.offsetTop!==5;this.doesAddBorderForTableAndCells=
+f.offsetTop===5;e.style.position="fixed";e.style.top="20px";this.supportsFixedPosition=e.offsetTop===20||e.offsetTop===15;e.style.position=e.style.top="";d.style.overflow="hidden";d.style.position="relative";this.subtractsBorderForOverflowNotVisible=e.offsetTop===-5;this.doesNotIncludeMarginInBodyOffset=a.offsetTop!==h;a.removeChild(b);c.offset.initialize=c.noop},bodyOffset:function(a){var b=a.offsetTop,d=a.offsetLeft;c.offset.initialize();if(c.offset.doesNotIncludeMarginInBodyOffset){b+=parseFloat(c.css(a,
+"marginTop"))||0;d+=parseFloat(c.css(a,"marginLeft"))||0}return{top:b,left:d}},setOffset:function(a,b,d){var e=c.css(a,"position");if(e==="static")a.style.position="relative";var f=c(a),h=f.offset(),l=c.css(a,"top"),k=c.css(a,"left"),o=e==="absolute"&&c.inArray("auto",[l,k])>-1;e={};var x={};if(o)x=f.position();l=o?x.top:parseInt(l,10)||0;k=o?x.left:parseInt(k,10)||0;if(c.isFunction(b))b=b.call(a,d,h);if(b.top!=null)e.top=b.top-h.top+l;if(b.left!=null)e.left=b.left-h.left+k;"using"in b?b.using.call(a,
+e):f.css(e)}};c.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),d=this.offset(),e=Ia.test(b[0].nodeName)?{top:0,left:0}:b.offset();d.top-=parseFloat(c.css(a,"marginTop"))||0;d.left-=parseFloat(c.css(a,"marginLeft"))||0;e.top+=parseFloat(c.css(b[0],"borderTopWidth"))||0;e.left+=parseFloat(c.css(b[0],"borderLeftWidth"))||0;return{top:d.top-e.top,left:d.left-e.left}},offsetParent:function(){return this.map(function(){for(var a=this.offsetParent||t.body;a&&!Ia.test(a.nodeName)&&
+c.css(a,"position")==="static";)a=a.offsetParent;return a})}});c.each(["Left","Top"],function(a,b){var d="scroll"+b;c.fn[d]=function(e){var f=this[0],h;if(!f)return null;if(e!==B)return this.each(function(){if(h=fa(this))h.scrollTo(!a?e:c(h).scrollLeft(),a?e:c(h).scrollTop());else this[d]=e});else return(h=fa(f))?"pageXOffset"in h?h[a?"pageYOffset":"pageXOffset"]:c.support.boxModel&&h.document.documentElement[d]||h.document.body[d]:f[d]}});c.each(["Height","Width"],function(a,b){var d=b.toLowerCase();
+c.fn["inner"+b]=function(){return this[0]?parseFloat(c.css(this[0],d,"padding")):null};c.fn["outer"+b]=function(e){return this[0]?parseFloat(c.css(this[0],d,e?"margin":"border")):null};c.fn[d]=function(e){var f=this[0];if(!f)return e==null?null:this;if(c.isFunction(e))return this.each(function(l){var k=c(this);k[d](e.call(this,l,k[d]()))});if(c.isWindow(f))return f.document.compatMode==="CSS1Compat"&&f.document.documentElement["client"+b]||f.document.body["client"+b];else if(f.nodeType===9)return Math.max(f.documentElement["client"+
+b],f.body["scroll"+b],f.documentElement["scroll"+b],f.body["offset"+b],f.documentElement["offset"+b]);else if(e===B){f=c.css(f,d);var h=parseFloat(f);return c.isNaN(h)?f:h}else return this.css(d,typeof e==="string"?e:e+"px")}})})(window);
diff --git a/tools/addon-sdk-1.7/examples/reddit-panel/data/panel.js b/tools/addon-sdk-1.7/examples/reddit-panel/data/panel.js
new file mode 100644
index 0000000..03f803c
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/reddit-panel/data/panel.js
@@ -0,0 +1,35 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// This is a content script. It executes inside the context of the Reddit page
+// loaded into the panel and has access to that page's window object and other
+// global objects (although the page does not have access to globals defined by
+// this script unless they are explicitly attached to the window object).
+//
+// This content script is injected into the context of the Reddit page
+// by the Panel API, which is accessed by the main add-on script in lib/main.js.
+// See that script for more information about how the panel is created.
+
+$(window).click(function (event) {
+ var t = event.target;
+
+ // Don't intercept the click if it isn't on a link.
+ if (t.nodeName != "A")
+ return;
+
+ // Don't intercept the click if it was on one of the links in the header
+ // or next/previous footer, since those links should load in the panel itself.
+ if ($(t).parents('#header').length || $(t).parents('.nextprev').length)
+ return;
+
+ // Intercept the click, passing it to the addon, which will load it in a tab.
+ event.stopPropagation();
+ event.preventDefault();
+ self.port.emit('click', t.toString());
+});
+
+// Panels have an OS-specific background color by default, and the Mac OS X
+// background color is dark grey, but Reddit expects its background to be white
+// and looks odd when it isn't, so set it to white.
+$("body").css("background", "white");
diff --git a/tools/addon-sdk-1.7/examples/reddit-panel/lib/main.js b/tools/addon-sdk-1.7/examples/reddit-panel/lib/main.js
new file mode 100644
index 0000000..4ea8352
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/reddit-panel/lib/main.js
@@ -0,0 +1,31 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var data = require("self").data;
+
+var reddit_panel = require("panel").Panel({
+ width: 240,
+ height: 320,
+ contentURL: "http://www.reddit.com/.mobile?keep_extension=True",
+ contentScriptFile: [data.url("jquery-1.4.4.min.js"),
+ data.url("panel.js")]
+});
+
+reddit_panel.port.on("click", function(url) {
+ require("tabs").open(url);
+});
+
+require("widget").Widget({
+ id: "open-reddit-btn",
+ label: "Reddit",
+ contentURL: "http://www.reddit.com/static/favicon.ico",
+ panel: reddit_panel
+});
+
+exports.main = function(options, callbacks) {
+ // If you run cfx with --static-args='{"quitWhenDone":true}' this program
+ // will automatically quit Firefox when it's done.
+ if (options.staticArgs.quitWhenDone)
+ callbacks.quit();
+};
diff --git a/tools/addon-sdk-1.7/examples/reddit-panel/package.json b/tools/addon-sdk-1.7/examples/reddit-panel/package.json
new file mode 100644
index 0000000..b183fac
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/reddit-panel/package.json
@@ -0,0 +1,9 @@
+{
+ "license": "MPL 2.0",
+ "name": "reddit-panel",
+ "contributors": [],
+ "author": "Myk Melez",
+ "keywords": [],
+ "description": "Displays Reddit in a panel.",
+ "id": "anonid0-reddit-panel"
+}
diff --git a/tools/addon-sdk-1.7/examples/reddit-panel/tests/test-main.js b/tools/addon-sdk-1.7/examples/reddit-panel/tests/test-main.js
new file mode 100644
index 0000000..f098135
--- /dev/null
+++ b/tools/addon-sdk-1.7/examples/reddit-panel/tests/test-main.js
@@ -0,0 +1,21 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var m = require("main");
+var self = require("self");
+
+exports.testMain = function(test) {
+ var callbacks = { quit: function() {
+ test.pass();
+ test.done();
+ } };
+
+ test.waitUntilDone();
+ // Make sure it doesn't crash...
+ m.main({ staticArgs: {quitWhenDone: true} }, callbacks);
+};
+
+exports.testData = function(test) {
+ test.assert(self.data.load("panel.js").length > 0);
+};
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/README.md b/tools/addon-sdk-1.7/packages/addon-kit/README.md
new file mode 100644
index 0000000..cfbb4df
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/README.md
@@ -0,0 +1,12 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+The addon-kit package provides high-level APIs for add-on developers.
+Most of the needs of most add-on developers should be served by the modules
+found here. Modules in this packages don't require any special privileges to
+run.
+
+The modules in the addon-kit package are relatively stable. We intend to add
+new APIs here and extend existing ones, but will avoid making incompatible
+changes to them unless absolutely necessary.
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/data/index.html b/tools/addon-sdk-1.7/packages/addon-kit/data/index.html
new file mode 100644
index 0000000..7095e7d
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/data/index.html
@@ -0,0 +1,12 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<html>
+ <head>
+ <title>Add-on Page</title>
+ </head>
+ <body>
+ <p>This is an add-on page test!</p>
+ </body>
+</html>
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/data/moz_favicon.ico b/tools/addon-sdk-1.7/packages/addon-kit/data/moz_favicon.ico
new file mode 100644
index 0000000..d444389
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/data/moz_favicon.ico
Binary files differ
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/data/pagemod-css-include-file.css b/tools/addon-sdk-1.7/packages/addon-kit/data/pagemod-css-include-file.css
new file mode 100644
index 0000000..91d8e25
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/data/pagemod-css-include-file.css
@@ -0,0 +1 @@
+div { border: 10px solid black; }
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/data/test-context-menu.js b/tools/addon-sdk-1.7/packages/addon-kit/data/test-context-menu.js
new file mode 100644
index 0000000..13c4eb2
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/data/test-context-menu.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+self.on("context", function () true);
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/data/test-page-mod.html b/tools/addon-sdk-1.7/packages/addon-kit/data/test-page-mod.html
new file mode 100644
index 0000000..da3ec99
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/data/test-page-mod.html
@@ -0,0 +1,12 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<html>
+<head>
+ <title>Page Mod test</title>
+</head>
+<body>
+ <p id="paragraph">Lorem ipsum dolor sit amet.</p>
+</body>
+</html>
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/data/test-page-worker.html b/tools/addon-sdk-1.7/packages/addon-kit/data/test-page-worker.html
new file mode 100644
index 0000000..aabe1df
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/data/test-page-worker.html
@@ -0,0 +1,12 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<html>
+<head>
+ <title>Page Worker test</title>
+</head>
+<body>
+ <p id="paragraph">Lorem ipsum dolor sit amet.</p>
+</body>
+</html>
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/data/test-page-worker.js b/tools/addon-sdk-1.7/packages/addon-kit/data/test-page-worker.js
new file mode 100644
index 0000000..d59ccae
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/data/test-page-worker.js
@@ -0,0 +1,29 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+// get title directly
+self.postMessage(["assertEqual", document.title, "Page Worker test",
+ "Correct page title accessed directly"]);
+
+// get <p> directly
+let p = document.getElementById("paragraph");
+self.postMessage(["assert", !!p, "<p> can be accessed directly"]);
+self.postMessage(["assertEqual", p.firstChild.nodeValue,
+ "Lorem ipsum dolor sit amet.",
+ "Correct text node expected"]);
+
+// Modify page
+let div = document.createElement("div");
+div.setAttribute("id", "block");
+div.appendChild(document.createTextNode("Test text created"));
+document.body.appendChild(div);
+
+// Check back the modification
+div = document.getElementById("block");
+self.postMessage(["assert", !!div, "<div> can be accessed directly"]);
+self.postMessage(["assertEqual", div.firstChild.nodeValue,
+ "Test text created", "Correct text node expected"]);
+self.postMessage(["done"]);
+
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/data/test.html b/tools/addon-sdk-1.7/packages/addon-kit/data/test.html
new file mode 100644
index 0000000..0c7cf24
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/data/test.html
@@ -0,0 +1,12 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<html>
+ <head>
+ <title>foo</title>
+ </head>
+ <body>
+ <p>bar</p>
+ </body>
+</html>
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/docs/clipboard.md b/tools/addon-sdk-1.7/packages/addon-kit/docs/clipboard.md
new file mode 100644
index 0000000..387766e
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/docs/clipboard.md
@@ -0,0 +1,62 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Dietrich Ayala [dietrich@mozilla.com] -->
+
+The `clipboard` module allows callers to interact with the system clipboard,
+setting and retrieving its contents.
+
+You can optionally specify the type of the data to set and retrieve.
+The following types are supported:
+
+* `text` (plain text)
+* `html` (a string of HTML)
+
+If no data type is provided, then the module will detect it for you.
+
+Examples
+--------
+
+Set and get the contents of the clipboard.
+
+ let clipboard = require("clipboard");
+ clipboard.set("Lorem ipsum dolor sit amet");
+ let contents = clipboard.get();
+
+Set the clipboard contents to some HTML.
+
+ let clipboard = require("clipboard");
+ clipboard.set("<blink>Lorem ipsum dolor sit amet</blink>", "html");
+
+If the clipboard contains HTML content, open it in a new tab.
+
+ let clipboard = require("clipboard");
+ if (clipboard.currentFlavors.indexOf("html") != -1)
+ require("tabs").open("data:text/html," + clipboard.get("html"));
+
+<api name="set">
+@function
+ Replace the contents of the user's clipboard with the provided data.
+@param data {string}
+ The data to put on the clipboard.
+@param [datatype] {string}
+ The type of the data (optional).
+</api>
+
+<api name="get">
+@function
+ Get the contents of the user's clipboard.
+@param [datatype] {string}
+ Retrieve the clipboard contents only if matching this type (optional).
+ The function will return null if the contents of the clipboard do not match
+ the supplied type.
+</api>
+
+<api name="currentFlavors">
+@property {array}
+ Data on the clipboard is sometimes available in multiple types. For example,
+ HTML data might be available as both a string of HTML (the `html` type)
+ and a string of plain text (the `text` type). This function returns an array
+ of all types in which the data currently on the clipboard is available.
+</api>
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/docs/context-menu.md b/tools/addon-sdk-1.7/packages/addon-kit/docs/context-menu.md
new file mode 100644
index 0000000..28fb35a
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/docs/context-menu.md
@@ -0,0 +1,719 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Drew Willcoxon [adw@mozilla.com] -->
+<!-- edited by Noelle Murata [fiveinchpixie@gmail.com] -->
+
+The `context-menu` module lets you add items to Firefox's page context menu.
+
+
+Introduction
+------------
+
+The `context-menu` API provides a simple, declarative way to add items to the
+page's context menu. You can add items that perform an action when clicked,
+submenus, and menu separators.
+
+Instead of manually adding items when particular contexts occur and then
+removing them when those contexts go away, you *bind* items to contexts, and the
+adding and removing is automatically handled for you. Items are bound to
+contexts in much the same way that event listeners are bound to events. When
+the user invokes the context menu, all of the items bound to the current context
+are automatically added to the menu. If no items are bound, none are added.
+Likewise, any items that were previously in the menu but are not bound to the
+current context are automatically removed from the menu. You never need to
+manually remove your items from the menu unless you want them to never appear
+again.
+
+For example, if your add-on needs to add a context menu item whenever the
+user visits a certain page, don't create the item when that page loads, and
+don't remove it when the page unloads. Rather, create your item only once and
+supply a context that matches the target URL.
+
+
+Specifying Contexts
+-------------------
+
+As its name implies, the context menu should be reserved for the occurrence of
+specific contexts. Contexts can be related to page content or the page itself,
+but they should never be external to the page.
+
+For example, a good use of the menu would be to show an "Edit Image" item when
+the user right-clicks an image in the page. A bad use would be to show a
+submenu that listed all the user's tabs, since tabs aren't related to the page
+or the node the user clicked to open the menu.
+
+### The Page Context
+
+First of all, you may not need to specify a context at all. When an item does
+not specify a context, the page context applies.
+
+The *page context* occurs when the user invokes the context menu on a
+non-interactive portion of the page. Try right-clicking a blank spot in this
+page, or on text. Make sure that no text is selected. The menu that appears
+should contain the items "Back", "Forward", "Reload", "Stop", and so on. This
+is the page context.
+
+The page context is appropriate when your item acts on the page as a whole. It
+does not occur when the user invokes the context menu on a link, image, or other
+non-text node, or while a selection exists.
+
+### Declarative Contexts
+
+You can specify some simple, declarative contexts when you create a menu item by
+setting the `context` property of the options object passed to its constructor,
+like this:
+
+ var cm = require("context-menu");
+ cm.Item({
+ label: "My Menu Item",
+ context: cm.URLContext("*.mozilla.org")
+ });
+
+These contexts may be specified by calling the following constructors. Each is
+exported by the `context-menu` module.
+
+<table>
+ <tr>
+ <th>Constructor</th>
+ <th>Description</th>
+ </tr>
+ <tr>
+ <td><code>
+ PageContext()
+ </code></td>
+ <td>
+ The page context.
+ </td>
+ </tr>
+ <tr>
+ <td><code>
+ SelectionContext()
+ </code></td>
+ <td>
+ This context occurs when the menu is invoked on a page in which the user
+ has made a selection.
+ </td>
+ </tr>
+ <tr>
+ <td><code>
+ SelectorContext(selector)
+ </code></td>
+ <td>
+ This context occurs when the menu is invoked on a node that either matches
+ <code>selector</code>, a CSS selector, or has an ancestor that matches.
+ <code>selector</code> may include multiple selectors separated by commas,
+ e.g., <code>"a[href], img"</code>.
+ </td>
+ </tr>
+ <tr>
+ <td><code>
+ URLContext(matchPattern)
+ </code></td>
+ <td>
+ This context occurs when the menu is invoked on pages with particular
+ URLs. <code>matchPattern</code> is a match pattern string or an array of
+ match pattern strings. When <code>matchPattern</code> is an array, the
+ context occurs when the menu is invoked on a page whose URL matches any of
+ the patterns. These are the same match pattern strings that you use with
+ the <a href="packages/addon-kit/page-mod.html"><code>page-mod</code></a>
+ <code>include</code> property.
+ <a href="packages/api-utils/match-pattern.html">Read more about patterns</a>.
+ </td>
+ </tr>
+ <tr>
+ <td>
+ array
+ </td>
+ <td>
+ An array of any of the other types. This context occurs when all contexts
+ in the array occur.
+ </td>
+ </tr>
+</table>
+
+Menu items also have a `context` property that can be used to add and remove
+declarative contexts after construction. For example:
+
+ var context = require("context-menu").SelectorContext("img");
+ myMenuItem.context.add(context);
+ myMenuItem.context.remove(context);
+
+When a menu item is bound to more than one context, it appears in the menu when
+all of those contexts occur.
+
+### In Content Scripts
+
+The declarative contexts are handy but not very powerful. For instance, you
+might want your menu item to appear for any page that has at least one image,
+but declarative contexts won't help you there.
+
+When you need more control control over the context in which your menu items are
+shown, you can use content scripts. Like other APIs in the SDK, the
+`context-menu` API uses
+[content scripts](dev-guide/guides/content-scripts/index.html) to let your
+add-on interact with pages in the browser. Each menu item you create in the
+top-level context menu can have a content script.
+
+A special event named `"context"` is emitted in your content scripts whenever
+the context menu is about to be shown. If you register a listener function for
+this event and it returns true, the menu item associated with the listener's
+content script is shown in the menu.
+
+For example, this item appears whenever the context menu is invoked on a page
+that contains at least one image:
+
+ require("context-menu").Item({
+ label: "This Page Has Images",
+ contentScript: 'self.on("context", function (node) {' +
+ ' return !!document.querySelector("img");' +
+ '});'
+ });
+
+Note that the listener function has a parameter called `node`. This is the node
+in the page that the user context-clicked to invoke the menu. You can use it to
+determine whether your item should be shown.
+
+You can both specify declarative contexts and listen for contexts in a content
+script. In that case, the declarative contexts are evaluated first. If they
+are not current, then your context listener is never called.
+
+This example takes advantage of that fact. The listener can be assured that
+`node` will always be an image:
+
+ var cm = require("context-menu");
+ cm.Item({
+ label: "A Mozilla Image",
+ context: cm.SelectorContext("img"),
+ contentScript: 'self.on("context", function (node) {' +
+ ' return /mozilla/.test(node.src);' +
+ '});'
+ });
+
+Your item is shown only when all declarative contexts are current and your
+context listener returns true.
+
+
+Handling Menu Item Clicks
+-------------------------
+
+In addition to using content scripts to listen for the `"context"` event as
+described above, you can use content scripts to handle item clicks. When the
+user clicks your menu item, an event named `"click"` is emitted in the item's
+content script.
+
+Therefore, to handle an item click, listen for the `"click"` event in that
+item's content script like so:
+
+ require("context-menu").Item({
+ label: "My Item",
+ contentScript: 'self.on("click", function (node, data) {' +
+ ' console.log("Item clicked!");' +
+ '});'
+ });
+
+Note that the listener function has parameters called `node` and `data`. `node`
+is the node that the user context-clicked to invoke the menu. You can use it
+when performing some action. `data` is the `data` property of the menu item
+that was clicked. Since only top-level menu items have content scripts, this
+comes in handy for determining which item in a `Menu` was clicked:
+
+ var cm = require("context-menu");
+ cm.Menu({
+ label: "My Menu",
+ contentScript: 'self.on("click", function (node, data) {' +
+ ' console.log("You clicked " + data);' +
+ '});',
+ items: [
+ cm.Item({ label: "Item 1", data: "item1" }),
+ cm.Item({ label: "Item 2", data: "item2" }),
+ cm.Item({ label: "Item 3", data: "item3" })
+ ]
+ });
+
+Often you will need to collect some kind of information in the click listener
+and perform an action unrelated to content. To communicate to the menu item
+associated with the content script, the content script can call the
+`postMessage` function attached to the global `self` object, passing it some
+JSON-able data. The menu item's `"message"` event listener will be called with
+that data.
+
+ var cm = require("context-menu");
+ cm.Item({
+ label: "Edit Image",
+ context: cm.SelectorContext("img"),
+ contentScript: 'self.on("click", function (node, data) {' +
+ ' self.postMessage(node.src);' +
+ '});',
+ onMessage: function (imgSrc) {
+ openImageEditor(imgSrc);
+ }
+ });
+
+
+Updating a Menu Item's Label
+----------------------------
+
+Each menu item must be created with a label, but you can change its label later
+using a couple of methods.
+
+The simplest method is to set the menu item's `label` property. This example
+updates the item's label based on the number of times it's been clicked:
+
+ var numClicks = 0;
+ var myItem = require("context-menu").Item({
+ label: "Click Me: " + numClicks,
+ contentScript: 'self.on("click", self.postMessage);',
+ onMessage: function () {
+ numClicks++;
+ this.label = "Click Me: " + numClicks;
+ // Setting myItem.label is equivalent.
+ }
+ });
+
+Sometimes you might want to update the label based on the context. For
+instance, if your item performs a search with the user's selected text, it would
+be nice to display the text in the item to provide feedback to the user. In
+these cases you can use the second method. Recall that your content scripts can
+listen for the `"context"` event and if your listeners return true, the items
+associated with the content scripts are shown in the menu. In addition to
+returning true, your `"context"` listeners can also return strings. When a
+`"context"` listener returns a string, it becomes the item's new label.
+
+This item implements the aforementioned search example:
+
+ var cm = require("context-menu");
+ cm.Item({
+ label: "Search Google",
+ context: cm.SelectionContext(),
+ contentScript: 'self.on("context", function () {' +
+ ' var text = window.getSelection().toString();' +
+ ' if (text.length > 20)' +
+ ' text = text.substr(0, 20) + "...";' +
+ ' return "Search Google for " + text;' +
+ '});'
+ });
+
+The `"context"` listener gets the window's current selection, truncating it if
+it's too long, and includes it in the returned string. When the item is shown,
+its label will be "Search Google for `text`", where `text` is the truncated
+selection.
+
+
+More Examples
+-------------
+
+For conciseness, these examples create their content scripts as strings and use
+the `contentScript` property. In your own add-on, you will probably want to
+create your content scripts in separate files and pass their URLs using the
+`contentScriptFile` property. See
+[Working with Content Scripts](dev-guide/guides/content-scripts/index.html)
+for more information.
+
+<div class="warning">
+<p>Unless your content script is extremely simple and consists only of a
+static string, don't use <code>contentScript</code>: if you do, you may
+have problems getting your add-on approved on AMO.</p>
+<p>Instead, keep the script in a separate file and load it using
+<code>contentScriptFile</code>. This makes your code easier to maintain,
+secure, debug and review.</p>
+</div>
+
+Show an "Edit Page Source" item when the user right-clicks a non-interactive
+part of the page:
+
+ require("context-menu").Item({
+ label: "Edit Page Source",
+ contentScript: 'self.on("click", function (node, data) {' +
+ ' self.postMessage(document.URL);' +
+ '});',
+ onMessage: function (pageURL) {
+ editSource(pageURL);
+ }
+ });
+
+Show an "Edit Image" item when the menu is invoked on an image:
+
+ var cm = require("context-menu");
+ cm.Item({
+ label: "Edit Image",
+ context: cm.SelectorContext("img"),
+ contentScript: 'self.on("click", function (node, data) {' +
+ ' self.postMessage(node.src);' +
+ '});',
+ onMessage: function (imgSrc) {
+ openImageEditor(imgSrc);
+ }
+ });
+
+Show an "Edit Mozilla Image" item when the menu is invoked on an image in a
+mozilla.org or mozilla.com page:
+
+ var cm = require("context-menu");
+ cm.Item({
+ label: "Edit Mozilla Image",
+ context: [
+ cm.URLContext(["*.mozilla.org", "*.mozilla.com"]),
+ cm.SelectorContext("img")
+ ],
+ contentScript: 'self.on("click", function (node, data) {' +
+ ' self.postMessage(node.src);' +
+ '});',
+ onMessage: function (imgSrc) {
+ openImageEditor(imgSrc);
+ }
+ });
+
+Show an "Edit Page Images" item when the page contains at least one image:
+
+ var cm = require("context-menu");
+ cm.Item({
+ label: "Edit Page Images",
+ // This ensures the item only appears during the page context.
+ context: cm.PageContext(),
+ contentScript: 'self.on("context", function (node) {' +
+ ' var pageHasImgs = !!document.querySelector("img");' +
+ ' return pageHasImgs;' +
+ '});' +
+ 'self.on("click", function (node, data) {' +
+ ' var imgs = document.querySelectorAll("img");' +
+ ' var imgSrcs = [];' +
+ ' for (var i = 0 ; i < imgs.length; i++)' +
+ ' imgSrcs.push(imgs[i].src);' +
+ ' self.postMessage(imgSrcs);' +
+ '});',
+ onMessage: function (imgSrcs) {
+ openImageEditor(imgSrcs);
+ }
+ });
+
+Show a "Search With" menu when the user right-clicks an anchor that searches
+Google or Wikipedia with the text contained in the anchor:
+
+ var cm = require("context-menu");
+ var googleItem = cm.Item({
+ label: "Google",
+ data: "http://www.google.com/search?q="
+ });
+ var wikipediaItem = cm.Item({
+ label: "Wikipedia",
+ data: "http://en.wikipedia.org/wiki/Special:Search?search="
+ });
+ var searchMenu = cm.Menu({
+ label: "Search With",
+ context: cm.SelectorContext("a[href]"),
+ contentScript: 'self.on("click", function (node, data) {' +
+ ' var searchURL = data + node.textContent;' +
+ ' window.location.href = searchURL;' +
+ '});',
+ items: [googleItem, wikipediaItem]
+ });
+
+
+<api name="Item">
+@class
+A labeled menu item that can perform an action when clicked.
+<api name="Item">
+@constructor
+ Creates a labeled menu item that can perform an action when clicked.
+@param options {object}
+ An object with the following keys:
+ @prop label {string}
+ The item's label. It must either be a string or an object that implements
+ `toString()`.
+ @prop [image] {string}
+ The item's icon, a string URL. The URL can be remote, a reference to an
+ image in the add-on's `data` directory, or a data URI.
+ @prop [data] {string}
+ An optional arbitrary value to associate with the item. It must be either a
+ string or an object that implements `toString()`. It will be passed to
+ click listeners.
+ @prop [context] {value}
+ If the item is contained in the top-level context menu, this declaratively
+ specifies the context under which the item will appear; see Specifying
+ Contexts above. Ignored if the item is contained in a submenu.
+ @prop [contentScript] {string,array}
+ If the item is contained in the top-level context menu, this is the content
+ script or an array of content scripts that the item can use to interact with
+ the page. Ignored if the item is contained in a submenu.
+ @prop [contentScriptFile] {string,array}
+ If the item is contained in the top-level context menu, this is the local
+ file URL of the content script or an array of such URLs that the item can
+ use to interact with the page. Ignored if the item is contained in a
+ submenu.
+ @prop [onMessage] {function}
+ If the item is contained in the top-level context menu, this function will
+ be called when the content script calls `self.postMessage`. It will be
+ passed the data that was passed to `postMessage`. Ignored if the item is
+ contained in a submenu.
+</api>
+
+<api name="label">
+@property {string}
+ The menu item's label. You can set this after creating the item to update its
+ label later.
+</api>
+
+<api name="image">
+@property {string}
+ The item's icon, a string URL. The URL can be remote, a reference to an image
+ in the add-on's `data` directory, or a data URI. You can set this after
+ creating the item to update its image later. To remove the item's image, set
+ it to `null`.
+</api>
+
+<api name="data">
+@property {string}
+ An optional arbitrary value to associate with the item. It must be either a
+ string or an object that implements `toString()`. It will be passed to
+ click listeners. You can set this after creating the item to update its data
+ later.
+</api>
+
+<api name="context">
+@property {list}
+ A list of declarative contexts for which the menu item will appear in the
+ context menu. Contexts can be added by calling `context.add()` and removed by
+ called `context.remove()`. This property is meaningful only for items
+ contained in the top-level context menu.
+</api>
+
+<api name="parentMenu">
+@property {Menu}
+ The item's parent `Menu`, or `null` if the item is contained in the top-level
+ context menu. This property is read-only. To add the item to a new menu,
+ call that menu's `addItem()` method.
+</api>
+
+<api name="contentScript">
+@property {string,array}
+ The content script or the array of content scripts associated with the menu
+ item during creation. This property is meaningful only for items contained in
+ the top-level context menu.
+</api>
+
+<api name="contentScriptFile">
+@property {string,array}
+ The URL of a content script or the array of such URLs associated with the menu
+ item during creation. This property is meaningful only for items contained in
+ the top-level context menu.
+</api>
+
+<api name="destroy">
+@method
+ Permanently removes the item from its parent menu and frees its resources.
+ The item must not be used afterward. If you need to remove the item from its
+ parent menu but use it afterward, call `removeItem()` on the parent menu
+ instead.
+</api>
+
+<api name="message">
+@event
+If you listen to this event you can receive message events from content
+scripts associated with this menu item. When a content script posts a
+message using `self.postMessage()`, the message is delivered to the add-on
+code in the menu item's `message` event.
+
+@argument {value}
+Listeners are passed a single argument which is the message posted
+from the content script. The message can be any
+<a href = "dev-guide/guides/content-scripts/using-port.html#json_serializable">JSON-serializable value</a>.
+</api>
+
+</api>
+
+<api name="Menu">
+@class
+A labeled menu item that expands into a submenu.
+
+<api name="Menu">
+@constructor
+ Creates a labeled menu item that expands into a submenu.
+@param options {object}
+ An object with the following keys:
+ @prop label {string}
+ The item's label. It must either be a string or an object that implements
+ `toString()`.
+ @prop items {array}
+ An array of menu items that the menu will contain. Each must be an `Item`,
+ `Menu`, or `Separator`.
+ @prop [image] {string}
+ The menu's icon, a string URL. The URL can be remote, a reference to an
+ image in the add-on's `data` directory, or a data URI.
+ @prop [context] {value}
+ If the menu is contained in the top-level context menu, this declaratively
+ specifies the context under which the menu will appear; see Specifying
+ Contexts above. Ignored if the menu is contained in a submenu.
+ @prop [contentScript] {string,array}
+ If the menu is contained in the top-level context menu, this is the content
+ script or an array of content scripts that the menu can use to interact with
+ the page. Ignored if the menu is contained in a submenu.
+ @prop [contentScriptFile] {string,array}
+ If the menu is contained in the top-level context menu, this is the local
+ file URL of the content script or an array of such URLs that the menu can
+ use to interact with the page. Ignored if the menu is contained in a
+ submenu.
+ @prop [onMessage] {function}
+ If the menu is contained in the top-level context menu, this function will
+ be called when the content script calls `self.postMessage`. It will be
+ passed the data that was passed to `postMessage`. Ignored if the item is
+ contained in a submenu.
+</api>
+
+<api name="label">
+@property {string}
+ The menu's label. You can set this after creating the menu to update its
+ label later.
+</api>
+
+<api name="items">
+@property {array}
+ An array containing the items in the menu. The array is read-only, meaning
+ that modifications to it will not affect the menu. However, setting this
+ property to a new array will replace all the items currently in the menu with
+ the items in the new array.
+</api>
+
+<api name="image">
+@property {string}
+ The menu's icon, a string URL. The URL can be remote, a reference to an image
+ in the add-on's `data` directory, or a data URI. You can set this after
+ creating the menu to update its image later. To remove the menu's image, set
+ it to `null`.
+</api>
+
+<api name="context">
+@property {list}
+ A list of declarative contexts for which the menu will appear in the context
+ menu. Contexts can be added by calling `context.add()` and removed by called
+ `context.remove()`. This property is meaningful only for menus contained in
+ the top-level context menu.
+</api>
+
+<api name="parentMenu">
+@property {Menu}
+ The menu's parent `Menu`, or `null` if the menu is contained in the top-level
+ context menu. This property is read-only. To add the menu to a new menu,
+ call that menu's `addItem()` method.
+</api>
+
+<api name="contentScript">
+@property {string,array}
+ The content script or the array of content scripts associated with the menu
+ during creation. This property is meaningful only for menus contained in the
+ top-level context menu.
+</api>
+
+<api name="contentScriptFile">
+@property {string,array}
+ The URL of a content script or the array of such URLs associated with the menu
+ during creation. This property is meaningful only for menus contained in the
+ top-level context menu.
+</api>
+
+<api name="addItem">
+@method
+ Appends a menu item to the end of the menu. If the item is already contained
+ in another menu or in the top-level context menu, it's automatically removed
+ first.
+@param item {Item,Menu,Separator}
+ The `Item`, `Menu`, or `Separator` to add to the menu.
+</api>
+
+<api name="removeItem">
+@method
+ Removes the given menu item from the menu. If the menu does not contain the
+ item, this method does nothing.
+@param item {Item,Menu,Separator}
+ The menu item to remove from the menu.
+</api>
+
+<api name="destroy">
+@method
+ Permanently removes the menu from its parent menu and frees its resources.
+ The menu must not be used afterward. If you need to remove the menu from its
+ parent menu but use it afterward, call `removeItem()` on the parent menu
+ instead.
+</api>
+
+<api name="message">
+@event
+If you listen to this event you can receive message events from content
+scripts associated with this menu item. When a content script posts a
+message using `self.postMessage()`, the message is delivered to the add-on
+code in the menu item's `message` event.
+
+@argument {value}
+Listeners are passed a single argument which is the message posted
+from the content script. The message can be any
+<a href = "dev-guide/guides/content-scripts/using-port.html#json_serializable">JSON-serializable value</a>.
+</api>
+
+</api>
+
+<api name="Separator">
+@class
+A menu separator. Separators can be contained only in `Menu`s, not in the
+top-level context menu.
+
+<api name="Separator">
+@constructor
+ Creates a menu separator.
+</api>
+
+<api name="parentMenu">
+@property {Menu}
+ The separator's parent `Menu`. This property is read-only. To add the
+ separator to a new menu, call that menu's `addItem()` method.
+</api>
+
+<api name="destroy">
+@method
+ Permanently removes the separator from its parent menu and frees its
+ resources. The separator must not be used afterward. If you need to remove
+ the separator from its parent menu but use it afterward, call `removeItem()`
+ on the parent menu instead.
+</api>
+
+</api>
+
+<api name="PageContext">
+@class
+<api name="PageContext">
+@constructor
+ Creates a page context. See Specifying Contexts above.
+</api>
+</api>
+
+<api name="SelectionContext">
+@class
+<api name="SelectionContext">
+@constructor
+ Creates a context that occurs when a page contains a selection. See
+ Specifying Contexts above.
+</api>
+</api>
+
+<api name="SelectorContext">
+@class
+<api name="SelectorContext">
+@constructor
+ Creates a context that matches a given CSS selector. See Specifying Contexts
+ above.
+@param selector {string}
+ A CSS selector.
+</api>
+</api>
+
+<api name="URLContext">
+@class
+<api name="URLContext">
+@constructor
+ Creates a context that matches pages with particular URLs. See Specifying
+ Contexts above.
+@param matchPattern {string,array}
+ A [match pattern](packages/api-utils/match-pattern.html) string or an array of
+ match pattern strings.
+</api>
+</api>
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/docs/hotkeys.md b/tools/addon-sdk-1.7/packages/addon-kit/docs/hotkeys.md
new file mode 100644
index 0000000..b12791c
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/docs/hotkeys.md
@@ -0,0 +1,78 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Irakli Gozalishvili [gozala@mozilla.com] -->
+
+Some add-ons may wish to define keyboard shortcuts for certain operations. This
+module exposes an API to create those.
+
+<api name="Hotkey">
+@class
+
+Module exports `Hotkey` constructor allowing users to create a `hotkey` for the
+host application.
+
+<api name="Hotkey">
+@constructor
+Creates a hotkey who's `onPress` listener method is invoked when key combination
+defined by `hotkey` is pressed.
+
+Please note: If more than one `hotkey` is created for the same key
+combination, the listener is executed only on the last one created
+
+@param options {Object}
+ Options for the hotkey, with the following keys:
+
+@prop combo {String}
+Any function key: `"f1, f2, ..., f24"` or key combination in the format
+of `'modifier-key'`:
+
+ "accel-s"
+ "meta-shift-i"
+ "control-alt-d"
+
+Modifier keynames:
+
+- **shift**: The Shift key.
+- **alt**: The Alt key. On the Macintosh, this is the Option key. On
+ Macintosh this can only be used in conjunction with another modifier,
+ since `Alt-Letter` combinations are reserved for entering special
+ characters in text.
+- **meta**: The Meta key. On the Macintosh, this is the Command key.
+- **control**: The Control key.
+- **accel**: The key used for keyboard shortcuts on the user's platform,
+ which is Control on Windows and Linux, and Command on Mac. Usually, this
+ would be the value you would use.
+
+@prop onPress {Function}
+Function that is invoked when the key combination `hotkey` is pressed.
+
+</api>
+<api name="destroy">
+@method
+Stops this instance of `Hotkey` from reacting on the key combinations. Once
+destroyed it can no longer be used.
+</api>
+</api>
+
+## Example ##
+
+ // Define keyboard shortcuts for showing and hiding a custom panel.
+ var { Hotkey } = require("hotkeys");
+
+ var showHotKey = Hotkey({
+ combo: "accel-shift-o",
+ onPress: function() {
+ showMyPanel();
+ }
+ });
+ var hideHotKey = Hotkey({
+ combo: "accel-alt-shift-o",
+ onPress: function() {
+ hideMyPanel();
+ }
+ });
+
+[Mozilla keyboard planning FAQ]:http://www.mozilla.org/access/keyboard/
+[keyboard shortcuts]:https://developer.mozilla.org/en/XUL_Tutorial/Keyboard_Shortcuts
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/docs/notifications.md b/tools/addon-sdk-1.7/packages/addon-kit/docs/notifications.md
new file mode 100644
index 0000000..ca120ab
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/docs/notifications.md
@@ -0,0 +1,64 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Drew Willcoxon [adw@mozilla.com] -->
+
+The `notifications` module allows you to display transient,
+[toaster](http://en.wikipedia.org/wiki/Toast_%28computing%29)-style
+desktop messages to the user.
+
+This API supports desktop notifications on Windows, OS X using
+[Growl](http://growl.info/), and Linux using libnotify. If the user's system
+does not support desktop notifications or if its notifications service is not
+running, then notifications made with this API are logged to Firefox's error
+console and, if the user launched Firefox from the command line, the terminal.
+
+Examples
+--------
+
+Here's a typical example. When the message is clicked, a string is logged to
+the console.
+
+ var notifications = require("notifications");
+ notifications.notify({
+ title: "Jabberwocky",
+ text: "'Twas brillig, and the slithy toves",
+ data: "did gyre and gimble in the wabe",
+ onClick: function (data) {
+ console.log(data);
+ // console.log(this.data) would produce the same result.
+ }
+ });
+
+This one displays an icon that's stored in the add-on's `data` directory. (See
+the [`self`](packages/addon-kit/self.html) module documentation for more information.)
+
+ var notifications = require("notifications");
+ var self = require("self");
+ var myIconURL = self.data.url("myIcon.png");
+ notifications.notify({
+ text: "I have an icon!",
+ iconURL: myIconURL
+ });
+
+
+<api name="notify">
+@function
+ Displays a transient notification to the user.
+@param options {object}
+ An object with the following keys. Each is optional.
+ @prop [title] {string}
+ A string to display as the message's title.
+ @prop [text] {string}
+ A string to display as the body of the message.
+ @prop [iconURL] {string}
+ The URL of an icon to display inside the message. It may be a remote URL,
+ a data URI, or a URL returned by the [`self`](packages/addon-kit/self.html)
+ module.
+ @prop [onClick] {function}
+ A function to be called when the user clicks the message. It will be passed
+ the value of `data`.
+ @prop [data] {string}
+ A string that will be passed to `onClick`.
+</api>
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/docs/page-mod.md b/tools/addon-sdk-1.7/packages/addon-kit/docs/page-mod.md
new file mode 100644
index 0000000..3b6ef6b
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/docs/page-mod.md
@@ -0,0 +1,412 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Nickolay Ponomarev [asqueella@gmail.com] -->
+<!-- contributed by Myk Melez [myk@mozilla.org] -->
+<!-- contributed by Irakli Gozalishvil [gozala@mozilla.com] -->
+
+Overview
+--------
+The page-mod module enables add-on developers to execute scripts in the context
+of specific web pages. Most obviously you could use page-mod to dynamically
+modify the content of certain pages.
+
+The module exports a constructor function `PageMod` which creates a new page
+modification (or "mod" for short).
+
+A page mod does not modify its pages until those pages are loaded or reloaded.
+In other words, if your add-on is loaded while the user's browser is open, the
+user will have to reload any open pages that match the mod for the mod to affect
+them.
+
+To stop a page mod from making any more modifications, call its `destroy`
+method.
+
+Like all modules that interact with web content, page-mod uses content
+scripts that execute in the content process and defines a messaging API to
+communicate between the content scripts and the main add-on script. For more
+details on content scripting see the tutorial on [interacting with web
+content](dev-guide/guides/content-scripts/index.html).
+
+To create a PageMod the add-on developer supplies:
+
+* a set of rules to select the desired subset of web pages based on their URL.
+Each rule is specified using the
+[match-pattern](packages/api-utils/match-pattern.html) syntax.
+
+* a set of content scripts to execute in the context of the desired pages.
+
+* a value for the onAttach option: this value is a function which will be
+called when a page is loaded that matches the ruleset. This is used to set up a
+communication channel between the add-on code and the content script.
+
+All these parameters are optional except for the ruleset, which must include
+at least one rule.
+
+The following add-on displays an alert whenever a page matching the ruleset is
+loaded:
+
+ var pageMod = require("page-mod");
+ pageMod.PageMod({
+ include: "*.org",
+ contentScript: 'window.alert("Page matches ruleset");'
+ });
+
+If you specify a value of "ready" or "end" for `contentScriptWhen`,
+as opposed to "start",
+then the content script can interact with the DOM itself:
+
+ var pageMod = require("page-mod");
+ pageMod.PageMod({
+ include: "*.org",
+ contentScriptWhen: 'end',
+ contentScript: 'document.body.innerHTML = ' +
+ ' "<h1>Page matches ruleset</h1>";'
+ });
+
+### Using `contentScriptFile` ###
+
+Most of the examples in this page define content scripts as strings,
+and use the `contentScript` option to assign them to page mods.
+
+Alternatively, you can create content scripts in separate files
+under your add-on's `data` directory. Then you can use the
+[`self`](packages/addon-kit/self.html) module to retrieve a URL pointing
+to the file, and assign this to the page-mod's `contentScriptFile`
+property.
+
+For example, if you save the content script
+file in your `data` directory as "myScript.js", you would assign it using
+code like:
+
+ var data = require("self").data;
+
+ var pageMod = require("page-mod");
+ pageMod.PageMod({
+ include: "*.org",
+ contentScriptWhen: 'end',
+ contentScriptFile: data.url("myScript.js")
+ });
+
+<div class="warning">
+<p>Unless your content script is extremely simple and consists only of a
+static string, don't use <code>contentScript</code>: if you do, you may
+have problems getting your add-on approved on AMO.</p>
+<p>Instead, keep the script in a separate file and load it using
+<code>contentScriptFile</code>. This makes your code easier to maintain,
+secure, debug and review.</p>
+</div>
+
+### Styling web pages ###
+
+Sometimes adding a script to web pages is not enough, you also want to styling
+them. `PageMod` provides an easy way to do that through options' `contentStyle`
+and `contentStyleFile` properties:
+
+ var data = require("self").data;
+ var pageMod = require("page-mod");
+
+ pageMod.PageMod({
+ include: "*.org",
+
+ contentStyleFile: data.url("my-page-mod.css"),
+ contentStyle: [
+ "div { padding: 10px; border: 1px solid silver}",
+ "img { display: none}"
+ ]
+ })
+
+It's important to note that `PageMod` will add these styles as
+[user style sheet](https://developer.mozilla.org/en/CSS/Getting_Started/Cascading_and_inheritance).
+
+## Communicating With Content Scripts ##
+
+When a matching page is loaded the `PageMod` will call the function that the
+add-on code supplied to `onAttach`. The `PageMod` supplies one argument to
+this function: a `worker` object.
+
+The worker can be thought of as the add-on's end of
+a communication channel between the add-on code and the content scripts that
+have been attached to this page.
+
+Thus the add-on can pass messages to the content scripts by calling the
+worker's `postMessage` function and can receive messages from the content
+scripts by registering a function as a listener to the worker's `on` function.
+
+Note that if multiple matching pages are loaded simultaneously then each page
+is loaded into its own execution context with its own copy of the content
+scripts. In this case `onAttach` is called once for each loaded page, and the
+add-on code will have a separate worker for each page:
+
+![Multiple workers](static-files/media/multiple-workers.jpg)
+
+This is demonstrated in the following example:
+
+ var pageMod = require("page-mod");
+ var tabs = require("tabs");
+
+ var workers = [];
+
+ pageMod.PageMod({
+ include: ["http://www.mozilla*"],
+ contentScriptWhen: 'end',
+ contentScript: "onMessage = function onMessage(message) {" +
+ " window.alert(message);};",
+ onAttach: function onAttach(worker) {
+ if (workers.push(worker) == 3) {
+ workers[0].postMessage("The first worker!");
+ workers[1].postMessage("The second worker!");
+ workers[2].postMessage("The third worker!");
+ }
+ }
+ });
+
+ tabs.open("http://www.mozilla.com");
+ tabs.open("http://www.mozilla.org");
+ tabs.open("http://www.mozilla-europe.org");
+
+Here we specify a ruleset to match any URLs starting with
+"http://www.mozilla". When a page matches we add the supplied worker to
+an array, and when we have three workers in the array we send a message to
+each worker in turn, telling it the order in which it was attached. The
+worker just displays the message in an alert box.
+
+This shows that separate pages execute in separate contexts and that each
+context has its own communication channel with the add-on script.
+
+Note though that while there is a separate worker for each execution context,
+the worker is shared across all the content scripts associated with a single
+execution context. In the following example we pass two content scripts into
+the `PageMod`: these content scripts will share a worker instance.
+
+In the example each content script identifies itself to the add-on script
+by sending it a message using the global `postMessage` function. In the
+`onAttach` function the add-on code logs the fact that a new page is
+attached and registers a listener function that simply logs the message:
+
+
+ var pageMod = require("page-mod");
+ var data = require("self").data;
+ var tabs = require("tabs");
+
+ pageMod.PageMod({
+ include: ["http://www.mozilla*"],
+ contentScriptWhen: 'end',
+ contentScript: ["postMessage('Content script 1 is attached to '+ " +
+ "document.URL);",
+ "postMessage('Content script 2 is attached to '+ " +
+ "document.URL);"],
+ onAttach: function onAttach(worker) {
+ console.log("Attaching content scripts")
+ worker.on('message', function(data) {
+ console.log(data);
+ });
+ }
+ });
+
+ tabs.open("http://www.mozilla.com");
+
+The console output of this add-on is:
+
+<pre>
+ info: Attaching content scripts
+ info: Content script 1 is attached to http://www.mozilla.com/en-US/
+ info: Content script 2 is attached to http://www.mozilla.com/en-US/
+</pre>
+
+### Mapping workers to tabs ###
+
+The [`worker`](packages/api-utils/content/worker.html) has a `tab`
+property which returns the tab associated with this worker. You can use this
+to access the [`tabs API`](packages/addon-kit/tabs.html) for the tab
+associated with a specific page:
+
+ var pageMod = require("page-mod");
+ var tabs = require("tabs");
+
+ pageMod.PageMod({
+ include: ["*"],
+ onAttach: function onAttach(worker) {
+ console.log(worker.tab.title);
+ }
+ });
+
+### Attaching content scripts to tabs ###
+
+We've seen that the page mod API attaches content scripts to pages based on
+their URL. Sometimes, though, we don't care about the URL: we just want
+to execute a script on demand in the context of a particular tab.
+
+For example, we might want to run a script in the context of the currently
+active tab when the user clicks a widget: to block certain content, to
+change the font style, or to display the page's DOM structure.
+
+Using the `attach` method of the [`tab`](packages/addon-kit/tabs.html)
+object, you can attach a set of content scripts to a particular tab. The
+scripts are executed immediately.
+
+The following add-on creates a widget which, when clicked, highlights all the
+`div` elements in the page loaded into the active tab:
+
+ var widgets = require("widget");
+ var tabs = require("tabs");
+
+ var widget = widgets.Widget({
+ id: "div-show",
+ label: "Show divs",
+ contentURL: "http://www.mozilla.org/favicon.ico",
+ onClick: function() {
+ tabs.activeTab.attach({
+ contentScript:
+ 'var divs = document.getElementsByTagName("div");' +
+ 'for (var i = 0; i < divs.length; ++i) {' +
+ 'divs[i].setAttribute("style", "border: solid red 1px;");' +
+ '}'
+ });
+ }
+ });
+
+## Destroying Workers ##
+
+Workers generate a `detach` event when their associated page is closed: that
+is, when the tab is closed or the tab's location changes. If
+you are maintaining a list of workers belonging to a page mod, you can use
+this event to remove workers that are no longer valid.
+
+For example, if you maintain a list of workers attached to a page mod:
+
+ var workers = [];
+
+ var pageMod = require("page-mod").PageMod({
+ include: ['*'],
+ contentScriptWhen: 'ready',
+ contentScriptFile: data.url('pagemod.js'),
+ onAttach: function(worker) {
+ workers.push(worker);
+ }
+ });
+
+You can remove workers when they are no longer valid by listening to `detach`:
+
+ var workers = [];
+
+ function detachWorker(worker, workerArray) {
+ var index = workerArray.indexOf(worker);
+ if(index != -1) {
+ workerArray.splice(index, 1);
+ }
+ }
+
+ var pageMod = require("page-mod").PageMod({
+ include: ['*'],
+ contentScriptWhen: 'ready',
+ contentScriptFile: data.url('pagemod.js'),
+ onAttach: function(worker) {
+ workers.push(worker);
+ worker.on('detach', function () {
+ detachWorker(this, workers);
+ });
+ }
+ });
+
+<api name="PageMod">
+@class
+A PageMod object. Once activated a page mod will execute the supplied content
+scripts in the context of any pages matching the pattern specified by the
+'include' property.
+<api name="PageMod">
+@constructor
+Creates a PageMod.
+@param options {object}
+ Options for the PageMod, with the following keys:
+ @prop include {string,array}
+ A match pattern string or an array of match pattern strings. These define
+ the pages to which the PageMod applies. See the
+ [match-pattern](packages/api-utils/match-pattern.html) module for
+ a description of match pattern syntax.
+ At least one match pattern must be supplied.
+
+ @prop [contentScriptFile] {string,array}
+ The local file URLs of content scripts to load. Content scripts specified
+ by this option are loaded *before* those specified by the `contentScript`
+ option. Optional.
+ @prop [contentScript] {string,array}
+ The texts of content scripts to load. Content scripts specified by this
+ option are loaded *after* those specified by the `contentScriptFile` option.
+ Optional.
+ @prop [contentScriptWhen="end"] {string}
+ When to load the content scripts. This may take one of the following
+ values:
+
+ * "start": load content scripts immediately after the document
+ element for the page is inserted into the DOM, but before the DOM content
+ itself has been loaded
+ * "ready": load content scripts once DOM content has been loaded,
+ corresponding to the
+ [DOMContentLoaded](https://developer.mozilla.org/en/Gecko-Specific_DOM_Events)
+ event
+ * "end": load content scripts once all the content (DOM, JS, CSS,
+ images) for the page has been loaded, at the time the
+ [window.onload event](https://developer.mozilla.org/en/DOM/window.onload)
+ fires
+
+ This property is optional and defaults to "end".
+
+ @prop [contentStyleFile] {string,array}
+ The local file URLs of stylesheet to load. Content style specified by this
+ option are loaded *before* those specified by the `contentStyle` option.
+ Optional.
+ @prop [contentStyle] {string,array}
+ The texts of stylesheet rules to add. Content styles specified by this
+ option are loaded *after* those specified by the `contentStyleFile` option.
+ Optional.
+
+ @prop [onAttach] {function}
+A function to call when the PageMod attaches content scripts to
+a matching page. The function will be called with one argument, a `worker`
+object which the add-on script can use to communicate with the content scripts
+attached to the page in question.
+
+</api>
+
+<api name="include">
+@property {List}
+A [list](packages/api-utils/list.html) of match pattern strings. These
+define the pages to which the page mod applies. See the
+[match-pattern](packages/api-utils/match-pattern.html) module for a
+description of match patterns. Rules can be added to the list by calling its
+`add` method and removed by calling its `remove` method.
+
+</api>
+
+<api name="destroy">
+@method
+Stops the page mod from making any more modifications. Once destroyed the page
+mod can no longer be used. Note that modifications already made to open pages
+will not be undone, except for any stylesheet added by `contentStyle` or
+`contentStyleFile`, that are unregistered immediately.
+</api>
+
+<api name="attach">
+@event
+This event is emitted this event when the page-mod's content scripts are
+attached to a page whose URL matches the page-mod's `include` filter.
+
+@argument {Worker}
+The listener function is passed a [`Worker`](packages/api-utils/content/worker.html) object that can be used to communicate
+with any content scripts attached to this page.
+</api>
+
+<api name="error">
+@event
+This event is emitted when an uncaught runtime error occurs in one of the page
+mod's content scripts.
+
+@argument {Error}
+Listeners are passed a single argument, the
+[Error](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error)
+object.
+</api>
+
+</api>
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/docs/page-worker.md b/tools/addon-sdk-1.7/packages/addon-kit/docs/page-worker.md
new file mode 100644
index 0000000..5539c25
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/docs/page-worker.md
@@ -0,0 +1,325 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Felipe Gomes [felipc@gmail.com] -->
+
+The `page-worker` module provides a way to create a permanent, invisible page
+and access its DOM.
+
+The module exports a constructor function `Page`, which constructs a new page
+worker. A page worker may be destroyed, after which its memory is freed, and
+you must create a new instance to load another page.
+
+You specify the page to load using the `contentURL` option to the
+[`Page()` constructor](packages/addon-kit/page-worker.html#Page(options)).
+This can point to a remote file:
+
+ pageWorker = require("page-worker").Page({
+ contentScript: "console.log(document.body.innerHTML);",
+ contentURL: "http://en.wikipedia.org/wiki/Internet"
+ });
+
+It can also point to an HTML file which you've packaged with your add-on.
+To do this, save the file in your add-on's `data` directory and create the
+URL using the `data.url()` method of the
+[`self`](packages/addon-kit/self.html) module:
+
+ pageWorker = require("page-worker").Page({
+ contentScript: "console.log(document.body.innerHTML);",
+ contentURL: require("self").data.url("myFile.html")
+ });
+
+You can load a new page by setting the page worker's `contentURL` property.
+In this example we fetch the first paragraph of a page from Wikipedia, then
+the first paragraph of a different page:
+
+ var getFirstParagraph = "var paras = document.getElementsByTagName('p');" +
+ "console.log(paras[0].textContent);" +
+ "self.port.emit('loaded');"
+
+ pageWorker = require("page-worker").Page({
+ contentScript: getFirstParagraph,
+ contentURL: "http://en.wikipedia.org/wiki/Chalk"
+ });
+
+ pageWorker.port.on("loaded", function() {
+ pageWorker.contentURL = "http://en.wikipedia.org/wiki/Cheese"
+ });
+
+## Scripting Page-Worker Content ##
+
+To access the page's DOM you need to attach a script to it. In the SDK these
+scripts are called "content scripts" because they're explicitly used for
+interacting with web content.
+
+You can specify one or more content scripts to load into the page using the
+`contentScript` or `contentScriptFile` options to the
+[`Page()` constructor](packages/addon-kit/page-worker.html#Page(options)).
+With `contentScript` you pass the script as a string, as in the examples
+above. With `contentScriptFile` you pass a URL which points to a script
+saved under your add-on's `data` directory. You construct the URL using
+the `data.url()` method of the
+[`self`](packages/addon-kit/self.html) module.
+
+While content scripts can access DOM content, they can't access any of the SDK
+APIs, so in many cases you'll need to exchange messages between the content
+script and your main add-on code for a complete solution.
+
+For example, the content script might read some content and send it back to
+the main add-on, which could store it using the
+[`simple-storage`](packages/addon-kit/simple-storage.html) API. You can
+communicate with the script using either the
+[`postMessage()`](dev-guide/guides/content-scripts/using-postmessage.html)
+API or (preferably, usually) the
+[`port`](dev-guide/guides/content-scripts/using-port.html) API.
+
+For example, this add-on loads a page from Wikipedia, and runs a content script
+in it to send all the headers back to the main add-on code:
+
+ var pageWorkers = require("page-worker");
+
+ // This content script sends header titles from the page to the add-on:
+ var script = "var elements = document.querySelectorAll('h2 > span'); " +
+ "for (var i = 0; i < elements.length; i++) { " +
+ " postMessage(elements[i].textContent) " +
+ "}";
+
+ // Create a page worker that loads Wikipedia:
+ pageWorkers.Page({
+ contentURL: "http://en.wikipedia.org/wiki/Internet",
+ contentScript: script,
+ contentScriptWhen: "ready",
+ onMessage: function(message) {
+ console.log(message);
+ }
+ });
+
+For conciseness, this example creates the content script as a string and uses
+the `contentScript` property. In your own add-ons, you will probably want to
+create your content scripts in separate files and pass their URLs using the
+`contentScriptFile` property.
+
+<div class="warning">
+<p>Unless your content script is extremely simple and consists only of a
+static string, don't use <code>contentScript</code>: if you do, you may
+have problems getting your add-on approved on AMO.</p>
+<p>Instead, keep the script in a separate file and load it using
+<code>contentScriptFile</code>. This makes your code easier to maintain,
+secure, debug and review.</p>
+</div>
+
+To learn much more about content scripts, see the
+[Working with Content Scripts](dev-guide/guides/content-scripts/index.html)
+guide.
+
+<div class="experimental">
+<h3>Scripting Trusted Page Content</h3>
+
+**Note that the feature described in this section is experimental: we'll
+very probably continue to support it, but the name of the `addon`
+property might change in a future release.**
+
+We've already seen that you can package HTML files in your add-on's `data`
+directory and load them using `page-worker`. We can call this "trusted"
+content, because unlike content loaded from a source outside the
+add-on, the add-on author knows exactly what it's doing. To
+interact with trusted content you don't need to use content scripts:
+you can just include a script from the HTML file in the normal way, using
+`<script>` tags.
+
+Like a content script, these scripts can communicate with the add-on code
+using the
+[`postMessage()`](dev-guide/guides/content-scripts/using-postmessage.html)
+API or the
+[`port`](dev-guide/guides/content-scripts/using-port.html) API.
+The crucial difference is that these scripts access the `postMessage`
+and `port` objects through the `addon` object, whereas content scripts
+access them through the `self` object.
+
+So given an add-on that loads trusted content and uses content scripts
+to access it, there are typically three changes you have to make, if you
+want to use normal page scripts instead:
+
+* **in the content script**: change occurrences of `self` to `addon`.
+For example, `self.port.emit("my-event")` becomes
+`addon.port.emit("my-event")`.
+
+* **in the HTML page itself**: add a `<script>` tag to load the script. So
+if your content script is saved under `data` as "my-script.js", you need
+a line like `<script src="my-script.js"></script>` in the page header.
+
+* **in the "main.js" file**: remove the `contentScriptFile` option in
+the `Page()` constructor.
+
+</div>
+
+<api name="Page">
+@class
+A `Page` object loads the page specified by its `contentURL` option and
+executes any content scripts that have been supplied to it in the
+`contentScript` and `contentScriptFile` options.
+
+The page is not displayed to the user.
+
+The page worker is loaded as soon as the `Page` object is created and stays
+loaded until its `destroy` method is called or the add-on is unloaded.
+
+<api name="Page">
+@constructor
+ Creates an uninitialized page worker instance.
+@param [options] {object}
+ The *`options`* parameter is optional, and if given it should be an object
+ with any of the following keys:
+ @prop [contentURL] {string}
+ The URL of the content to load in the panel.
+ @prop [allow] {object}
+ An object with keys to configure the permissions on the page worker. The
+ boolean key `script` controls if scripts from the page are allowed to run.
+ `script` defaults to true.
+ @prop [contentScriptFile] {string,array}
+ A local file URL or an array of local file URLs of content scripts to load.
+ Content scripts specified by this option are loaded *before* those specified
+ by the `contentScript` option. See
+ [Working with Content Scripts](dev-guide/guides/content-scripts/index.html)
+ for help on setting this property.
+ @prop [contentScript] {string,array}
+ A string or an array of strings containing the texts of content scripts to
+ load. Content scripts specified by this option are loaded *after* those
+ specified by the `contentScriptFile` option.
+ @prop [contentScriptWhen="end"] {string}
+ When to load the content scripts. This may take one of the following
+ values:
+
+ * "start": load content scripts immediately after the document
+ element for the page is inserted into the DOM, but before the DOM content
+ itself has been loaded
+ * "ready": load content scripts once DOM content has been loaded,
+ corresponding to the
+ [DOMContentLoaded](https://developer.mozilla.org/en/Gecko-Specific_DOM_Events)
+ event
+ * "end": load content scripts once all the content (DOM, JS, CSS,
+ images) for the page has been loaded, at the time the
+ [window.onload event](https://developer.mozilla.org/en/DOM/window.onload)
+ fires
+
+ This property is optional and defaults to "end".
+
+ @prop [onMessage] {function}
+ Use this to add a listener to the page worker's `message` event.
+</api>
+
+<api name="port">
+@property {EventEmitter}
+[EventEmitter](packages/api-utils/events.html) object that allows you to:
+
+* send events to the content script using the `port.emit` function
+* receive events from the content script using the `port.on` function
+
+See the guide to
+<a href="dev-guide/guides/content-scripts/using-port.html">
+communicating using <code>port</code></a> for details.
+</api>
+
+<api name="contentURL">
+@property {string}
+The URL of content to load. This can point to
+local content loaded from your add-on's "data" directory or remote content.
+Setting it loads the content immediately.
+</api>
+
+<api name="allow">
+@property {object}
+ A object describing permissions for the content. It contains a single key
+ named `script` whose value is a boolean that indicates whether or not to
+ execute script in the content. `script` defaults to true.
+</api>
+
+<api name="contentScriptFile">
+@property {string,array}
+A local file URL or an array of local file URLs of content scripts to load.
+</api>
+
+<api name="contentScript">
+@property {string,array}
+A string or an array of strings containing the texts of content scripts to
+load.
+</api>
+
+<api name="contentScriptWhen">
+@property {string}
+ When to load the content scripts. This may have one of the following
+ values:
+
+ * "start": load content scripts immediately after the document
+ element for the page is inserted into the DOM, but before the DOM content
+ itself has been loaded
+ * "ready": load content scripts once DOM content has been loaded,
+ corresponding to the
+ [DOMContentLoaded](https://developer.mozilla.org/en/Gecko-Specific_DOM_Events)
+ event
+ * "end": load content scripts once all the content (DOM, JS, CSS,
+ images) for the page has been loaded, at the time the
+ [window.onload event](https://developer.mozilla.org/en/DOM/window.onload)
+ fires
+
+</api>
+
+<api name="destroy">
+@method
+Unloads the page worker. After you destroy a page worker, its memory is freed
+and you must create a new instance if you need to load another page.
+</api>
+
+<api name="postMessage">
+@method
+Sends a message to the content scripts.
+@param message {value}
+The message to send. Must be JSON-able.
+</api>
+
+<api name="on">
+@method
+Registers an event listener with the page worker. See
+[Working with Events](dev-guide/guides/events.html) for help with
+events.
+@param type {string}
+The type of event to listen for.
+@param listener {function}
+The listener function that handles the event.
+</api>
+
+<api name="removeListener">
+@method
+Unregisters an event listener from the page worker.
+@param type {string}
+The type of event for which `listener` was registered.
+@param listener {function}
+The listener function that was registered.
+</api>
+
+<api name="message">
+@event
+If you listen to this event you can receive message events from content
+scripts associated with this page worker. When a content script posts a
+message using `self.postMessage()`, the message is delivered to the add-on
+code in the page worker's `message` event.
+
+@argument {value}
+Listeners are passed a single argument which is the message posted
+from the content script. The message can be any
+<a href = "dev-guide/guides/content-scripts/using-port.html#json_serializable">JSON-serializable value</a>
+</api>
+
+<api name="error">
+@event
+This event is emitted when an uncaught runtime error occurs in one of the
+page worker's content scripts.
+
+@argument {Error}
+Listeners are passed a single argument, the
+[Error](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error)
+object.
+</api>
+
+</api>
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/docs/panel.md b/tools/addon-sdk-1.7/packages/addon-kit/docs/panel.md
new file mode 100644
index 0000000..0a85db9
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/docs/panel.md
@@ -0,0 +1,607 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Myk Melez [myk@mozilla.org] -->
+<!-- contributed by Irakli Gozalishvili [gozala@mozilla.com] -->
+
+This module exports a single constructor function `Panel` which constructs a
+new panel.
+
+A panel is a dialog. Its content is specified as HTML and you can
+execute scripts in it, so the appearance and behaviour of the panel
+is limited only by what you can do using HTML, CSS and JavaScript.
+
+The screenshot below shows a panel whose content is built from the
+list of currently open tabs:
+
+<img class="image-center" src="static-files/media/screenshots/panel-tabs-osx.png"
+alt="Simple panel example">
+
+Panels are useful for presenting temporary interfaces to users in a way that is
+easier for users to ignore and dismiss than a modal dialog, since panels are
+hidden the moment users interact with parts of the application interface outside
+them.
+
+A panel's content is loaded as soon as it is created, before the panel is shown,
+and the content remains loaded when a panel is hidden, so it is possible
+to keep a panel around in the background, updating its content as appropriate
+in preparation for the next time it is shown.
+
+Your add-on can receive notifications when a panel is shown or hidden by
+listening to its `show` and `hide` events.
+
+## Panel Content ##
+
+The panel's content is specified as HTML, which is loaded from the URL
+supplied in the `contentURL` option to the panel's constructor.
+
+You can load remote HTML into the panel:
+
+ var panel = require("panel").Panel({
+ width: 180,
+ height: 180,
+ contentURL: "https://en.wikipedia.org/w/index.php?title=Jetpack&useformat=mobile"
+ });
+
+ panel.show();
+
+<img class="image-center" src="static-files/media/screenshots/wikipedia-jetpack-panel.png"
+alt="Wikipedia Jetpack panel">
+
+You can also load HTML that's been packaged with your add-on, and this is
+most probably how you will create dialogs. To do this, save
+the HTML in your add-on's `data` directory and load it using the `data.url()`
+method exported by the
+[`self`](packages/addon-kit/self.html) module, like this:
+
+ var panel = require("panel").Panel({
+ contentURL: require("self").data.url("myFile.html")
+ });
+
+ panel.show();
+
+## Updating Panel Content ##
+
+You can update the panel's content simply by setting the panel's `contentURL`
+property.
+
+Here's an add-on that adds two widgets to the add-on bar, one which
+shows Google's mobile site and one which shows Bing's mobile site. The widgets
+share a panel object, and switch between the two sites by updating the panel's
+`contentURL` property:
+
+ var panel = require("panel").Panel({
+ contentURL: "about:blank",
+ onHide: function () {
+ panel.contentURL = "about:blank";
+ }
+ });
+
+ require("widget").Widget({
+ id: "bing",
+ label: "Bing",
+ contentURL: "http://www.bing.com/favicon.ico",
+ panel: panel,
+ onClick: function() {
+ panel.contentURL = "http://m.bing.com/";
+ }
+ });
+
+ require("widget").Widget({
+ id: "google",
+ label: "Google",
+ contentURL: "http://www.google.com/favicon.ico",
+ panel: panel,
+ onClick: function() {
+ panel.contentURL = "http://www.google.com/xhtml";
+ }
+ });
+
+## Scripting Panel Content ##
+
+You can't directly access your panel's content from your main add-on code.
+To access the panel's content, you need to load a script into the panel.
+In the SDK these scripts are called "content scripts" because they're
+explicitly used for interacting with web content.
+
+While content scripts can access the content they're attached to, they can't
+use the SDK's APIs. So implementing a complete solution usually means you
+have to send messages between the content script and the main add-on code.
+
+* You can specify one or more content scripts to load into a panel using the
+`contentScript` or `contentScriptFile` options to the
+[`Panel()` constructor](packages/addon-kit/panel.html#Panel%28options%29).
+
+* You can communicate with the script using either the
+[`postMessage()`](dev-guide/guides/content-scripts/using-postmessage.html)
+API or (preferably, usually) the
+[`port`](dev-guide/guides/content-scripts/using-port.html) API.
+
+For example, here's an add-on whose content script intercepts mouse clicks
+on links inside the panel, and sends the target URL to the main add-on
+code. The content script sends messages using `self.port.emit()` and the
+add-on script receives them using `panel.port.on()`.
+
+ var myScript = "window.addEventListener('click', function(event) {" +
+ " var t = event.target;" +
+ " if (t.nodeName == 'A')" +
+ " self.port.emit('click-link', t.toString());" +
+ "}, false);"
+
+ var panel = require("panel").Panel({
+ contentURL: "http://www.bbc.co.uk/mobile/index.html",
+ contentScript: myScript
+ });
+
+ panel.port.on("click-link", function(url) {
+ console.log(url);
+ });
+
+ panel.show();
+
+This example uses `contentScript` to supply the script as a string. It's
+usually better practice to use `contentScriptFile`, which is a URL pointing
+to a script file saved under your add-on's `data` directory.
+
+<div class="warning">
+<p>Unless your content script is extremely simple and consists only of a
+static string, don't use <code>contentScript</code>: if you do, you may
+have problems getting your add-on approved on AMO.</p>
+<p>Instead, keep the script in a separate file and load it using
+<code>contentScriptFile</code>. This makes your code easier to maintain,
+secure, debug and review.</p>
+</div>
+
+<img class="image-right" src="static-files/media/screenshots/text-entry-panel.png"
+alt="Text entry panel">
+
+### Getting User Input ###
+
+The following add-on adds a widget which displays a panel when
+clicked. The panel just contains a `<textarea>` element: when the user
+presses the `return` key, the contents of the `<textarea>` is sent to the
+main add-on code.
+
+The add-on consists of three files:
+
+* **`main.js`**: the main add-on code, that creates the widget and panel
+* **`get-text.js`**: the content script that interacts with the panel content
+* **`text-entry.html`**: the panel content itself, specified as HTML
+
+"main.js" is saved in your add-on's `lib` directory, and the other two files
+go in your add-on's `data` directory:
+
+<pre>
+my-addon/
+ data/
+ get-text.js
+ text-entry.html
+ lib/
+ main.js
+</pre>
+
+The "main.js" looks like this:
+
+ var data = require("self").data;
+
+ // Create a panel whose content is defined in "text-entry.html".
+ // Attach a content script called "get-text.js".
+ var text_entry = require("panel").Panel({
+ width: 212,
+ height: 200,
+ contentURL: data.url("text-entry.html"),
+ contentScriptFile: data.url("get-text.js")
+ });
+
+ // Send the content script a message called "show" when
+ // the panel is shown.
+ text_entry.on("show", function() {
+ text_entry.port.emit("show");
+ });
+
+ // Listen for messages called "text-entered" coming from
+ // the content script. The message payload is the text the user
+ // entered.
+ // In this implementation we'll just log the text to the console.
+ text_entry.port.on("text-entered", function (text) {
+ console.log(text);
+ text_entry.hide();
+ });
+
+ // Create a widget, and attach the panel to it, so the panel is
+ // shown when the user clicks the widget.
+ require("widget").Widget({
+ label: "Text entry",
+ id: "text-entry",
+ contentURL: "http://www.mozilla.org/favicon.ico",
+ panel: text_entry
+ });
+
+The content script "get-text.js" looks like this:
+
+ self.port.on("show", function (arg) {
+ var textArea = document.getElementById('edit-box');
+ textArea.focus();
+ // When the user hits return, send a message to main.js.
+ // The message payload is the contents of the edit box.
+ textArea.onkeyup = function(event) {
+ if (event.keyCode == 13) {
+ // Remove the newline.
+ text = textArea.value.replace(/(\r\n|\n|\r)/gm,"");
+ self.port.emit("text-entered", text);
+ textArea.value = '';
+ }
+ };
+ });
+
+Finally, the "text-entry.html" file defines the `<textarea>` element:
+
+<pre class="brush: html">
+
+&lt;html&gt;
+
+&lt;head&gt;
+ &lt;style type="text/css" media="all"&gt;
+ textarea {
+ margin: 10px;
+ }
+ &lt;/style&gt;
+&lt;/head&gt;
+
+&lt;body&gt;
+ &lt;textarea rows="10" cols="20" id="edit-box">&lt;/textarea&gt;
+&lt;/body&gt;
+
+&lt;/html&gt;
+</pre>
+
+To learn much more about content scripts, see the
+[Working with Content Scripts](dev-guide/guides/content-scripts/index.html)
+guide.
+
+<div class="experimental">
+<h3>Scripting Trusted Panel Content</h3>
+
+**Note that the feature described in this section is experimental: we'll
+very probably continue to support it, but the name of the `addon`
+property might change in a future release.**
+
+We've already seen that you can package HTML files in your add-on's `data`
+directory and use them to define the panel's content. We can call this
+"trusted" content, because unlike content loaded from a source outside the
+add-on, the add-on author knows exactly what it's doing. To
+interact with trusted content you don't need to use content scripts:
+you can just include a script from the HTML file in the normal way, using
+`script` tags.
+
+Like a content script, these scripts can communicate with the add-on code
+using the
+[`postMessage()`](dev-guide/guides/content-scripts/using-postmessage.html)
+API or the
+[`port`](dev-guide/guides/content-scripts/using-port.html) API.
+The crucial difference is that these scripts access the `postMessage`
+and `port` objects through the `addon` object, whereas content scripts
+access them through the `self` object.
+
+To show the difference, we can easily convert the `text-entry` add-on above
+to use normal page scripts instead of content scripts.
+
+The main add-on code is exactly the same as the main add-on code in the
+previous example, except that we don't attach a content script:
+
+ var data = require("self").data;
+
+ // Create a panel whose content is defined in "text-entry.html".
+ var text_entry = require("panel").Panel({
+ width: 212,
+ height: 200,
+ contentURL: data.url("text-entry.html"),
+ });
+
+ // Send the page script a message called "show" when
+ // the panel is shown.
+ text_entry.on("show", function() {
+ text_entry.port.emit("show");
+ });
+
+ // Listen for messages called "text-entered" coming from
+ // the page script. The message payload is the text the user
+ // entered.
+ // In this implementation we'll just log the text to the console.
+ text_entry.port.on("text-entered", function (text) {
+ console.log(text);
+ text_entry.hide();
+ });
+
+ // Create a widget, and attach the panel to it, so the panel is
+ // shown when the user clicks the widget.
+ require("widget").Widget({
+ label: "Text entry",
+ id: "text-entry",
+ contentURL: "http://www.mozilla.org/favicon.ico",
+ panel: text_entry
+ });
+
+The page script is exactly the same as the content script above, except
+that instead of `self`, we use `addon` to access the messaging APIs:
+
+ addon.port.on("show", function (arg) {
+ var textArea = document.getElementById('edit-box');
+ textArea.focus();
+ // When the user hits return, send a message to main.js.
+ // The message payload is the contents of the edit box.
+ textArea.onkeyup = function(event) {
+ if (event.keyCode == 13) {
+ // Remove the newline.
+ text = textArea.value.replace(/(\r\n|\n|\r)/gm,"");
+ addon.port.emit("text-entered", text);
+ textArea.value = '';
+ }
+ };
+ });
+
+Finally, the HTML file now references "get-text.js" inside a `script` tag:
+
+<pre class="brush: html">
+
+&lt;html&gt;
+
+&lt;head&gt;
+ &lt;style type="text/css" media="all"&gt;
+ textarea {
+ margin: 10px;
+ }
+ &lt;/style&gt;
+ &lt;script src="get-text.js"&gt;&lt;/script&gt;
+&lt;/head&gt;
+
+&lt;body&gt;
+ &lt;textarea rows="10" cols="20" id="edit-box">&lt;/textarea&gt;
+&lt;/body&gt;
+
+&lt;/html&gt;
+</pre>
+</div>
+
+## Styling Trusted Panel Content ##
+
+When the panel's content is specified using an HTML file in your `data`
+directory, you can style it using CSS, either embedding the CSS directly
+in the file or referencing a CSS file stored under `data`.
+
+The panel's default style is different for each operating system:
+
+<img class="image-center" src="static-files/media/screenshots/panel-default-style.png"
+alt="OS X panel default style">
+
+This helps to ensure that the panel's style is consistent with the dialogs
+displayed by Firefox and other applications, but means you need to take care
+when applying your own styles. For example, if you set the panel's
+`background-color` property to `white` and do not set the `color` property,
+then the panel's text will be invisible on OS X although it looks fine on Ubuntu.
+
+<api name="Panel">
+@class
+The Panel object represents a floating modal dialog that can by an add-on to
+present user interface content.
+
+Once a panel object has been created it can be shown and hidden using its
+`show()` and `hide()` methods. Once a panel is no longer needed it can be
+deactivated using `destroy()`.
+
+The content of a panel is specified using the `contentURL` option. An add-on
+can interact with the content of a panel using content scripts which it
+supplies in the `contentScript` and/or `contentScriptFile` options. For example,
+a content script could create a menu and send the user's selection to the
+add-on.
+
+<api name="Panel">
+@constructor
+Creates a panel.
+@param options {object}
+ Options for the panel, with the following keys:
+ @prop [width] {number}
+ The width of the panel in pixels. Optional.
+ @prop [height] {number}
+ The height of the panel in pixels. Optional.
+ @prop [contentURL] {string}
+ The URL of the content to load in the panel.
+ @prop [allow] {object}
+ An optional object describing permissions for the content. It should
+ contain a single key named `script` whose value is a boolean that indicates
+ whether or not to execute script in the content. `script` defaults to true.
+ @prop [contentScriptFile] {string,array}
+ A local file URL or an array of local file URLs of content scripts to load.
+ Content scripts specified by this property are loaded *before* those
+ specified by the `contentScript` property.
+ @prop [contentScript] {string,array}
+ A string or an array of strings containing the texts of content scripts to
+ load. Content scripts specified by this property are loaded *after* those
+ specified by the `contentScriptFile` property.
+ @prop [contentScriptWhen="end"] {string}
+ When to load the content scripts. This may take one of the following
+ values:
+
+ * "start": load content scripts immediately after the document
+ element for the panel is inserted into the DOM, but before the DOM content
+ itself has been loaded
+ * "ready": load content scripts once DOM content has been loaded,
+ corresponding to the
+ [DOMContentLoaded](https://developer.mozilla.org/en/Gecko-Specific_DOM_Events)
+ event
+ * "end": load content scripts once all the content (DOM, JS, CSS,
+ images) for the panel has been loaded, at the time the
+ [window.onload event](https://developer.mozilla.org/en/DOM/window.onload)
+ fires
+
+ This property is optional and defaults to "end".
+
+ @prop [onMessage] {function}
+ Include this to listen to the panel's `message` event.
+ @prop [onShow] {function}
+ Include this to listen to the panel's `show` event.
+ @prop [onHide] {function}
+ Include this to listen to the panel's `hide` event.
+</api>
+
+<api name="port">
+@property {EventEmitter}
+[EventEmitter](packages/api-utils/events.html) object that allows you to:
+
+* send events to the content script using the `port.emit` function
+* receive events from the content script using the `port.on` function
+
+See the guide to
+<a href="dev-guide/guides/content-scripts/using-port.html">
+communicating using <code>port</code></a> for details.
+</api>
+
+<api name="isShowing">
+@property {boolean}
+Tells if the panel is currently shown or not. This property is read-only.
+</api>
+
+<api name="height">
+@property {number}
+The height of the panel in pixels.
+</api>
+
+<api name="width">
+@property {number}
+The width of the panel in pixels.
+</api>
+
+<api name="contentURL">
+@property {string}
+The URL of content loaded into the panel. This can point to
+local content loaded from your add-on's "data" directory or remote content.
+Setting it updates the panel's content immediately.
+</api>
+
+<api name="allow">
+@property {object}
+An object describing permissions for the content. It contains a single key
+named `script` whose value is a boolean that indicates whether or not to execute
+script in the content.
+</api>
+
+<api name="contentScriptFile">
+@property {string,array}
+A local file URL or an array of local file URLs of content scripts to load.
+Content scripts specified by this property are loaded *before* those
+specified by the `contentScript` property.
+</api>
+
+<api name="contentScript">
+@property {string,array}
+A string or an array of strings containing the texts of content scripts to
+load. Content scripts specified by this property are loaded *after* those
+specified by the `contentScriptFile` property.
+</api>
+
+<api name="contentScriptWhen">
+@property {string}
+When to load the content scripts. This may have one of the following
+values:
+
+* "start": load content scripts immediately after the document
+element for the panel is inserted into the DOM, but before the DOM content
+itself has been loaded
+* "ready": load content scripts once DOM content has been loaded,
+corresponding to the
+[DOMContentLoaded](https://developer.mozilla.org/en/Gecko-Specific_DOM_Events)
+event
+* "end": load content scripts once all the content (DOM, JS, CSS,
+images) for the panel has been loaded, at the time the
+[window.onload event](https://developer.mozilla.org/en/DOM/window.onload)
+fires
+
+</api>
+
+<api name="destroy">
+@method
+Destroys the panel, unloading any content that was loaded in it. Once
+destroyed, the panel can no longer be used. If you just want to hide
+the panel and might show it later, use `hide` instead.
+</api>
+
+<api name="postMessage">
+@method
+Sends a message to the content scripts.
+@param message {value}
+The message to send. Must be stringifiable to JSON.
+</api>
+
+<api name="show">
+@method
+Displays the panel.
+</api>
+
+<api name="hide">
+@method
+Stops displaying the panel.
+</api>
+
+<api name="resize">
+@method
+Resizes the panel.
+@param width {number}
+The new width of the panel in pixels.
+@param height {number}
+The new height of the panel in pixels.
+</api>
+
+<api name="on">
+@method
+ Registers an event listener with the panel.
+@param type {string}
+ The type of event to listen for.
+@param listener {function}
+ The listener function that handles the event.
+</api>
+
+<api name="removeListener">
+@method
+ Unregisters an event listener from the panel.
+@param type {string}
+ The type of event for which `listener` was registered.
+@param listener {function}
+ The listener function that was registered.
+</api>
+
+<api name="show">
+@event
+This event is emitted when the panel is shown.
+</api>
+
+<api name="hide">
+@event
+This event is emitted when the panel is hidden.
+</api>
+
+<api name="message">
+@event
+If you listen to this event you can receive message events from content
+scripts associated with this panel. When a content script posts a
+message using `self.postMessage()`, the message is delivered to the add-on
+code in the panel's `message` event.
+
+@argument {value}
+Listeners are passed a single argument which is the message posted
+from the content script. The message can be any
+<a href = "dev-guide/guides/content-scripts/using-port.html#json_serializable">JSON-serializable value</a>.
+</api>
+
+<api name="error">
+@event
+This event is emitted when an uncaught runtime error occurs in one of the
+panel's content scripts.
+
+@argument {Error}
+Listeners are passed a single argument, the
+[Error](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error)
+object.
+</api>
+
+</api>
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/docs/passwords.md b/tools/addon-sdk-1.7/packages/addon-kit/docs/passwords.md
new file mode 100644
index 0000000..8ee6109
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/docs/passwords.md
@@ -0,0 +1,568 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Irakli Gozalishvili [gozala@mozilla.com] -->
+
+The `passwords` module allows add-ons to interact with Firefox's
+[Password Manager](http://support.mozilla.com/en-US/kb/Remembering%20passwords)
+to add, retrieve and remove stored credentials.
+
+A _credential_ is the set of information a user supplies to authenticate
+herself with a service. Typically a credential consists of a username and a
+password.
+
+Using this module you can:
+
+1. **Search** for credentials which have been stored in the Password Manager.
+ You can then use the credentials to access their related service (for
+ example, by logging into a web site).
+
+2. **Store** credentials in the Password Manager. You can store different sorts
+ of credentials, as outlined in the "Credentials" section below.
+
+3. **Remove** stored credentials from the Password Manager.
+
+## Credentials ##
+
+In this API, credentials are represented by objects.
+
+You create credential objects to pass into the API, and the API also returns
+credential objects to you. The sections below explain both the properties you
+should define on credential objects and the properties you can expect on
+credential objects returned by the API.
+
+All credential objects include `username` and `password` properties. Different
+sorts of stored credentials include various additional properties, as
+outlined in this section.
+
+You can use the Passwords API with three sorts of credentials:
+
+* Add-on credentials
+* HTML form credentials
+* HTTP Authentication credentials
+
+### Add-on Credential ###
+
+These are associated with your add-on rather than a particular web site.
+They contain the following properties:
+
+<table>
+<colgroup>
+<col width="25%">
+</colgroup>
+<tr>
+ <td>
+ <code>username</code>
+ </td>
+ <td>
+ The username.
+ </td>
+</tr>
+
+<tr>
+ <td>
+ <code>password</code>
+ </td>
+ <td>
+ The password.
+ </td>
+</tr>
+
+<tr>
+ <td>
+ <code>url</code>
+ </td>
+ <td>
+ <p>For an add-on credential, this property is of the form:<br><code>
+ addon:&lt;addon-id&gt;</code>, where <code>&lt;addon-id&gt;</code>
+ is the add-on's
+ <a href="dev-guide/guides/program-id.html">
+ Program ID</a>.</p>
+ <p>You don't supply this value when storing an add-on credential: it is
+ automatically generated for you. However, you can use it to work out
+ which stored credentials belong to your add-on by comparing it with the
+ <code>uri</code> property of the
+ <a href="packages/addon-kit/self.html"><code>self</code></a>
+ module.</p>
+ </td>
+</tr>
+
+<tr>
+ <td>
+ <code>realm</code>
+ </td>
+ <td>
+ <p>You can use this as a name for the credential, to distinguish
+ it from any other credentials you've stored.</p>
+ <p>The realm is displayed
+ in Firefox's Password Manager, under "Site", in brackets after the URL.
+ For example, if the realm for a credential is "User Registration", then
+ its "Site" field will look something like:</p>
+ <code>addon:jid0-01mBBFyu0ZAXCFuB1JYKooSTKIc (User Registration)</code>
+ </td>
+</tr>
+
+</table>
+
+### HTML Form Credential ###
+
+If a web service uses HTML forms to authenticate its users, then the
+corresponding credential is an HTML Form credential.
+
+It contains the following properties:
+
+<table>
+<colgroup>
+<col width="25%">
+</colgroup>
+<tr>
+ <td>
+ <code>username</code>
+ </td>
+ <td>
+ The username.
+ </td>
+</tr>
+
+<tr>
+ <td>
+ <code>password</code>
+ </td>
+ <td>
+ The password.
+ </td>
+</tr>
+
+<tr>
+ <td>
+ <code>url</code>
+ </td>
+ <td>
+ The URL for the web service which requires the credential.
+ You should omit anything after the hostname and (optional) port.
+ </td>
+</tr>
+
+<tr>
+ <td>
+ <code>formSubmitURL</code>
+ </td>
+ <td>
+ The value of the form's "action" attribute.
+ You should omit anything after the hostname and (optional) port.
+ If the form doesn't contain an "action" attribute, this property should
+ match the <code>url</code> property.
+ </td>
+</tr>
+
+<tr>
+ <td>
+ <code>usernameField</code>
+ </td>
+ <td>
+ The value of the "name" attribute for the form's username field.
+ </td>
+</tr>
+
+<tr>
+ <td>
+ <code>passwordField</code>
+ </td>
+ <td>
+ The value of the "name" attribute for the form's password field.
+ </td>
+</tr>
+
+</table>
+
+So: given a form at `http://www.example.com/login`
+with the following HTML:
+
+<script type="syntaxhighlighter" class="brush: html"><![CDATA[
+<form action="http://login.example.com/foo/authenticate.cgi">
+ <div>Please log in.</div>
+ <label>Username:</label> <input type="text" name="uname">
+ <label>Password:</label> <input type="password" name="pword">
+</form>
+]]>
+</script>
+
+The corresponding values for the credential (excluding username and password)
+should be:
+
+<pre>
+ url: "http://www.example.com"
+ formSubmitURL: "http://login.example.com"
+ usernameField: "uname"
+ passwordField: "pword"
+</pre>
+
+Note that for both `url` and `formSubmitURL`, the portion of the URL after the
+hostname is omitted.
+
+### HTTP Authentication Credential ###
+
+These are used to authenticate the user to a web site
+which uses HTTP Authentication, as detailed in
+[RFC 2617](http://tools.ietf.org/html/rfc2617).
+They contain the following properties:
+
+<table>
+<colgroup>
+<col width="25%">
+</colgroup>
+<tr>
+ <td>
+ <code>username</code>
+ </td>
+ <td>
+ The username.
+ </td>
+</tr>
+
+<tr>
+ <td>
+ <code>password</code>
+ </td>
+ <td>
+ The password.
+ </td>
+</tr>
+
+<tr>
+ <td>
+ <code>url</code>
+ </td>
+ <td>
+ The URL for the web service which requires the credential.
+ You should omit anything after the hostname and (optional) port.
+ </td>
+</tr>
+
+<tr>
+ <td>
+ <code>realm</code>
+ </td>
+ <td>
+ <p>The WWW-Authenticate response header sent by the server may include a
+ "realm" field as detailed in
+ <a href="http://tools.ietf.org/html/rfc2617">RFC 2617</a>. If it does,
+ this property contains the value for the "realm" field. Otherwise, it is
+ omitted.</p>
+ <p>The realm is displayed in Firefox's Password Manager, under "Site",
+ in brackets after the URL.</p>
+ </td>
+</tr>
+
+</table>
+
+So: if a web server at `http://www.example.com` requested authentication with
+a response code like this:
+
+<pre>
+ HTTP/1.0 401 Authorization Required
+ Server: Apache/1.3.27
+ WWW-Authenticate: Basic realm="ExampleCo Login"
+</pre>
+
+The corresponding values for the credential (excluding username and password)
+should be:
+
+<pre>
+ url: "http://www.example.com"
+ realm: "ExampleCo Login"
+</pre>
+
+## onComplete and onError ##
+
+This API is explicitly asynchronous, so all its functions take two callback
+functions as additional options: `onComplete` and `onError`.
+
+`onComplete` is called when the operation has completed successfully and
+`onError` is called when the function encounters an error.
+
+Because the `search` function is expected to return a list of matching
+credentials, its `onComplete` option is mandatory. Because the other functions
+don't return a value in case of success their `onComplete` options are
+optional.
+
+For all functions, `onError` is optional.
+
+<api name="search">
+@function
+
+This function is used to retrieve a credential, or a list of credentials,
+stored in the Password Manager.
+
+You pass it any subset of the possible properties a credential can contain.
+Credentials which match all the properties you supplied are returned as an
+argument to the `onComplete` callback.
+
+So if you pass in an empty set of properties, all stored credentials are
+returned:
+
+ function show_all_passwords() {
+ require("passwords").search({
+ onComplete: function onComplete(credentials) {
+ credentials.forEach(function(credential) {
+ console.log(credential.username);
+ console.log(credential.password);
+ });
+ }
+ });
+ }
+
+If you pass it a single property, only credentials matching that property are
+returned:
+
+ function show_passwords_for_joe() {
+ require("passwords").search({
+ username: "joe",
+ onComplete: function onComplete(credentials) {
+ credentials.forEach(function(credential) {
+ console.log(credential.username);
+ console.log(credential.password);
+ });
+ }
+ });
+ }
+
+If you pass more than one property, returned credentials must match all of
+them:
+
+ function show_google_password_for_joe() {
+ require("passwords").search({
+ username: "joe",
+ url: "https://www.google.com",
+ onComplete: function onComplete(credentials) {
+ credentials.forEach(function(credential) {
+ console.log(credential.username);
+ console.log(credential.password);
+ });
+ }
+ });
+ }
+
+To retrieve only credentials associated with your add-on, use the `url`
+property, initialized from `self.uri`:
+
+ function show_my_addon_passwords() {
+ require("passwords").search({
+ url: require("self").uri,
+ onComplete: function onComplete(credentials) {
+ credentials.forEach(function(credential) {
+ console.log(credential.username);
+ console.log(credential.password);
+ });
+ }
+ });
+ }
+
+@param options {object}
+The `options` object may contain any credential properties. It is used to
+restrict the set of credentials returned by the `search` function.
+
+See "Credentials" above for details on what these properties should be.
+
+Additionally, `options` must contain a function assigned to its `onComplete`
+property: this is called when the function completes and is passed the set of
+credentials retrieved.
+
+`options` may contain a function assigned to its `onError` property, which is
+called if the function encounters an error. `onError` is passed the error as an
+[nsIException](https://developer.mozilla.org/en/nsIException) object.
+
+@prop [username] {string}
+The username for the credential.
+
+@prop [password] {string}
+The password for the credential.
+
+@prop [url] {string}
+The URL associated with the credential.
+
+@prop [formSubmitURL] {string}
+The URL an HTML form credential is submitted to.
+
+@prop [realm] {string}
+For HTTP Authentication credentials, the realm for which the credential was
+requested. For add-on credentials, a name for the credential.
+
+@prop [usernameField] {string}
+The value of the `name` attribute for the user name input field in a form.
+
+@prop [passwordField] {string}
+The value of the `name` attribute for the password input field in a form.
+
+@prop onComplete {function}
+The callback function that is called once the function completes successfully.
+It is passed all the matching credentials as a list. This is the only
+mandatory option.
+
+@prop [onError] {function}
+The callback function that is called if the function failed. The
+callback is passed an `error` containing a reason of a failure: this is an
+[nsIException](https://developer.mozilla.org/en/nsIException) object.
+
+</api>
+
+<api name="store">
+@function
+
+This function is used to store a credential in the Password Manager.
+
+It takes an `options` object as an argument: this contains all the properties
+for the new credential.
+
+As different sorts of credentials contain different properties, the
+appropriate options differ depending on the sort of credential being stored.
+
+To store an add-on credential:
+
+ require("passwords").store({
+ realm: "User Registration",
+ username: "joe",
+ password: "SeCrEt123",
+ });
+
+To store an HTML form credential:
+
+ require("passwords").store({
+ url: "http://www.example.com",
+ formSubmitURL: "http://login.example.com",
+ username: "joe",
+ usernameField: "uname",
+ password: "SeCrEt123",
+ passwordField: "pword"
+ });
+
+To store an HTTP Authentication credential:
+
+ require("passwords").store({
+ url: "http://www.example.com",
+ realm: "ExampleCo Login",
+ username: "joe",
+ password: "SeCrEt123",
+ });
+
+See "Credentials" above for more details on how to set these properties.
+
+The options parameter may also include `onComplete` and `onError`
+callback functions, which are called when the function has completed
+successfully and when it encounters an error, respectively. These options
+are both optional.
+
+@param options {object}
+An object containing the properties of the credential to be stored, and
+optional `onComplete` and `onError` callback functions.
+
+@prop username {string}
+The username for the credential.
+
+@prop password {string}
+The password for the credential.
+
+@prop [url] {string}
+The URL to which the credential applies. Omitted for add-on
+credentials.
+
+@prop [formSubmitURL] {string}
+The URL a form-based credential was submitted to. Omitted for add-on
+credentials and HTTP Authentication credentials.
+
+@prop [realm] {string}
+For HTTP Authentication credentials, the realm for which the credential was
+requested. For add-on credentials, a name for the credential.
+
+@prop [usernameField] {string}
+The value of the `name` attribute for the username input in a form.
+Omitted for add-on credentials and HTTP Authentication credentials.
+
+@prop [passwordField] {string}
+The value of the `name` attribute for the password input in a form.
+Omitted for add-on credentials and HTTP Authentication credentials.
+
+@prop [onComplete] {function}
+The callback function that is called once the function completes successfully.
+
+@prop [onError] {function}
+The callback function that is called if the function failed. The
+callback is passed an `error` argument: this is an
+[nsIException](https://developer.mozilla.org/en/nsIException) object.
+
+</api>
+
+<api name="remove">
+@function
+
+Removes a stored credential. You supply it all the properties of the credential
+to remove, along with optional `onComplete` and `onError` callbacks.
+
+Because you must supply all the credential's properties, it may be convenient
+to call `search` first, and use its output as the input to `remove`. For
+example, to remove all of joe's stored credentials:
+
+ require("passwords").search({
+ username: "joe",
+ onComplete: function onComplete(credentials) {
+ credentials.forEach(require("passwords").remove);
+ })
+ });
+
+To change an existing credential just call `store` after `remove` succeeds:
+
+ require("passwords").remove({
+ realm: "User Registration",
+ username: "joe",
+ password: "SeCrEt123"
+ onComplete: function onComplete() {
+ require("passwords").store({
+ realm: "User Registration",
+ username: "joe",
+ password: "{{new password}}"
+ })
+ }
+ });
+
+@param options {object}
+
+An object containing all the properties of the credential to be removed,
+and optional `onComplete` and `onError` callback functions.
+
+@prop username {string}
+The username for the credential.
+
+@prop password {string}
+The password for the credential.
+
+@prop [url] {string}
+The URL to which the credential applies. Omitted for add-on
+credentials.
+
+@prop [formSubmitURL] {string}
+The URL a form-based credential was submitted to. Omitted for add-on
+credentials and HTTP Authentication credentials.
+
+@prop [realm] {string}
+For HTTP Authentication credentials, the realm for which the credential was
+requested. For add-on credentials, a name for the credential.
+
+@prop [usernameField] {string}
+The value of the `name` attribute for the username input in a form.
+Omitted for add-on credentials and HTTP Authentication credentials.
+
+@prop [passwordField] {string}
+The value of the `name` attribute for the password input in a form.
+Omitted for add-on credentials and HTTP Authentication credentials.
+
+@prop [onComplete] {function}
+The callback function that is called once the function has completed
+successfully.
+
+@prop [onError] {function}
+The callback function that is called if the function failed. The
+callback is passed an `error` argument: this is an
+[nsIException](https://developer.mozilla.org/en/nsIException) object.
+
+</api>
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/docs/private-browsing.md b/tools/addon-sdk-1.7/packages/addon-kit/docs/private-browsing.md
new file mode 100644
index 0000000..e553357
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/docs/private-browsing.md
@@ -0,0 +1,50 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Paul O'Shannessy [paul@oshannessy.com] -->
+<!-- edited by Noelle Murata [fiveinchpixie@gmail.com] -->
+<!-- contributed by Irakli Gozalishvili [gozala@mozilla.com] -->
+
+The `private-browsing` module allows you to access Firefox's private browsing
+mode, detecting if it is active and when its state changes.
+
+This module is available in all applications. However, only Firefox will ever
+transition into or out of private browsing mode. For all other applications,
+`pb.isActive` will always be `false`, and none of the events will be emitted.
+
+<api name="isActive">
+@property {boolean}
+ This read-only boolean is true if private browsing mode is turned on.
+</api>
+
+<api name="activate">
+@function
+ Turns on private browsing mode.
+</api>
+
+<api name="deactivate">
+@function
+ Turns off private browsing mode.
+</api>
+
+<api name="start">
+@event
+Emitted immediately after the browser enters private browsing mode.
+
+ var pb = require("private-browsing");
+ pb.on("start", function() {
+ // Do something when the browser starts private browsing mode.
+ });
+
+</api>
+
+<api name="stop">
+@event
+Emitted immediately after the browser exits private browsing mode.
+
+ var pb = require("private-browsing");
+ pb.on("stop", function() {
+ // Do something when the browser stops private browsing mode.
+ });
+</api> \ No newline at end of file
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/docs/request.md b/tools/addon-sdk-1.7/packages/addon-kit/docs/request.md
new file mode 100644
index 0000000..af37ecf
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/docs/request.md
@@ -0,0 +1,203 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+The `request` module lets you make simple yet powerful network requests.
+
+<api name="Request">
+@class
+The `Request` object is used to make `GET`, `POST` or `PUT` network requests.
+It is constructed with a URL to which the request is sent. Optionally the user
+may specify a collection of headers and content to send alongside the request
+and a callback which will be executed once the request completes.
+
+Once a `Request` object has been created a `GET` request can be executed by
+calling its `get()` method, a `POST` request by calling its `post()` method,
+or a `PUT` request by calling its `put()` method.
+
+When the server completes the request, the `Request` object emits a "complete"
+event. Registered event listeners are passed a `Response` object.
+
+Each `Request` object is designed to be used once. Once `GET`, `POST` or `PUT`
+are called, attempting to call either will throw an error.
+
+Since the request is not being made by any particular website, requests made
+here are not subject to the same-domain restriction that requests made in web
+pages are subject to.
+
+With the exception of `response`, all of a `Request` object's properties
+correspond with the options in the constructor. Each can be set by simply
+performing an assignment. However, keep in mind that the same validation rules
+that apply to `options` in the constructor will apply during assignment. Thus,
+each can throw if given an invalid value.
+
+The example below shows how to use Request to get the most recent public tweet.
+
+ var Request = require("request").Request;
+ var latestTweetRequest = Request({
+ url: "http://api.twitter.com/1/statuses/public_timeline.json",
+ onComplete: function (response) {
+ var tweet = response.json[0];
+ console.log("User: " + tweet.user.screen_name);
+ console.log("Tweet: " + tweet.text);
+ }
+ });
+
+ // Be a good consumer and check for rate limiting before doing more.
+ Request({
+ url: "http://api.twitter.com/1/account/rate_limit_status.json",
+ onComplete: function (response) {
+ if (response.json.remaining_hits) {
+ latestTweetRequest.get();
+ } else {
+ console.log("You have been rate limited!");
+ }
+ }
+ }).get();
+
+<api name="Request">
+@constructor
+This constructor creates a request object that can be used to make network
+requests. The constructor takes a single parameter `options` which is used to
+set several properties on the resulting `Request`.
+@param options {object}
+ @prop url {string}
+ This is the url to which the request will be made.
+
+ @prop [onComplete] {function}
+ This function will be called when the request has received a response (or in
+ terms of XHR, when `readyState == 4`). The function is passed a `Response`
+ object.
+
+ @prop [headers] {object}
+ An unordered collection of name/value pairs representing headers to send
+ with the request.
+
+ @prop [content] {string,object}
+ The content to send to the server. If `content` is a string, it should be
+ URL-encoded (use `encodeURIComponent`). If `content` is an object, it
+ should be a collection of name/value pairs. Nested objects & arrays should
+ encode safely.
+
+ For `GET` requests, the query string (`content`) will be appended to the
+ URL. For `POST` and `PUT` requests, the query string will be sent as the body
+ of the request.
+
+ @prop [contentType] {string}
+ The type of content to send to the server. This explicitly sets the
+ `Content-Type` header. The default value is `application/x-www-form-urlencoded`.
+
+ @prop [overrideMimeType] {string}
+ Use this string to override the MIME type returned by the server in the
+ response's Content-Type header. You can use this to treat the content as a
+ different MIME type, or to force text to be interpreted using a specific
+ character.
+
+ For example, if you're retrieving text content which was encoded as
+ ISO-8859-1 (Latin 1), it will be given a content type of "utf-8" and
+ certain characters will not display correctly. To force the response to
+ be interpreted as Latin-1, use `overrideMimeType`:
+
+ var Request = require("request").Request;
+ var quijote = Request({
+ url: "http://www.latin1files.org/quijote.txt",
+ overrideMimeType: "text/plain; charset=latin1",
+ onComplete: function (response) {
+ console.log(response.text);
+ }
+ });
+
+ quijote.get();
+
+</api>
+
+<api name="url">
+@property {string}
+</api>
+
+<api name="headers">
+@property {object}
+</api>
+
+<api name="content">
+@property {string,object}
+</api>
+
+<api name="contentType">
+@property {string}
+</api>
+
+<api name="response">
+@property {Response}
+</api>
+
+<api name="get">
+@method
+Make a `GET` request.
+@returns {Request}
+</api>
+
+<api name="post">
+@method
+Make a `POST` request.
+@returns {Request}
+</api>
+
+<api name="put">
+@method
+Make a `PUT` request.
+@returns {Request}
+</api>
+
+<api name="complete">
+@event
+The `Request` object emits this event when the request has completed and a
+response has been received.
+
+@argument {Response}
+Listener functions are passed the response to the request as a `Response` object.
+</api>
+
+</api>
+
+
+<api name="Response">
+@class
+The Response object contains the response to a network request issued using a
+`Request` object. It is returned by the `get()`, `post()` or `put()` method of a
+`Request` object.
+
+All members of a `Response` object are read-only.
+<api name="text">
+@property {string}
+The content of the response as plain text.
+</api>
+
+<api name="json">
+@property {object}
+The content of the response as a JavaScript object. The value will be `null`
+if the document cannot be processed by `JSON.parse`.
+</api>
+
+<api name="status">
+@property {string}
+The HTTP response status code (e.g. *200*).
+</api>
+
+<api name="statusText">
+@property {string}
+The HTTP response status line (e.g. *OK*).
+</api>
+
+<api name="headers">
+@property {object}
+The HTTP response headers represented as key/value pairs.
+
+To print all the headers you can do something like this:
+
+ for (var headerName in response.headers) {
+ console.log(headerName + " : " + response.headers[headerName]);
+ }
+
+</api>
+</api>
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/docs/selection.md b/tools/addon-sdk-1.7/packages/addon-kit/docs/selection.md
new file mode 100644
index 0000000..f2d4ca5
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/docs/selection.md
@@ -0,0 +1,90 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Eric H. Jung [eric.jung@yahoo.com] -->
+<!-- contributed by Irakli Gozalishvili [gozala@mozilla.com] -->
+
+The `selection` module provides a means to get and set text and HTML selections
+in the current Firefox page. It can also observe new selections.
+
+Registering for Selection Notifications
+---------------------------------------
+
+To be notified when the user makes a selection, register a listener for the
+"select" event. Each listener will be called after a selection is made.
+
+ function myListener() {
+ console.log("A selection has been made.");
+ }
+ var selection = require("selection");
+ selection.on('select', myListener);
+
+ // You can remove listeners too.
+ selection.removeListener('select', myListener);
+
+Iterating Over Discontiguous Selections
+---------------------------------------
+
+Discontiguous selections can be accessed by iterating over the `selection`
+module itself. Each iteration yields a `Selection` object from which `text`,
+`html`, and `isContiguous` properties can be accessed.
+
+
+Examples
+--------
+
+Log the current contiguous selection as text:
+
+ var selection = require("selection");
+ if (selection.text)
+ console.log(selection.text);
+
+Log the current discontiguous selections as HTML:
+
+ var selection = require("selection");
+ if (!selection.isContiguous) {
+ for (var subselection in selection) {
+ console.log(subselection.html);
+ }
+ }
+
+Surround HTML selections with delimiters:
+
+ var selection = require("selection");
+ selection.on('select', function () {
+ selection.html = "\\\" + selection.html + "///";
+ });
+
+<api name="text">
+@property {string}
+ Gets or sets the current selection as plain text. Setting the selection
+ removes all current selections, inserts the specified text at the location of
+ the first selection, and selects the new text. Getting the selection when
+ there is no current selection returns `null`. Setting the selection when there
+ is no current selection throws an exception. Getting the selection when
+ `isContiguous` is `true` returns the text of the first selection.
+</api>
+
+<api name="html">
+@property {string}
+ Gets or sets the current selection as HTML. Setting the selection removes all
+ current selections, inserts the specified text at the location of the first
+ selection, and selects the new text. Getting the selection when there is no
+ current selection returns `null`. Setting the selection when there is no
+ current selection throws an exception. Getting the selection when
+ `isContiguous` is `true` returns the text of the first selection.
+</api>
+
+<api name="isContiguous">
+@property {boolean}
+ `true` if the current selection is a single, contiguous selection, and `false`
+ if there are two or more discrete selections, each of which may or may not be
+ spatially adjacent. (Discontiguous selections can be created by the user with
+ Ctrl+click-and-drag.)
+</api>
+
+<api name="select">
+@event
+ This event is emitted whenever the user makes a new selection in a page.
+</api>
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/docs/self.md b/tools/addon-sdk-1.7/packages/addon-kit/docs/self.md
new file mode 100644
index 0000000..8ccdb01
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/docs/self.md
@@ -0,0 +1,79 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- edited by Erik Vold [erikvvold@gmail.com] -->
+
+The `self` module provides access to data that is bundled with the add-on
+as a whole. It also provides access to the
+[Program ID](dev-guide/guides/program-id.html), a value which is
+unique for each add-on.
+
+Note that the `self` module is completely different from the global `self`
+object accessible to content scripts, which is used by a content script to
+[communicate with the add-on code](dev-guide/guides/content-scripts/using-port.html).
+
+<api name="id">
+@property {string}
+This property is a printable string that is unique for each add-on. It comes
+from the `id` property set in the `package.json` file in the main package
+(i.e. the package in which you run `cfx xpi`). While not generally of use to
+add-on code directly, it can be used by internal API code to index local
+storage and other resources that are associated with a particular add-on.
+Eventually, this ID will be unspoofable (see
+[JEP 118](https://wiki.mozilla.org/Labs/Jetpack/Reboot/JEP/118) for details).
+</api>
+
+<api name="name">
+@property {string}
+This property contains the add-on's short name. It comes from the `name`
+property in the main package's `package.json` file.
+</api>
+
+<api name="version">
+@property {string}
+This property contains the add-on's version string. It comes from the
+`version` property set in the `package.json` file in the main package.
+</api>
+
+<api name="data">
+@property {object}
+The `data` object is used to access data that was bundled with the add-on.
+This data lives in the main package's `data/` directory, immediately below
+the `package.json` file. All files in this directory will be copied into the
+XPI and made available through the `data` object.
+
+The [Package Specification](dev-guide/package-spec.html)
+section explains the `package.json` file.
+
+<api name="data.load">
+@method
+The `data.load(NAME)` method returns the contents of an embedded data file,
+as a string. It is most useful for data that will be modified or parsed in
+some way, such as JSON, XML, plain text, or perhaps an HTML template. For
+data that can be displayed directly in a content frame, use `data.url(NAME)`.
+@param name {string} The filename to be read, relative to the
+ package's `data` directory. Each package that uses the `self` module
+ will see its own `data` directory.
+@returns {string}
+</api>
+
+<api name="data.url">
+@method
+The `data.url(NAME)` method returns a url that points at an embedded
+data file. It is most useful for data that can be displayed directly in a
+content frame. The url can be passed to a content frame constructor, such
+as the Panel:
+
+ var self = require("self");
+ var myPanel = require("panel").Panel({
+ contentURL: self.data.url("my-panel-content.html")
+ });
+ myPanel.show();
+
+@param name {string} The filename to be read, relative to the
+ package's `data` directory. Each package that uses the `self` module
+ will see its own `data` directory.
+@returns {String}
+</api>
+</api>
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/docs/simple-prefs.md b/tools/addon-sdk-1.7/packages/addon-kit/docs/simple-prefs.md
new file mode 100644
index 0000000..b3cd076
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/docs/simple-prefs.md
@@ -0,0 +1,75 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Erik Vold [erikvvold@gmail.com] -->
+
+#### *Experimental*
+
+The `simple-prefs` module lets you easily and persistently store preferences
+across application restarts, which can be configured by users in the
+Add-ons Manager.
+
+Introduction
+------------
+
+With the simple preferences module you can store booleans, integers, and string
+values.
+
+
+Inline Options & Default Values
+-------------------------------
+
+In order to have a `options.xul` (for inline options) generated, or a
+`defaults/preferences/prefs.js` for default preferences, you will need to
+define the preferences in your `package.json`, like so:
+
+ {
+ "fullName": "Example Add-on",
+ ...
+ "preferences": [{
+ "name": "somePreference",
+ "title": "Some preference title",
+ "description": "Some short description for the preference",
+ "type": "string",
+ "value": "this is the default string value"
+ }]
+ }
+
+
+<api name="prefs">
+@property {object}
+ *experimental* A persistent object private to your add-on. Properties with boolean,
+ number, and string values will be persisted in the Mozilla preferences system.
+</api>
+
+
+<api name="on">
+@function
+ *experimental* Registers an event `listener` that will be called when a preference is changed.
+
+**Example:**
+
+ function onPrefChange(prefName) {
+ console.log("The " + prefName + " preference changed.");
+ }
+ require("simple-prefs").on("somePreference", onPrefChange);
+ require("simple-prefs").on("someOtherPreference", onPrefChange);
+
+
+@param prefName {String}
+ The name of the preference to watch for changes.
+@param listener {Function}
+ The listener function that processes the event.
+</api>
+
+<api name="removeListener">
+@function
+ *experimental* Unregisters an event `listener` for the specified preference.
+
+@param prefName {String}
+ The name of the preference to watch for changes.
+@param listener {Function}
+ The listener function that processes the event.
+</api>
+
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/docs/simple-storage.md b/tools/addon-sdk-1.7/packages/addon-kit/docs/simple-storage.md
new file mode 100644
index 0000000..bbe9cbe
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/docs/simple-storage.md
@@ -0,0 +1,220 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+The `simple-storage` module lets you easily and persistently store data across
+Firefox restarts. If you're familiar with [DOM storage][] on the Web, it's
+kind of like that, but for add-ons.
+
+[DOM storage]: https://developer.mozilla.org/en/DOM/Storage
+
+The simple storage module exports an object called `storage` that is persistent
+and private to your add-on. It's a normal JavaScript object, and you can treat
+it as you would any other.
+
+To store a value, just assign it to a property on `storage`:
+
+ var ss = require("simple-storage");
+ ss.storage.myArray = [1, 1, 2, 3, 5, 8, 13];
+ ss.storage.myBoolean = true;
+ ss.storage.myNull = null;
+ ss.storage.myNumber = 3.1337;
+ ss.storage.myObject = { a: "foo", b: { c: true }, d: null };
+ ss.storage.myString = "O frabjous day!";
+
+You can store array, boolean, number, object, null, and string values.
+If you'd like to store other types of values, you'll first have to convert
+them to strings or another one of these types.
+
+Be careful to set properties on the `storage` object and not the module itself:
+
+ // This is no good!
+ var ss = require("simple-storage");
+ ss.foo = "I will not be saved! :(";
+
+Simple Storage and "cfx run"
+----------------------------
+The simple storage module stores its data in your profile.
+Because `cfx run` by default uses a fresh profile each time it runs,
+simple storage won't work with add-ons executed using `cfx run` - that
+is, stored data will not persist from one run to the next.
+
+The easiest solution to this problem is to use the
+[`--profiledir` option to `cfx run`](dev-guide/cfx-tool.html#profiledir).
+
+If you use this method, you must end your debugging session by
+quitting Firefox normally, not by cancelling the shell command.
+If you don't close Firefox normally, then simple storage will
+not be notified that the session is finished, and will not write
+your data to the backing store.
+
+Constructing Arrays
+-------------------
+Be careful to construct array objects conditionally in your code, or you may
+zero them each time the construction code runs. For example, this add-on
+tries to store the URLs of pages the user visits:
+
+<pre><code>
+var ss = require("simple-storage");
+ss.storage.pages = [];
+
+require("tabs").on("ready", function(tab) {
+ ss.storage.pages.push(tab.url);
+});
+
+var widget = require("widget").Widget({
+ id: "log_history",
+ label: "Log History",
+ width: 30,
+ content: "Log",
+ onClick: function() {
+ console.log(ss.storage.pages);
+ }
+});
+</code></pre>
+
+But this isn't going to work, because it empties the array each time the
+add-on runs (for example, each time Firefox is started). Line 2 needs
+to be made conditional, so the array is only constructed if it does
+not already exist:
+
+<pre><code>
+if (!ss.storage.pages)
+ ss.storage.pages = [];
+</code></pre>
+
+Deleting Data
+-------------
+You can delete properties using the `delete` operator. Here's an add-on
+that adds three widgets to write, read, and delete a value:
+
+<pre><code>
+var widgets = require("widget");
+var ss = require("simple-storage");
+
+var widget = widgets.Widget({
+ id: "write",
+ label: "Write",
+ width: 50,
+ content: "Write",
+ onClick: function() {
+ ss.storage.value = 1;
+ console.log("Setting value");
+ }
+});
+
+var widget = widgets.Widget({
+ id: "read",
+ label: "Read",
+ width: 50,
+ content: "Read",
+ onClick: function() {
+ console.log(ss.storage.value);
+ }
+});
+
+var widget = widgets.Widget({
+ id: "delete",
+ label: "Delete",
+ width: 50,
+ content: "Delete",
+ onClick: function() {
+ delete ss.storage.value;
+ console.log("Deleting value");
+ }
+});
+</pre></code>
+
+If you run it, you'll see that after clicking "Read" after clicking
+"Delete" gives you the expected output:
+
+<pre>
+info: undefined
+</pre>
+
+Quotas
+------
+The simple storage available to your add-on is limited. Currently this limit is
+about five megabytes (5,242,880 bytes). You can choose to be notified when you
+go over quota, and you should respond by reducing the amount of data in storage.
+If the user quits the application while you are over quota, all data stored
+since the last time you were under quota will not be persisted. You should not
+let that happen.
+
+To listen for quota notifications, register a listener for the `"OverQuota"`
+event. It will be called when your storage goes over quota.
+
+ function myOnOverQuotaListener() {
+ console.log("Uh oh.");
+ }
+ ss.on("OverQuota", myOnOverQuotaListener);
+
+Listeners can also be removed:
+
+ ss.removeListener("OverQuota", myOnOverQuotaListener);
+
+To find out how much of your quota you're using, check the module's `quotaUsage`
+property. It indicates the percentage of quota your storage occupies. If
+you're within your quota, it's a number from 0 to 1, inclusive, and if you're
+over, it's a number greater than 1.
+
+Therefore, when you're notified that you're over quota, respond by removing
+storage until your `quotaUsage` is less than or equal to 1. Which particular
+data you remove is up to you. For example:
+
+ ss.storage.myList = [ /* some long array */ ];
+ ss.on("OverQuota", function () {
+ while (ss.quotaUsage > 1)
+ ss.storage.myList.pop();
+ });
+
+
+Private Browsing
+----------------
+If your storage is related to your users' Web history, personal information, or
+other sensitive data, your add-on should respect [private browsing mode][SUMO].
+While private browsing mode is active, you should not store any sensitive data.
+
+Because any kind of data can be placed into simple storage, support for private
+browsing is not built into the module. Instead, use the
+[`private-browsing`](packages/addon-kit/private-browsing.html) module to
+check private browsing status and respond accordingly.
+
+For example, the URLs your users visit should not be stored during private
+browsing. If your add-on records the URL of the selected tab, here's how you
+might handle that:
+
+ ss.storage.history = [];
+ var privateBrowsing = require("private-browsing");
+ if (!privateBrowsing.isActive) {
+ var url = getSelectedTabURL();
+ ss.storage.history.push(url);
+ }
+
+For more information on supporting private browsing, see its [Mozilla Developer
+Network documentation][MDN]. While that page does not apply specifically to
+SDK-based add-ons (and its code samples don't apply at all), you should follow
+its guidance on best practices and policies.
+
+[SUMO]: http://support.mozilla.com/en-US/kb/Private+Browsing
+[MDN]: https://developer.mozilla.org/En/Supporting_private_browsing_mode
+
+
+<api name="storage">
+@property {object}
+ A persistent object private to your add-on. Properties with array, boolean,
+ number, object, null, and string values will be persisted.
+</api>
+
+<api name="quotaUsage">
+@property {number}
+ A number in the range [0, Infinity) that indicates the percentage of quota
+ occupied by storage. A value in the range [0, 1] indicates that the storage
+ is within quota. A value greater than 1 indicates that the storage exceeds
+ quota.
+</api>
+
+<api name="OverQuota">
+@event
+The module emits this event when your add-on's storage goes over its quota.
+</api>
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/docs/tabs.md b/tools/addon-sdk-1.7/packages/addon-kit/docs/tabs.md
new file mode 100644
index 0000000..f1e44df
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/docs/tabs.md
@@ -0,0 +1,385 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Dietrich Ayala [dietrich@mozilla.com] -->
+<!-- edited by Noelle Murata [fiveinchpixie@gmail.com] -->
+
+The `tabs` module provides easy access to tabs and tab-related events.
+
+The module itself can be used like a basic list of all opened
+tabs across all windows. In particular, you can enumerate it:
+
+ var tabs = require('tabs');
+ for each (var tab in tabs)
+ console.log(tab.title);
+
+You can also access individual tabs by index:
+
+ var tabs = require('tabs');
+
+ tabs.on('ready', function () {
+ console.log('first: ' + tabs[0].title);
+ console.log('last: ' + tabs[tabs.length-1].title);
+ });
+
+You can open a new tab, specifying various properties including location:
+
+ var tabs = require("tabs");
+ tabs.open("http://www.example.com");
+
+You can register event listeners to be notified when tabs open, close, finish
+loading DOM content, or are made active or inactive:
+
+ var tabs = require("tabs");
+
+ // Listen for tab openings.
+ tabs.on('open', function onOpen(tab) {
+ myOpenTabs.push(tab);
+ });
+
+ // Listen for tab content loads.
+ tabs.on('ready', function(tab) {
+ console.log('tab is loaded', tab.title, tab.url)
+ });
+
+You can get and set various properties of tabs (but note that properties
+ relating to the tab's content, such as the URL, will not contain valid
+values until after the tab's `ready` event fires). By setting the `url`
+property you can load a new page in the tab:
+
+ var tabs = require("tabs");
+ tabs.on('activate', function(tab) {
+ tab.url = "http://www.example.com";
+ });
+
+You can attach a [content script](dev-guide/guides/content-scripts/index.html)
+to the page hosted in a tab, and use that to access and manipulate the page's
+content:
+
+ var tabs = require("tabs");
+
+ tabs.on('activate', function(tab) {
+ tab.attach({
+ contentScript: 'self.postMessage(document.body.innerHTML);',
+ onMessage: function (message) {
+ console.log(message);
+ }
+ });
+ });
+
+<api name="activeTab">
+@property {Tab}
+
+The currently active tab in the active window. This property is read-only. To
+activate a `Tab` object, call its `activate` method.
+
+**Example**
+
+ // Get the active tab's title.
+ var tabs = require("tabs");
+ console.log("title of active tab is " + tabs.activeTab.title);
+</api>
+
+<api name="length">
+@property {number}
+The number of open tabs across all windows.
+</api>
+
+<api name="open">
+@function
+Opens a new tab. The new tab will open in the active window or in a new window,
+depending on the `inNewWindow` option.
+
+**Example**
+
+ var tabs = require("tabs");
+
+ // Open a new tab on active window and make tab active.
+ tabs.open("http://www.mysite.com");
+
+ // Open a new tab in a new window and make it active.
+ tabs.open({
+ url: "http://www.mysite.com",
+ inNewWindow: true
+ });
+
+ // Open a new tab on active window in the background.
+ tabs.open({
+ url: "http://www.mysite.com",
+ inBackground: true
+ });
+
+ // Open a new tab as an app tab and do something once it's open.
+ tabs.open({
+ url: "http://www.mysite.com",
+ isPinned: true,
+ onOpen: function onOpen(tab) {
+ // do stuff like listen for content
+ // loading.
+ }
+ });
+
+@param options {object}
+An object containing configurable options for how and where the tab will be
+opened, as well as a listeners for the tab events.
+
+If the only option being used is `url`, then a bare string URL can be passed to
+`open` instead of adding at a property of the `options` object.
+
+@prop [url] {string}
+String URL to be opened in the new tab.
+This is a required property.
+
+@prop [inNewWindow] {boolean}
+If present and true, a new browser window will be opened and the URL will be
+opened in the first tab in that window. This is an optional property.
+
+@prop [inBackground] {boolean}
+If present and true, the new tab will be opened to the right of the active tab
+and will not be active. This is an optional property.
+
+@prop [isPinned] {boolean}
+If present and true, then the new tab will be pinned as an
+[app tab](http://support.mozilla.com/en-US/kb/what-are-app-tabs).
+
+@prop [onOpen] {function}
+A callback function that will be registered for 'open' event.
+This is an optional property.
+@prop [onClose] {function}
+A callback function that will be registered for 'close' event.
+This is an optional property.
+@prop [onReady] {function}
+A callback function that will be registered for 'ready' event.
+This is an optional property.
+@prop [onActivate] {function}
+A callback function that will be registered for 'activate' event.
+This is an optional property.
+@prop [onDeactivate] {function}
+A callback function that will be registered for 'deactivate' event.
+This is an optional property.
+</api>
+
+<api name="Tab">
+@class
+A `Tab` instance represents a single open tab. It contains various tab
+properties, several methods for manipulation, as well as per-tab event
+registration.
+
+Tabs emit all the events described in the Events section. Listeners are
+passed the `Tab` object that triggered the event.
+
+<api name="title">
+@property {string}
+The title of the page currently loaded in the tab.
+This property can be set to change the tab title.
+</api>
+
+<api name="url">
+@property {String}
+The URL of the page currently loaded in the tab.
+This property can be set to load a different URL in the tab.
+</api>
+
+<api name="favicon">
+@property {string}
+The URL of the favicon for the page currently loaded in the tab.
+This property is read-only.
+</api>
+
+<api name="index">
+@property {integer}
+The index of the tab relative to other tabs in the application window.
+This property can be set to change its relative position.
+</api>
+
+<api name="isPinned">
+@property {boolean}
+Whether or not tab is pinned as an [app tab][].
+This property is read-only.
+[app tab]:http://support.mozilla.com/en-US/kb/what-are-app-tabs
+</api>
+
+<api name="getThumbnail">
+@property {method}
+Returns thumbnail data URI of the page currently loaded in this tab.
+</api>
+
+<api name="pin">
+@method
+Pins this tab as an [app tab][].
+[app tab]:http://support.mozilla.com/en-US/kb/what-are-app-tabs
+</api>
+
+<api name="unpin">
+@method
+Unpins this tab.
+</api>
+
+<api name="close">
+@method
+Closes this tab.
+
+@param [callback] {function}
+A function to be called when the tab finishes its closing process.
+This is an optional argument.
+</api>
+
+<api name="reload">
+@method
+Reloads this tab.
+</api>
+
+<api name="activate">
+@method
+Makes this tab active, which will bring this tab to the foreground.
+</api>
+
+<api name="attach">
+@method
+ Create a page mod and attach it to the document in the tab.
+
+**Example**
+
+ var tabs = require("tabs");
+
+ tabs.on('ready', function(tab) {
+ tab.attach({
+ contentScript:
+ 'document.body.style.border = "5px solid red";'
+ });
+ });
+
+@param options {object}
+ Options for the page mod, with the following keys:
+
+@prop [contentScriptFile] {string,array}
+ The local file URLs of content scripts to load. Content scripts specified
+ by this option are loaded *before* those specified by the `contentScript`
+ option. Optional.
+@prop [contentScript] {string,array}
+ The texts of content scripts to load. Content scripts specified by this
+ option are loaded *after* those specified by the `contentScriptFile` option.
+ Optional.
+@prop [onMessage] {function}
+ A function called when the page mod receives a message from content scripts.
+ Listeners are passed a single argument, the message posted from the
+ content script. Optional.
+
+@returns {Worker}
+ See [Content Scripts guide](dev-guide/guides/content-scripts/index.html)
+ to learn how to use the `Worker` object to communicate with the content script.
+
+</api>
+
+<api name="close">
+@event
+
+This event is emitted when the tab is closed. It's also emitted when the
+tab's window is closed.
+
+@argument {Tab}
+Listeners are passed the tab object.
+</api>
+
+<api name="ready">
+@event
+
+This event is emitted when the DOM for the tab's content is ready. It is
+equivalent to the `DOMContentLoaded` event for the given content page.
+
+A single tab will emit this event every time the DOM is loaded: so it will be
+emitted again if the tab's location changes or the content is reloaded.
+
+After this event has been emitted, all properties relating to the tab's
+content can be used.
+
+@argument {Tab}
+Listeners are passed the tab object.
+</api>
+
+<api name="activate">
+@event
+
+This event is emitted when the tab is made active.
+
+@argument {Tab}
+Listeners are passed the tab object.
+</api>
+
+<api name="deactivate">
+@event
+
+This event is emitted when the tab is made inactive.
+
+@argument {Tab}
+Listeners are passed the tab object.
+</api>
+
+</api>
+
+<api name="open">
+@event
+
+This event is emitted when a new tab is opened. This does not mean that
+the content has loaded, only that the browser tab itself is fully visible
+to the user.
+
+Properties relating to the tab's content (for example: `title`, `favicon`,
+and `url`) will not be correct at this point. If you need to access these
+properties, listen for the `ready` event:
+
+ var tabs = require("tabs");
+ tabs.on('open', function(tab){
+ tab.on('ready', function(tab){
+ console.log(tab.url);
+ });
+ });
+
+@argument {Tab}
+Listeners are passed the tab object that just opened.
+</api>
+
+<api name="close">
+@event
+
+This event is emitted when a tab is closed. When a window is closed
+this event will be emitted for each of the open tabs in that window.
+
+@argument {Tab}
+Listeners are passed the tab object that has closed.
+</api>
+
+<api name="ready">
+@event
+
+This event is emitted when the DOM for a tab's content is ready.
+It is equivalent to the `DOMContentLoaded` event for the given content page.
+
+A single tab will emit this event every time the DOM is loaded: so it will be
+emitted again if the tab's location changes or the content is reloaded.
+
+After this event has been emitted, all properties relating to the tab's
+content can be used.
+
+@argument {Tab}
+Listeners are passed the tab object that has loaded.
+</api>
+
+<api name="activate">
+@event
+
+This event is emitted when an inactive tab is made active.
+
+@argument {Tab}
+Listeners are passed the tab object that has become active.
+</api>
+
+<api name="deactivate">
+@event
+
+This event is emitted when the active tab is made inactive.
+
+@argument {Tab}
+Listeners are passed the tab object that has become inactive.
+</api>
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/docs/timers.md b/tools/addon-sdk-1.7/packages/addon-kit/docs/timers.md
new file mode 100644
index 0000000..192663a
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/docs/timers.md
@@ -0,0 +1,52 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Drew Willcoxon [adw@mozilla.com] -->
+<!-- contributed by Atul Varma [atul@mozilla.com] -->
+<!-- edited by Noelle Murata [fiveinchpixie@gmail.com] -->
+<!-- contributed by Irakli Gozalishvil [gozala@mozilla.com] -->
+
+The `timers` module provides access to web-like timing functionality.
+
+<api name="setTimeout">
+@function
+ Schedules `callback` to be called in `ms` milliseconds. Any additional
+ arguments are passed straight through to the callback.
+@returns {integer}
+ An ID that can later be used to undo this scheduling, if `callback` hasn't yet
+ been called.
+@param callback {function}
+ Function to be called.
+@param ms {integer}
+ Interval in milliseconds after which the function will be called.
+</api>
+
+<api name="clearTimeout">
+@function
+ Given an ID returned from `setTimeout()`, prevents the callback with the ID
+ from being called (if it hasn't yet been called).
+@param ID {integer}
+ An ID returned from `setTimeout()`.
+</api>
+
+<api name="setInterval">
+@function
+ Schedules `callback` to be called repeatedly every `ms` milliseconds. Any
+ additional arguments are passed straight through to the callback.
+@returns {integer}
+ An ID that can later be used to unschedule the callback.
+@param callback {function}
+ Function to be called.
+@param ms {integer}
+ Interval in milliseconds at which the function will be called.
+</api>
+
+<api name="clearInterval">
+@function
+ Given an ID returned from `setInterval()`, prevents the callback with the ID
+ from being called again.
+@param ID {integer}
+ An ID returned from `setInterval()`.
+</api>
+
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/docs/widget.md b/tools/addon-sdk-1.7/packages/addon-kit/docs/widget.md
new file mode 100644
index 0000000..815a085
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/docs/widget.md
@@ -0,0 +1,909 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Dietrich Ayala [dietrich@mozilla.com] -->
+<!-- contributed by Drew Willcoxon [adw@mozilla.com] -->
+<!-- edited by Noelle Murata [fiveinchpixie@gmail.com] -->
+
+The `widget` module provides your add-on with a simple user interface that is
+consistent with other add-ons and blends in well with Firefox.
+
+"Widgets" are small pieces of content that live in the Firefox 4
+[add-on bar](https://developer.mozilla.org/en/The_add-on_bar).
+They can be simple icons or complex web pages. You can attach
+[panels](packages/addon-kit/panel.html) to them that open when they're
+clicked, or you can define a custom click handler to perform some other action,
+like opening a web page in a tab.
+
+There are a few advantages to using widgets over an ad hoc user interface.
+First, your users will be accustomed to interacting with add-ons via widgets and
+the add-on bar. Second, it allows Firefox to treat your interface as a
+first-class citizen. For example, in the future Firefox may allow the user to
+drag widgets from the add-on bar to other toolbars. By exposing your interface
+as a widget, your add-on would automatically inherit such functionality.
+
+## Creation and Content ##
+
+Widgets can contain images or arbitrary web content. You can include this
+content inline as a string by using the `content` property, or point to content
+using a URL with the `contentURL` property.
+
+Upon creation, the widget is automatically added to the add-on bar.
+You can set the width of a widget, but the height is fixed so as to fit in the
+add-on bar. If the content is an image, it is automatically scaled to be 16x16
+pixels.
+
+For example, this widget contains an image, so it looks like a simple icon:
+
+ require("widget").Widget({
+ id: "mozilla-icon",
+ label: "My Mozilla Widget",
+ contentURL: "http://www.mozilla.org/favicon.ico"
+ });
+
+<img class="image-center" src="static-files/media/screenshots/widget-mozilla-icon.png"
+alt="Widget displaying an icon">
+
+You can make `contentURL` point to an HTML or icon file which you have
+packaged inside your add-on. Just save the file in your add-on's `data`
+directory, and reference it using the `data.url()` method of the
+[`self`](packages/addon-kit/self.html) module:
+
+ var data = require("self").data;
+
+ require("widget").Widget({
+ id: "my-widget",
+ label: "My Widget",
+ contentURL: data.url("my-content.html")
+ });
+
+This widget contains an entire web page:
+
+ require("widget").Widget({
+ id: "hello-display",
+ label: "My Hello Widget",
+ content: "Hello!",
+ width: 50
+ });
+
+<img class="image-center" src="static-files/media/screenshots/widget-hello-text.png"
+alt="Widget displaying 'hello'">
+
+Widgets are quite small by default, so this example used the `width` property to
+grow it in order to show all the text.
+
+## Scripting Widget Content ##
+
+To interact with the widget's content you need to load a separate script into
+the panel. In the SDK these scripts are called "content scripts" because
+they're explicitly used for interacting with web content.
+
+While content scripts can access the content they're attached to, they can't
+use the SDK's APIs. So implementing a complete solution usually means you
+have to send messages between the content script and the main add-on code.
+
+* You can specify one or more content scripts to load into the widget using the
+`contentScript` or `contentScriptFile` options to the
+[`Widget()` constructor](packages/addon-kit/widget.html#Widget(options)).
+
+* You can communicate with the script using either the
+[`postMessage()`](dev-guide/guides/content-scripts/using-postmessage.html)
+API or (preferably, usually) the
+[`port`](dev-guide/guides/content-scripts/using-port.html) API.
+
+<div class="warning">
+<p>Unless your content script is extremely simple and consists only of a
+static string, don't use <code>contentScript</code>: if you do, you may
+have problems getting your add-on approved on AMO.</p>
+<p>Instead, keep the script in a separate file and load it using
+<code>contentScriptFile</code>. This makes your code easier to maintain,
+secure, debug and review.</p>
+</div>
+
+<!-- The icons this widget displays, shown in the screenshot, is taken from the
+Glossy Buttons icon set created by IconEden which is made freely available for
+commercial and non-commercial use.
+See: http://www.iconeden.com/icon/category/free -->
+
+<img class="image-right" src="static-files/media/screenshots/widget-player-buttons.png"
+alt="Media player UI implemented as a widget">
+
+For example, suppose we want to implement a media player as an add-on.
+We could implement the main user interface as a widget hosting an array
+of buttons to control play/pause/stop functions.
+
+We can then use a content script to listen for clicks on those buttons.
+But because content scripts can't use the SDK's APIs, we'll want the
+content script to send messages to the main add-on code, which can then
+implement the media player functions using the SDK.
+
+The widget's content is specified using HTML like this:
+
+<pre class="brush: html">
+&lt;html&gt;
+ &lt;body&gt;
+ &lt;img src="play.png" id="play-button"&gt;
+ &lt;img src="pause.png" id="pause-button"&gt;
+ &lt;img src="stop.png" id="stop-button"&gt;
+ &lt;/body&gt;
+&lt;/html&gt;
+</pre>
+
+We just include three icons, and assign an ID to each one. This HTML file,
+and the icon files it references, are saved in the add-on's `data`
+directory.
+
+Next, we write a content script that listens for click events on each icon
+and sends the corresponding message to the main add-on code:
+
+ var play_button = document.getElementById("play-button");
+ play_button.onclick = function() {
+ self.port.emit("play");
+ }
+
+ var pause_button = document.getElementById("pause-button");
+ pause_button.onclick = function() {
+ self.port.emit("pause");
+ }
+
+ var stop_button = document.getElementById("stop-button");
+ stop_button.onclick = function() {
+ self.port.emit("stop");
+ }
+
+We save this file in the add-on's `data` directory as "button-script.js".
+Finally. in the add-on's "main.js" file, we create the widget, assign it
+the HTML file and the content script, and listen for events from the content
+script:
+
+ const widgets = require("widget");
+ const data = require("self").data;
+
+ var player = widgets.Widget({
+ id: "player",
+ width: 72,
+ label: "Player",
+ contentURL: data.url("buttons.html"),
+ contentScriptFile: data.url("button-script.js")
+ });
+
+ player.port.on("play", function() {
+ console.log("playing");
+ });
+
+ player.port.on("pause", function() {
+ console.log("pausing");
+ });
+
+ player.port.on("stop", function() {
+ console.log("stopping");
+ });
+
+To learn much more about content scripts, see the
+[Working with Content Scripts](dev-guide/guides/content-scripts/index.html)
+guide.
+
+<div class="experimental">
+<h3>Scripting Trusted Widget Content</h3>
+
+**Note that the feature described in this section is experimental: we'll
+very probably continue to support it, but the name of the `addon`
+property might change in a future release.**
+
+We've already seen that you can package HTML files in your add-on's `data`
+directory and use them to define the widget's content. We can call this
+"trusted" content, because unlike content loaded from a source outside the
+add-on, the add-on author knows exactly what it's doing. To
+interact with trusted content you don't need to use content scripts:
+you can just include a script from the HTML file in the normal way, using
+`script` tags.
+
+Like a content script, these scripts can communicate with the add-on code
+using the
+[`postMessage()`](dev-guide/guides/content-scripts/using-postmessage.html)
+API or the
+[`port`](dev-guide/guides/content-scripts/using-port.html) API.
+The crucial difference is that these scripts access the `postMessage`
+and `port` objects through the `addon` object, whereas content scripts
+access them through the `self` object.
+
+To show the difference, convert the `player` add-on above
+to use normal page scripts instead of content scripts.
+
+First, in the content script, change `self` to `addon`, and wrap it in a
+function:
+
+ function init() {
+ var play_button = document.getElementById("play-button");
+ play_button.onclick = function() {
+ addon.port.emit("play");
+ }
+
+ var pause_button = document.getElementById("pause-button");
+ pause_button.onclick = function() {
+ addon.port.emit("pause");
+ }
+
+ var stop_button = document.getElementById("stop-button");
+ stop_button.onclick = function() {
+ addon.port.emit("stop");
+ }
+ }
+
+Next, add a `script` tag to reference "button-script.js", and
+call its `init()` function on load:
+
+<pre class="brush: html">
+&lt;html&gt;
+ &lt;head&gt;
+ &lt;script src="button-script.js">&lt;/script&gt;
+ &lt;/head&gt;
+ &lt;body onLoad="init()"&gt;
+ &lt;img src="play.png" id="play-button"&gt;
+ &lt;img src="pause.png" id="pause-button"&gt;
+ &lt;img src="stop.png" id="stop-button"&gt;
+ &lt;/body&gt;
+&lt;/html&gt;
+</pre>
+
+Finally, remove the line attaching the content script from "main.js":
+
+ const widgets = require("widget");
+ const data = require("self").data;
+
+ var player = widgets.Widget({
+ id: "player",
+ width: 72,
+ label: "Player",
+ contentURL: data.url("buttons.html")
+ });
+
+ player.port.emit("init");
+
+ player.port.on("play", function() {
+ console.log("playing");
+ });
+
+ player.port.on("pause", function() {
+ console.log("pausing");
+ });
+
+ player.port.on("stop", function() {
+ console.log("stopping");
+ });
+</div>
+
+## Attaching Panels to Widgets ##
+
+You can supply a [panel](packages/addon-kit/panel.html) to the widget's
+constructor: if you do this, the panel is automatically displayed when the
+user clicks the widget.
+
+<!-- The icon the widget displays, shown in the screenshot, is taken from the
+Circular icon set, http://prothemedesign.com/circular-icons/ which is made
+available under the Creative Commons Attribution 2.5 Generic License:
+http://creativecommons.org/licenses/by/2.5/ -->
+
+<img class="image-right" src="static-files/media/screenshots/widget-panel-clock.png"
+alt="Panel attached to a widget">
+
+ data = require("self").data
+
+ var clockPanel = require("panel").Panel({
+ width:215,
+ height:160,
+ contentURL: data.url("clock.html")
+ });
+
+ require("widget").Widget({
+ id: "open-clock-btn",
+ label: "Clock",
+ contentURL: data.url("History.png"),
+ panel: clockPanel
+ });
+
+Note that this is, at the moment, the only way you can attach a panel to a widget.
+
+You must supply the panel in the widget's constructor for it to work. If you
+assign the panel to the widget after construction, the panel can still be shown
+but will not be anchored to the widget:
+
+ data = require("self").data
+
+ var clockPanel = require("panel").Panel({
+ width:215,
+ height:160,
+ contentURL: data.url("clock.html")
+ });
+
+ widget = require("widget").Widget({
+ id: "open-clock-btn",
+ label: "Clock",
+ contentURL: data.url("History.png")
+ });
+
+ widget.panel = clockPanel;
+
+ // Will not be anchored
+ widget.panel.show();
+
+Also, if you try to call `panel.show()` inside your widget's `click` event
+listener, the panel will not be anchored:
+
+ data = require("self").data
+
+ var clockPanel = require("panel").Panel({
+ width:215,
+ height:160,
+ contentURL: data.url("clock.html")
+ });
+
+ require("widget").Widget({
+ id: "open-clock-btn",
+ label: "Clock",
+ contentURL: data.url("History.png"),
+ panel: clockPanel,
+ onClick: function() {
+ // Will not be anchored
+ this.panel.show();
+ }
+ });
+
+See [bug 638142](https://bugzilla.mozilla.org/show_bug.cgi?id=638142).
+
+## Examples ##
+
+For conciseness, these examples create their content scripts as strings and use
+the `contentScript` property. In your own add-ons, you will probably want to
+create your content scripts in separate files and pass their URLs using the
+`contentScriptFile` property. See
+[Working with Content Scripts](dev-guide/guides/content-scripts/index.html) for more
+information.
+
+ var widgets = require("widget");
+
+ // A basic click-able image widget.
+ widgets.Widget({
+ id: "google-link",
+ label: "Widget with an image and a click handler",
+ contentURL: "http://www.google.com/favicon.ico",
+ onClick: function() {
+ require("tabs").activeTab.url = "http://www.google.com/";
+ }
+ });
+<br>
+
+ // A widget that changes display on mouseover.
+ widgets.Widget({
+ id: "mouseover-effect",
+ label: "Widget with changing image on mouseover",
+ contentURL: "http://www.yahoo.com/favicon.ico",
+ onMouseover: function() {
+ this.contentURL = "http://www.bing.com/favicon.ico";
+ },
+ onMouseout: function() {
+ this.contentURL = "http://www.yahoo.com/favicon.ico";
+ }
+ });
+<br>
+
+ // A widget that updates content on a timer.
+ widgets.Widget({
+ id: "auto-update-widget",
+ label: "Widget that updates content on a timer",
+ content: "0",
+ contentScript: 'setTimeout(function() {' +
+ ' document.body.innerHTML++;' +
+ '}, 2000)',
+ contentScriptWhen: "ready"
+ });
+<br>
+
+ // A widget that loads a random Flickr photo every 5 minutes.
+ widgets.Widget({
+ id: "random-flickr",
+ label: "Random Flickr Photo Widget",
+ contentURL: "http://www.flickr.com/explore/",
+ contentScriptWhen: "ready",
+ contentScript: 'postMessage(document.querySelector(".pc_img").src);' +
+ 'setTimeout(function() {' +
+ ' document.location = "http://www.flickr.com/explore/";' +
+ '}, 5 * 60 * 1000);',
+ onMessage: function(imgSrc) {
+ this.contentURL = imgSrc;
+ },
+ onClick: function() {
+ require("tabs").activeTab.url = this.contentURL;
+ }
+ });
+<br>
+
+ // A widget created with a specified width, that grows.
+ let myWidget = widgets.Widget({
+ id: "widget-effect",
+ label: "Wide widget that grows wider on a timer",
+ content: "I'm getting longer.",
+ width: 50,
+ });
+ require("timers").setInterval(function() {
+ myWidget.width += 10;
+ }, 1000);
+<br>
+
+ // A widget communicating bi-directionally with a content script.
+ let widget = widgets.Widget({
+ id: "message-test",
+ label: "Bi-directional communication!",
+ content: "<foo>bar</foo>",
+ contentScriptWhen: "ready",
+ contentScript: 'on("message", function(message) {' +
+ ' alert("Got message: " + message);' +
+ '});' +
+ 'postMessage("ready");',
+ onMessage: function(message) {
+ if (message == "ready")
+ widget.postMessage("me too");
+ }
+ });
+
+<api-name="Widget">
+@class
+Represents a widget object.
+
+<api name="Widget">
+@constructor {options}
+ Creates a new widget. The widget is immediately added to the add-on bar.
+
+@param options {object}
+ An object with the following keys:
+
+ @prop label {string}
+ A required string description of the widget used for accessibility,
+ title bars, and error reporting.
+
+ @prop id {string}
+ Mandatory string used to identify your widget in order to save its
+ location when the user moves it in the browser.
+ This string has to be unique and must not be changed over time.
+
+ @prop [content] {string}
+ An optional string value containing the displayed content of the widget.
+ It may contain HTML. Widgets must have either the `content` property or the
+ `contentURL` property set.
+
+ If the content is an image, it is automatically scaled to be 16x16 pixels.
+
+ @prop [contentURL] {string}
+ An optional string URL to content to load into the widget. This can be
+ [local content](dev-guide/guides/content-scripts/index.html) or remote
+ content, an image or web content. Widgets must have either the `content`
+ property or the `contentURL` property set.
+
+ If the content is an image, it is automatically scaled to be 16x16 pixels.
+
+ @prop [panel] {Panel}
+ An optional [panel](packages/addon-kit/panel.html) to open when the
+ user clicks on the widget. Note: If you also register a "click" listener,
+ it will be called instead of the panel being opened. However, you can show
+ the panel from the listener by calling `this.panel.show()`.
+
+ @prop [width] {integer}
+ Optional width in pixels of the widget. If not given, a default width is
+ used.
+
+ @prop [onClick] {function}
+ Include this to listen to the widget's `click` event.
+
+ @prop [onMessage] {function}
+ Include this to listen to the widget's `message` event.
+
+ @prop [onMouseover] {function}
+ Include this to listen to the widget's `mouseover` event.
+
+ @prop [onMouseout] {function}
+ Include this to listen to the widget's `mouseout` event.
+
+ @prop [onAttach] {function}
+ Include this to listen to the widget's `attach` event.
+
+ @prop [tooltip] {string}
+ Optional text to show when the user's mouse hovers over the widget. If not
+ given, the `label` is used.
+
+ @prop [allow] {object}
+ An optional object describing permissions for the content. It should
+ contain a single key named `script` whose value is a boolean that indicates
+ whether or not to execute script in the content. `script` defaults to true.
+
+ @prop [contentScriptFile] {string,array}
+ A local file URL or an array of local file URLs of content scripts to load.
+ Content scripts specified by this property are loaded *before* those
+ specified by the `contentScript` property.
+
+ @prop [contentScript] {string,array}
+ A string or an array of strings containing the texts of content scripts to
+ load. Content scripts specified by this property are loaded *after* those
+ specified by the `contentScriptFile` property.
+
+ @prop [contentScriptWhen="end"] {string}
+ When to load the content scripts. This may take one of the following
+ values:
+
+ * "start": load content scripts immediately after the document
+ element for the widget is inserted into the DOM, but before the DOM content
+ itself has been loaded
+ * "ready": load content scripts once DOM content has been loaded,
+ corresponding to the
+ [DOMContentLoaded](https://developer.mozilla.org/en/Gecko-Specific_DOM_Events)
+ event
+ * "end": load content scripts once all the content (DOM, JS, CSS,
+ images) for the widget has been loaded, at the time the
+ [window.onload event](https://developer.mozilla.org/en/DOM/window.onload)
+ fires
+
+ This property is optional and defaults to "end".
+
+</api>
+
+<api name="destroy">
+@method
+ Removes the widget from the add-on bar.
+</api>
+
+<api name="postMessage">
+@method
+ Sends a message to the widget's content scripts.
+@param data {value}
+ The message to send.
+ The message can be any
+<a href = "dev-guide/guides/content-scripts/using-port.html#json_serializable">JSON-serializable value</a>.
+</api>
+
+<api name="on">
+@method
+ Registers an event listener with the widget.
+@param type {string}
+ The type of event to listen for.
+@param listener {function}
+ The listener function that handles the event.
+</api>
+
+<api name="removeListener">
+@method
+ Unregisters an event listener from the widget.
+@param type {string}
+ The type of event for which `listener` was registered.
+@param listener {function}
+ The listener function that was registered.
+</api>
+
+<api name="getView">
+@method
+ Retrieve a `WidgetView` instance of this widget relative to a browser window.
+@param window {BrowserWindow}
+ The [BrowserWindow](packages/addon-kit/windows.html) instance to match.
+@returns {WidgetView}
+ A `WidgetView` instance associated with the browser window. Any changes
+ subsequently applied to this object will only be applied to the widget
+ attached to that window.
+</api>
+
+<api name="label">
+@property {string}
+ The widget's label. Read-only.
+</api>
+
+<api name="content">
+@property {string}
+ A string containing the widget's content. It can contain HTML. Setting it
+ updates the widget's appearance immediately. However, if the widget was
+ created using `contentURL`, then this property is meaningless, and setting it
+ has no effect.
+</api>
+
+<api name="contentURL">
+@property {string}
+ The URL of content to load into the widget. This can point to
+ local content loaded from your add-on's "data" directory or remote
+ content, an image or web content. Setting it updates the widget's appearance
+ immediately. However, if the widget was created using `content`, then this
+ property is meaningless, and setting it has no effect.
+</api>
+
+<api name="panel">
+@property {Panel}
+ A [panel](packages/addon-kit/panel.html) to open when the user clicks on
+ the widget.
+</api>
+
+<api name="width">
+@property {number}
+ The widget's width in pixels. Setting it updates the widget's appearance
+ immediately.
+</api>
+
+<api name="tooltip">
+@property {string}
+ The text of the tooltip that appears when the user hovers over the widget.
+</api>
+
+<api name="allow">
+@property {object}
+ A object describing permissions for the content. It contains a single key
+ named `script` whose value is a boolean that indicates whether or not to
+ execute script in the content.
+</api>
+
+<api name="contentScriptFile">
+@property {string,array}
+ A local file URL or an array of local file URLs of content scripts to load.
+</api>
+
+<api name="contentScript">
+@property {string,array}
+ A string or an array of strings containing the texts of content scripts to
+ load.
+</api>
+
+<api name="contentScriptWhen">
+@property {string}
+ When to load the content scripts. This may have one of the following
+ values:
+
+ * "start": load content scripts immediately after the document
+ element for the widget is inserted into the DOM, but before the DOM content
+ itself has been loaded
+ * "ready": load content scripts once DOM content has been loaded,
+ corresponding to the
+ [DOMContentLoaded](https://developer.mozilla.org/en/Gecko-Specific_DOM_Events)
+ event
+ * "end": load content scripts once all the content (DOM, JS, CSS,
+ images) for the widget has been loaded, at the time the
+ [window.onload event](https://developer.mozilla.org/en/DOM/window.onload)
+ fires
+
+</api>
+
+<api name="port">
+@property {EventEmitter}
+[EventEmitter](packages/api-utils/events.html) object that allows you to:
+
+* send events to the content script using the `port.emit` function
+* receive events from the content script using the `port.on` function
+
+See the guide to
+<a href="dev-guide/guides/content-scripts/using-port.html">
+communicating using <code>port</code></a> for details.
+</api>
+
+<api name="attach">
+@event
+This event is emitted when a new `WidgetView` object is created using the
+`getView()` function.
+</api>
+
+<api name="click">
+@event
+This event is emitted when the widget is clicked.
+</api>
+
+<api name="message">
+@event
+If you listen to this event you can receive message events from content
+scripts associated with this widget. When a content script posts a
+message using `self.postMessage()`, the message is delivered to the add-on
+code in the widget's `message` event.
+
+@argument {value}
+Listeners are passed a single argument which is the message posted
+from the content script. The message can be any
+<a href = "dev-guide/guides/content-scripts/using-port.html#json_serializable">JSON-serializable value</a>.
+</api>
+
+<api name="mouseover">
+@event
+This event is emitted when the user moves the mouse over the widget.
+</api>
+
+<api name="mouseout">
+@event
+This event is emitted when the user moves the mouse away from the widget.
+</api>
+
+</api>
+
+
+<api-name="WidgetView">
+@class
+Represents a widget instance specific to one browser window.
+
+Anything you do to an instance of this object will only be applied to the
+instance attached to its browser window: widget instances attached to other
+browser windows will be unaffected.
+
+By contrast, any changes you make to an instance of the normal `Widget` class
+will be applied across all browser windows.
+
+This class has all the same methods, attributes and events as the `Widget`
+class except for the `getView` method and the `attach` event.
+
+In this example `WidgetView` is used to display different content for
+`http` and `https` schemes:
+
+ // A widget that update its content specifically to each window.
+ let tabs = require("tabs");
+ let windows = require("windows").browserWindows;
+ let widget = widgets.Widget({
+ id: "window-specific-test",
+ label: "Widget with content specific to each window",
+ content: " ",
+ width: 50
+ });
+ // Observe tab switch or document changes in each existing tab:
+ function updateWidgetState(tab) {
+ let view = widget.getView(tab.window);
+ if (!view) return;
+ // Update widget displayed text:
+ view.content = tab.url.match(/^https/) ? "Secured" : "Unsafe";
+ }
+ tabs.on('ready', updateWidgetState);
+ tabs.on('activate', updateWidgetState);
+
+<api name="destroy">
+@method
+ Removes the widget view from the add-on bar.
+</api>
+
+<api name="postMessage">
+@method
+ Sends a message to the widget view's content scripts.
+@param data {value}
+ The message to send. The message can be any
+<a href = "dev-guide/guides/content-scripts/using-port.html#json_serializable">JSON-serializable value</a>.
+</api>
+
+<api name="on">
+@method
+ Registers an event listener with the widget view.
+@param type {string}
+ The type of event to listen for.
+@param listener {function}
+ The listener function that handles the event.
+</api>
+
+<api name="removeListener">
+@method
+ Unregisters an event listener from the widget view.
+@param type {string}
+ The type of event for which `listener` was registered.
+@param listener {function}
+ The listener function that was registered.
+</api>
+
+<api name="label">
+@property {string}
+ The widget view's label. Read-only.
+</api>
+
+<api name="content">
+@property {string}
+ A string containing the widget view's content. It can contain HTML.
+ Setting it updates the widget view's appearance immediately. However,
+ if the widget view was created using `contentURL`, then this property
+ is meaningless, and setting it has no effect.
+</api>
+
+<api name="contentURL">
+@property {string}
+ The URL of content to load into the widget. This can point to
+ local content loaded from your add-on's "data" directory or remote
+ content, an image or web content. Setting it updates the widget's appearance
+ immediately. However, if the widget was created using `content`, then this
+ property is meaningless, and setting it has no effect.
+</api>
+
+<api name="panel">
+@property {Panel}
+ A [panel](packages/addon-kit/panel.html) to open when the user clicks on
+ the widget view.
+</api>
+
+<api name="width">
+@property {number}
+ The widget view's width in pixels. Setting it updates the widget view's
+ appearance immediately.
+</api>
+
+<api name="tooltip">
+@property {string}
+ The text of the tooltip that appears when the user hovers over the widget
+ view.
+</api>
+
+<api name="allow">
+@property {object}
+ A object describing permissions for the content. It contains a single key
+ named `script` whose value is a boolean that indicates whether or not to
+ execute script in the content.
+</api>
+
+<api name="contentScriptFile">
+@property {string,array}
+ A local file URL or an array of local file URLs of content scripts to load.
+</api>
+
+<api name="contentScript">
+@property {string,array}
+ A string or an array of strings containing the texts of content scripts to
+ load.
+</api>
+
+<api name="contentScriptWhen">
+@property {string}
+ When to load the content scripts. This may have one of the following
+ values:
+
+ * "start": load content scripts immediately after the document
+ element for the widget view is inserted into the DOM, but before the DOM
+ content itself has been loaded
+ * "ready": load content scripts once DOM content has been loaded,
+ corresponding to the
+ [DOMContentLoaded](https://developer.mozilla.org/en/Gecko-Specific_DOM_Events)
+ event
+ * "end": load content scripts once all the content (DOM, JS, CSS,
+ images) for the widget view has been loaded, at the time the
+ [window.onload event](https://developer.mozilla.org/en/DOM/window.onload)
+ fires
+
+</api>
+
+<api name="port">
+@property {EventEmitter}
+[EventEmitter](packages/api-utils/events.html) object that allows you to:
+
+* send events to the content script using the `port.emit` function
+* receive events from the content script using the `port.on`
+
+See the guide to
+<a href="dev-guide/guides/content-scripts/using-port.html">
+communicating using <code>port</code></a> for details.
+</api>
+
+<api name="detach">
+@event
+The `detach` event is fired when the widget view is removed from its related
+window.
+This can occur if the window is closed, Firefox exits, or the add-on is
+disabled.
+</api>
+
+<api name="click">
+@event
+This event is emitted when the widget view is clicked.
+</api>
+
+<api name="message">
+@event
+If you listen to this event you can receive message events from content
+scripts associated with this widget view. When a content script posts a
+message using `self.postMessage()`, the message is delivered to the add-on
+code in the widget view's `message` event.
+
+@argument {value}
+Listeners are passed a single argument which is the message posted
+from the content script. The message can be any
+<a href = "dev-guide/guides/content-scripts/using-port.html#json_serializable">JSON-serializable value</a>.
+</api>
+
+<api name="mouseover">
+@event
+This event is emitted when the user moves the mouse over the widget view.
+</api>
+
+<api name="mouseout">
+@event
+This event is emitted when the user moves the mouse away from the widget view.
+</api>
+
+</api>
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/docs/windows.md b/tools/addon-sdk-1.7/packages/addon-kit/docs/windows.md
new file mode 100644
index 0000000..f44817e
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/docs/windows.md
@@ -0,0 +1,191 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Felipe Gomes [felipc@gmail.com] -->
+
+
+The `windows` module provides easy access to browser windows, their
+tabs, and open/close related functions and events.
+
+This module currently only supports browser windows and does not provide
+access to non-browser windows such as the Bookmarks Library, preferences
+or other non-browser windows created via add-ons.
+
+<api name="browserWindows">
+@property {List}
+An object that contains various properties and methods to access
+functionality from browser windows, such as opening new windows, accessing
+their tabs or switching the current active window.
+
+`browserWindows` provides access to all the currently open browser windows:
+
+ var windows = require("windows");
+ for each (var window in windows.browserWindows) {
+ console.log(window.title);
+ }
+
+ console.log(windows.browserWindows.length);
+
+Object emits all the events listed under "Events" section.
+
+####Examples####
+
+ var windows = require("windows").browserWindows;
+
+ // add a listener to the 'open' event
+ windows.on('open', function(window) {
+ myOpenWindows.push(window);
+ });
+
+ // add a listener to the 'close' event
+ windows.on('close', function(window) {
+ console.log("A window was closed.");
+ });
+
+<api name="activeWindow">
+@property {BrowserWindow}
+
+The currently active window. This property is read-only.
+
+**Example**
+
+ // get
+ var windows = require("windows");
+ console.log("title of active window is " +
+ windows.browserWindows.activeWindow.title);
+
+ anotherWindow.activate();
+ // set
+ windows.activeWindow == anotherWindow // true
+</api>
+
+</api>
+
+<api name="open">
+@function
+Open a new window.
+
+ var windows = require("windows").browserWindows;
+
+ // Open a new window.
+ windows.open("http://www.example.com");
+
+ // Open a new window and set a listener for "open" event.
+ windows.open({
+ url: "http://www.example.com",
+ onOpen: function(window) {
+ // do stuff like listen for content
+ // loading.
+ }
+ });
+
+Returns the window that was opened:
+
+ var widgets = require("widget");
+ var windows = require("windows").browserWindows;
+
+ var example = windows.open("http://www.example.com");
+
+ var widget = widgets.Widget({
+ id: "close-window",
+ label: "Close window",
+ contentURL: "http://www.mozilla.org/favicon.ico",
+ onClick: function() {
+ example.close();
+ }
+ });
+
+@param options {object}
+An object containing configurable options for how this window will be opened,
+as well as a callback for being notified when the window has fully opened.
+
+If the only option being used is `url`, then a bare string URL can be passed to
+`open` instead of specifying it as a property of the `options` object.
+
+@prop url {string}
+String URL to be opened in the new window.
+This is a required property.
+
+@prop [onOpen] {function}
+A callback function that is called when the window has opened. This does not
+mean that the URL content has loaded, only that the window itself is fully
+functional and its properties can be accessed. This is an optional property.
+
+@prop [onClose] {function}
+A callback function that is called when the window will be called.
+This is an optional property.
+
+@returns {BrowserWindow}
+</api>
+
+<api name="BrowserWindow">
+@class
+A `BrowserWindow` instance represents a single open window. They can be
+retrieved from the `browserWindows` property exported by this module.
+
+ var windows = require("windows").browserWindows;
+
+ //Print how many tabs the current window has
+ console.log("The active window has " +
+ windows.activeWindow.tabs.length +
+ " tabs.");
+
+ // Print the title of all browser windows
+ for each (var window in windows) {
+ console.log(window.title);
+ }
+
+ // close the active window
+ windows.activeWindow.close();
+
+ windows.activeWindow.close(function() {
+ console.log("The active window was closed");
+ });
+
+<api name="title">
+@property {string}
+The current title of the window. Usually the title of the active tab,
+plus an app identifier.
+This property is read-only.
+</api>
+
+<api name="tabs">
+@property {TabList}
+A live list of tabs in this window. This object has the same interface as the
+[`tabs` API](packages/addon-kit/tabs.html), except it contains only the
+tabs in this window, not all tabs in all windows. This property is read-only.
+</api>
+
+<api name="activate">
+@method
+Makes window active, which will focus that window and bring it to the
+foreground.
+</api>
+
+<api name="close">
+@method
+Close the window.
+
+@param [callback] {function}
+A function to be called when the window finishes its closing process.
+This is an optional argument.
+</api>
+
+</api>
+
+<api name="open">
+@event
+Event emitted when a new window is open.
+This does not mean that the content has loaded, only that the browser window
+itself is fully visible to the user.
+@argument {Window}
+Listeners are passed the `window` object that triggered the event.
+</api>
+
+<api name="close">
+@event
+Event emitted when a window is closed.
+@argument {Window}
+Listeners are passed the `window` object that triggered the event.
+</api>
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/lib/addon-page.js b/tools/addon-sdk-1.7/packages/addon-kit/lib/addon-page.js
new file mode 100644
index 0000000..eeb5461
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/lib/addon-page.js
@@ -0,0 +1,33 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+const { uriPrefix, name } = require('@packaging');
+const { WindowTracker, isBrowser } = require('api-utils/window-utils');
+const { add, remove } = require('api-utils/array');
+const { getTabs, closeTab } = require('api-utils/tabs/utils');
+
+// Note: This is an URL that will be returned by calling
+// `require('self').data.url('index.html')` from the add-on modules.
+// We could not use this expression as in this module it would have
+// returned "addon-kit/data/index.html" instead.
+const addonURL = uriPrefix + name + '/data/index.html';
+
+WindowTracker({
+ onTrack: function onTrack(window) {
+ if (isBrowser(window))
+ add(window.XULBrowserWindow.inContentWhitelist, addonURL);
+ },
+ onUntrack: function onUntrack(window) {
+ getTabs(window).
+ filter(function(tab) tab.linkedBrowser.currentURI.spec === addonURL).
+ forEach(function(tab) {
+ // Note: `onUntrack` will be called for all windows on add-on unloads,
+ // so we want to clean them up from these URLs.
+ remove(window.XULBrowserWindow.inContentWhitelist, addonURL);
+ closeTab(tab);
+ });
+ }
+});
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/lib/clipboard.js b/tools/addon-sdk-1.7/packages/addon-kit/lib/clipboard.js
new file mode 100644
index 0000000..2feab22
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/lib/clipboard.js
@@ -0,0 +1,230 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {Cc,Ci} = require("chrome");
+const errors = require("api-utils/errors");
+const apiUtils = require("api-utils/api-utils");
+
+/*
+While these data flavors resemble Internet media types, they do
+no directly map to them.
+*/
+const kAllowableFlavors = [
+ "text/unicode",
+ "text/html"
+ /* CURRENTLY UNSUPPORTED FLAVORS
+ "text/plain",
+ "image/png",
+ "image/jpg",
+ "image/gif"
+ "text/x-moz-text-internal",
+ "AOLMAIL",
+ "application/x-moz-file",
+ "text/x-moz-url",
+ "text/x-moz-url-data",
+ "text/x-moz-url-desc",
+ "text/x-moz-url-priv",
+ "application/x-moz-nativeimage",
+ "application/x-moz-nativehtml",
+ "application/x-moz-file-promise-url",
+ "application/x-moz-file-promise-dest-filename",
+ "application/x-moz-file-promise",
+ "application/x-moz-file-promise-dir"
+ */
+];
+
+/*
+Aliases for common flavors. Not all flavors will
+get an alias. New aliases must be approved by a
+Jetpack API druid.
+*/
+const kFlavorMap = [
+ { short: "text", long: "text/unicode" },
+ { short: "html", long: "text/html" }
+ // Images are currently unsupported.
+ //{ short: "image", long: "image/png" },
+];
+
+let clipboardService = Cc["@mozilla.org/widget/clipboard;1"].
+ getService(Ci.nsIClipboard);
+
+let clipboardHelper = Cc["@mozilla.org/widget/clipboardhelper;1"].
+ getService(Ci.nsIClipboardHelper);
+
+
+exports.set = function(aData, aDataType) {
+ let options = {
+ data: aData,
+ datatype: aDataType || "text"
+ };
+ options = apiUtils.validateOptions(options, {
+ data: {
+ is: ["string"]
+ },
+ datatype: {
+ is: ["string"]
+ }
+ });
+
+ var flavor = fromJetpackFlavor(options.datatype);
+
+ if (!flavor)
+ throw new Error("Invalid flavor");
+
+ // Additional checks for using the simple case
+ if (flavor == "text/unicode") {
+ clipboardHelper.copyString(options.data);
+ return true;
+ }
+
+ // Below are the more complex cases where we actually have to work with a
+ // nsITransferable object
+ var xferable = Cc["@mozilla.org/widget/transferable;1"].
+ createInstance(Ci.nsITransferable);
+ if (!xferable)
+ throw new Error("Couldn't set the clipboard due to an internal error " +
+ "(couldn't create a Transferable object).");
+
+ switch (flavor) {
+ case "text/html":
+ // add text/html flavor
+ let (str = Cc["@mozilla.org/supports-string;1"].
+ createInstance(Ci.nsISupportsString))
+ {
+ str.data = options.data;
+ xferable.addDataFlavor(flavor);
+ xferable.setTransferData(flavor, str, str.data.length * 2);
+ }
+
+ // add a text/unicode flavor (html converted to plain text)
+ let (str = Cc["@mozilla.org/supports-string;1"].
+ createInstance(Ci.nsISupportsString),
+ converter = Cc["@mozilla.org/feed-textconstruct;1"].
+ createInstance(Ci.nsIFeedTextConstruct))
+ {
+ converter.type = "html";
+ converter.text = options.data;
+ str.data = converter.plainText();
+ xferable.addDataFlavor("text/unicode");
+ xferable.setTransferData("text/unicode", str, str.data.length * 2);
+ }
+ break;
+ // TODO: images!
+ default:
+ throw new Error("Unable to handle the flavor " + flavor + ".");
+ }
+
+ // TODO: Not sure if this will ever actually throw. -zpao
+ try {
+ clipboardService.setData(
+ xferable,
+ null,
+ clipboardService.kGlobalClipboard
+ );
+ } catch (e) {
+ throw new Error("Couldn't set clipboard data due to an internal error: " + e);
+ }
+ return true;
+};
+
+
+exports.get = function(aDataType) {
+ let options = {
+ datatype: aDataType || "text"
+ };
+ options = apiUtils.validateOptions(options, {
+ datatype: {
+ is: ["string"]
+ }
+ });
+
+ var xferable = Cc["@mozilla.org/widget/transferable;1"].
+ createInstance(Ci.nsITransferable);
+ if (!xferable)
+ throw new Error("Couldn't set the clipboard due to an internal error " +
+ "(couldn't create a Transferable object).");
+
+ var flavor = fromJetpackFlavor(options.datatype);
+
+ // Ensure that the user hasn't requested a flavor that we don't support.
+ if (!flavor)
+ throw new Error("Getting the clipboard with the flavor '" + flavor +
+ "' is > not supported.");
+
+ // TODO: Check for matching flavor first? Probably not worth it.
+
+ xferable.addDataFlavor(flavor);
+
+ // Get the data into our transferable.
+ clipboardService.getData(
+ xferable,
+ clipboardService.kGlobalClipboard
+ );
+
+ var data = {};
+ var dataLen = {};
+ try {
+ xferable.getTransferData(flavor, data, dataLen);
+ } catch (e) {
+ // Clipboard doesn't contain data in flavor, return null.
+ return null;
+ }
+
+ // There's no data available, return.
+ if (data.value === null)
+ return null;
+
+ // TODO: Add flavors here as we support more in kAllowableFlavors.
+ switch (flavor) {
+ case "text/unicode":
+ case "text/html":
+ data = data.value.QueryInterface(Ci.nsISupportsString).data;
+ break;
+ default:
+ data = null;
+ }
+
+ return data;
+};
+
+exports.__defineGetter__("currentFlavors", function() {
+ // Loop over kAllowableFlavors, calling hasDataMatchingFlavors for each.
+ // This doesn't seem like the most efficient way, but we can't get
+ // confirmation for specific flavors any other way. This is supposed to be
+ // an inexpensive call, so performance shouldn't be impacted (much).
+ var currentFlavors = [];
+ for each (var flavor in kAllowableFlavors) {
+ var matches = clipboardService.hasDataMatchingFlavors(
+ [flavor],
+ 1,
+ clipboardService.kGlobalClipboard
+ );
+ if (matches)
+ currentFlavors.push(toJetpackFlavor(flavor));
+ }
+ return currentFlavors;
+});
+
+// SUPPORT FUNCTIONS ////////////////////////////////////////////////////////
+
+function toJetpackFlavor(aFlavor) {
+ for each (let flavorMap in kFlavorMap)
+ if (flavorMap.long == aFlavor)
+ return flavorMap.short;
+ // Return null in the case where we don't match
+ return null;
+}
+
+function fromJetpackFlavor(aJetpackFlavor) {
+ // TODO: Handle proper flavors better
+ for each (let flavorMap in kFlavorMap)
+ if (flavorMap.short == aJetpackFlavor || flavorMap.long == aJetpackFlavor)
+ return flavorMap.long;
+ // Return null in the case where we don't match.
+ return null;
+}
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/lib/context-menu.js b/tools/addon-sdk-1.7/packages/addon-kit/lib/context-menu.js
new file mode 100644
index 0000000..75ccbea
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/lib/context-menu.js
@@ -0,0 +1,1492 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {Ci} = require("chrome");
+
+if (!require("api-utils/xul-app").is("Firefox")) {
+ throw new Error([
+ "The context-menu module currently supports only Firefox. In the future ",
+ "we would like it to support other applications, however. Please see ",
+ "https://bugzilla.mozilla.org/show_bug.cgi?id=560716 for more information."
+ ].join(""));
+}
+
+const apiUtils = require("api-utils/api-utils");
+const collection = require("api-utils/collection");
+const { Worker } = require("api-utils/content");
+const { URL } = require("api-utils/url");
+const { MatchPattern } = require("api-utils/match-pattern");
+const { EventEmitterTrait: EventEmitter } = require("api-utils/events");
+const observerServ = require("api-utils/observer-service");
+const jpSelf = require("self");
+const winUtils = require("api-utils/window-utils");
+const { getInnerId } = require("api-utils/window/utils");
+const { Trait } = require("api-utils/light-traits");
+const { Cortex } = require("api-utils/cortex");
+const timer = require("timer");
+
+// All user items we add have this class name.
+const ITEM_CLASS = "jetpack-context-menu-item";
+
+// Items in the top-level context menu also have this class.
+const TOPLEVEL_ITEM_CLASS = "jetpack-context-menu-item-toplevel";
+
+// Items in the overflow submenu also have this class.
+const OVERFLOW_ITEM_CLASS = "jetpack-context-menu-item-overflow";
+
+// The ID of the menu separator that separates standard context menu items from
+// our user items.
+const SEPARATOR_ID = "jetpack-context-menu-separator";
+
+// If more than this number of items are added to the context menu, all items
+// overflow into a "Jetpack" submenu.
+const OVERFLOW_THRESH_DEFAULT = 10;
+const OVERFLOW_THRESH_PREF =
+ "extensions.addon-sdk.context-menu.overflowThreshold";
+
+// The label of the overflow sub-xul:menu.
+//
+// TODO: Localize this.
+const OVERFLOW_MENU_LABEL = "Add-ons";
+
+// The ID of the overflow sub-xul:menu.
+const OVERFLOW_MENU_ID = "jetpack-content-menu-overflow-menu";
+
+// The ID of the overflow submenu's xul:menupopup.
+const OVERFLOW_POPUP_ID = "jetpack-content-menu-overflow-popup";
+
+// These are used by PageContext.isCurrent below. If the popupNode or any of
+// its ancestors is one of these, Firefox uses a tailored context menu, and so
+// the page context doesn't apply.
+const NON_PAGE_CONTEXT_ELTS = [
+ Ci.nsIDOMHTMLAnchorElement,
+ Ci.nsIDOMHTMLAppletElement,
+ Ci.nsIDOMHTMLAreaElement,
+ Ci.nsIDOMHTMLButtonElement,
+ Ci.nsIDOMHTMLCanvasElement,
+ Ci.nsIDOMHTMLEmbedElement,
+ Ci.nsIDOMHTMLImageElement,
+ Ci.nsIDOMHTMLInputElement,
+ Ci.nsIDOMHTMLMapElement,
+ Ci.nsIDOMHTMLMediaElement,
+ Ci.nsIDOMHTMLMenuElement,
+ Ci.nsIDOMHTMLObjectElement,
+ Ci.nsIDOMHTMLOptionElement,
+ Ci.nsIDOMHTMLSelectElement,
+ Ci.nsIDOMHTMLTextAreaElement,
+];
+
+// This is used to access private properties of Item and Menu instances.
+const PRIVATE_PROPS_KEY = {
+ valueOf: function valueOf() "private properties key"
+};
+
+// Used as an internal ID for items and as part of a public ID for item DOM
+// elements. Careful: This number is not necessarily unique to any one instance
+// of the module. For each module instance, when the first item is created this
+// number will be 0, when the second is created it will be 1, and so on.
+let nextItemID = 0;
+
+// The number of items that haven't finished initializing yet. See
+// AIT__finishActiveItemInit().
+let numItemsWithUnfinishedInit = 0;
+
+exports.Item = Item;
+exports.Menu = Menu;
+exports.Separator = Separator;
+
+
+// A word about traits and privates. `this` inside of traits methods is an
+// object private to the implementation. It should never be publicly leaked.
+// We use Cortex in the exported menu item constructors to create public
+// reflections of the private objects that hide private properties -- those
+// prefixed with an underscore. Public reflections are attached to the private
+// objects via the `_public` property.
+//
+// All item objects passed into the implementation by the client will be public
+// reflections, not private objects. Likewise, all item objects passed out of
+// the implementation to the client must be public, not private. Mixing up
+// public and private is bad and easy to do, so not only are private objects
+// restricted to the implementation, but as much as possible we try to restrict
+// them to the Item, Menu, and Separator traits and constructors. Everybody
+// else in the implementation should expect to be passed public reflections, and
+// they must specifically request private objects via privateItem().
+
+// Item, Menu, and Separator are composed of this trait.
+const ItemBaseTrait = Trait({
+
+ _initBase: function IBT__initBase(opts, optRules, optsToNotSet) {
+ this._optRules = optRules;
+ for (let optName in optRules)
+ if (optsToNotSet.indexOf(optName) < 0)
+ this[optName] = opts[optName];
+ optsToNotSet.forEach(function (opt) validateOpt(opts[opt], optRules[opt]));
+ this._isInited = true;
+
+ this._id = nextItemID++;
+ this._parentMenu = null;
+
+ // This makes the private properties accessible to anyone with access to
+ // PRIVATE_PROPS_KEY. Barring loader tricks, only this file has has access
+ // to it, so only this file has access to the private properties.
+ const self = this;
+ this.valueOf = function IBT_valueOf(key) {
+ return key === PRIVATE_PROPS_KEY ? self : self._public;
+ };
+ },
+
+ destroy: function IBT_destroy() {
+ if (this._wasDestroyed)
+ return;
+ if (this.parentMenu)
+ this.parentMenu.removeItem(this._public);
+ else if (!(this instanceof Separator) && this._hasFinishedInit)
+ browserManager.removeTopLevelItem(this._public);
+ browserManager.unregisterItem(this._public);
+ this._wasDestroyed = true;
+ },
+
+ get parentMenu() {
+ return this._parentMenu;
+ },
+
+ set parentMenu(val) {
+ throw new Error("The 'parentMenu' property is not intended to be set. " +
+ "Use menu.addItem(item) instead.");
+ },
+
+ set _isTopLevel(val) {
+ if (val)
+ this._workerReg = new WorkerRegistry(this._public);
+ else {
+ this._workerReg.destroy();
+ delete this._workerReg;
+ }
+ },
+
+ get _topLevelItem() {
+ let topLevelItem = this._public;
+ let parentMenu = this.parentMenu;
+ while (parentMenu) {
+ topLevelItem = parentMenu;
+ parentMenu = parentMenu.parentMenu;
+ }
+ return topLevelItem;
+ }
+});
+
+// Item and Menu are composed of this trait.
+const ActiveItemTrait = Trait.compose(ItemBaseTrait, EventEmitter, Trait({
+
+ _initActiveItem: function AIT__initActiveItem(opts, optRules, optsToNotSet) {
+ this._initBase(opts, optRules,
+ optsToNotSet.concat(["onMessage", "context"]));
+
+ if ("onMessage" in opts)
+ this.on("message", opts.onMessage);
+
+ // When a URL context is removed (by calling context.remove(urlContext)), we
+ // may need to create workers for windows containing pages that the item now
+ // matches. Likewise, when a URL context is added, we need to destroy
+ // workers for windows containing pages that the item now does not match.
+ //
+ // collection doesn't provide a way to listen for removals. utils/registry
+ // does, but it doesn't allow its elements to be enumerated. So as a hack,
+ // use a collection for item.context and replace its add and remove methods.
+ collection.addCollectionProperty(this, "context");
+ if (opts.context)
+ this.context.add(opts.context);
+
+ const self = this;
+
+ let add = this.context.add;
+ this.context.add = function itemContextAdd() {
+ let args = Array.slice(arguments);
+ add.apply(self.context, args);
+ if (self._workerReg && args.some(function (a) a instanceof URLContext))
+ self._workerReg.destroyUnneededWorkers();
+ };
+
+ let remove = this.context.remove;
+ this.context.remove = function itemContextRemove() {
+ let args = Array.slice(arguments);
+ remove.apply(self.context, args);
+ if (self._workerReg && args.some(function (a) a instanceof URLContext))
+ self._workerReg.createNeededWorkers();
+ };
+ },
+
+ // Workers are only created for top-level menu items. When a top-level item
+ // is later added to a Menu, its workers are destroyed. Well, all items start
+ // out as top-level because there is, unfortunately, no contextMenu.add(). So
+ // when an item is created and immediately added to a Menu, workers for it are
+ // needlessly created and destroyed. The point of this timeout is to avoid
+ // that. Items that are created and added to Menus in the same turn of the
+ // event loop won't have workers created for them.
+ _finishActiveItemInit: function AIT__finishActiveItemInit() {
+ numItemsWithUnfinishedInit++;
+ const self = this;
+ timer.setTimeout(function AIT__finishActiveItemInitTimeout() {
+ if (!self.parentMenu && !self._wasDestroyed)
+ browserManager.addTopLevelItem(self._public);
+ self._hasFinishedInit = true;
+ numItemsWithUnfinishedInit--;
+ }, 0);
+ },
+
+ get label() {
+ return this._label;
+ },
+
+ set label(val) {
+ this._label = validateOpt(val, this._optRules.label);
+ if (this._isInited)
+ browserManager.setItemLabel(this, this._label);
+ return this._label;
+ },
+
+ get image() {
+ return this._image;
+ },
+
+ set image(val) {
+ this._image = validateOpt(val, this._optRules.image);
+ if (this._isInited)
+ browserManager.setItemImage(this, this._image);
+ return this._image;
+ },
+
+ get contentScript() {
+ return this._contentScript;
+ },
+
+ set contentScript(val) {
+ this._contentScript = validateOpt(val, this._optRules.contentScript);
+ return this._contentScript;
+ },
+
+ get contentScriptFile() {
+ return this._contentScriptFile;
+ },
+
+ set contentScriptFile(val) {
+ this._contentScriptFile =
+ validateOpt(val, this._optRules.contentScriptFile);
+ return this._contentScriptFile;
+ }
+}));
+
+// Item is composed of this trait.
+const ItemTrait = Trait.compose(ActiveItemTrait, Trait({
+
+ _initItem: function IT__initItem(opts, optRules) {
+ this._initActiveItem(opts, optRules, []);
+ },
+
+ get data() {
+ return this._data;
+ },
+
+ set data(val) {
+ this._data = validateOpt(val, this._optRules.data);
+ if (this._isInited)
+ browserManager.setItemData(this, this._data);
+ return this._data;
+ },
+
+ toString: function IT_toString() {
+ return '[object Item "' + this.label + '"]';
+ }
+}));
+
+// The exported Item constructor.
+function Item(options) {
+ let optRules = optionsRules();
+ optRules.data = {
+ map: function (v) v.toString(),
+ is: ["string", "undefined"]
+ };
+
+ let item = ItemTrait.create(Item.prototype);
+ item._initItem(options, optRules);
+
+ item._public = Cortex(item);
+ browserManager.registerItem(item._public);
+ item._finishActiveItemInit();
+
+ return item._public;
+}
+
+// Menu is composed of this trait.
+const MenuTrait = Trait.compose(
+ ActiveItemTrait.resolve({ destroy: "_destroyThisItem" }),
+ Trait({
+
+ _initMenu: function MT__initMenu(opts, optRules, optsToNotSet) {
+ this._items = [];
+ this._initActiveItem(opts, optRules, optsToNotSet);
+ },
+
+ destroy: function MT_destroy() {
+ while (this.items.length)
+ this.items[0].destroy();
+ this._destroyThisItem();
+ },
+
+ get items() {
+ return this._items;
+ },
+
+ set items(val) {
+ let newItems = validateOpt(val, this._optRules.items);
+ while (this.items.length)
+ this.items[0].destroy();
+ newItems.forEach(function (i) this.addItem(i), this);
+ return newItems;
+ },
+
+ addItem: function MT_addItem(item) {
+ // First, remove the item from its current parent.
+ let privates = privateItem(item);
+ if (item.parentMenu)
+ item.parentMenu.removeItem(item);
+ else if (!(item instanceof Separator) && privates._hasFinishedInit)
+ browserManager.removeTopLevelItem(item);
+
+ // Now add the item to this menu.
+ this._items.push(item);
+ privates._parentMenu = this._public;
+ browserManager.addItemToMenu(item, this._public);
+ },
+
+ removeItem: function MT_removeItem(item) {
+ let idx = this._items.indexOf(item);
+ if (idx < 0)
+ return;
+ this._items.splice(idx, 1);
+ privateItem(item)._parentMenu = null;
+ browserManager.removeItemFromMenu(item, this._public);
+ },
+
+ toString: function MT_toString() {
+ return '[object Menu "' + this.label + '"]';
+ }
+}));
+
+// The exported Menu constructor.
+function Menu(options) {
+ let optRules = optionsRules();
+ optRules.items = {
+ is: ["array"],
+ ok: function (v) {
+ return v.every(function (item) {
+ return (item instanceof Item) ||
+ (item instanceof Menu) ||
+ (item instanceof Separator);
+ });
+ },
+ msg: "items must be an array, and each element in the array must be an " +
+ "Item, Menu, or Separator."
+ };
+
+ let menu = MenuTrait.create(Menu.prototype);
+
+ // We can't rely on _initBase to set the `items` property, because the menu
+ // needs to be registered with and added to the browserManager before any
+ // child items are added to it.
+ menu._initMenu(options, optRules, ["items"]);
+
+ menu._public = Cortex(menu);
+ browserManager.registerItem(menu._public);
+ menu.items = options.items;
+ menu._finishActiveItemInit();
+
+ return menu._public;
+}
+
+// The exported Separator constructor.
+function Separator() {
+ let sep = ItemBaseTrait.create(Separator.prototype);
+ sep._initBase({}, {}, []);
+
+ sep._public = Cortex(sep);
+ browserManager.registerItem(sep._public);
+ sep._hasFinishedInit = true;
+ return sep._public;
+}
+
+
+function Context() {}
+
+function PageContext() {
+ this.isCurrent = function PageContext_isCurrent(popupNode) {
+ let win = popupNode.ownerDocument.defaultView;
+ if (win && !win.getSelection().isCollapsed)
+ return false;
+
+ let cursor = popupNode;
+ while (cursor && !(cursor instanceof Ci.nsIDOMHTMLHtmlElement)) {
+ if (NON_PAGE_CONTEXT_ELTS.some(function (iface) cursor instanceof iface))
+ return false;
+ cursor = cursor.parentNode;
+ }
+ return true;
+ };
+}
+
+PageContext.prototype = new Context();
+
+function SelectorContext(selector) {
+ let opts = apiUtils.validateOptions({ selector: selector }, {
+ selector: {
+ is: ["string"],
+ msg: "selector must be a string."
+ }
+ });
+
+ this.adjustPopupNode = function SelectorContext_adjustPopupNode(node) {
+ return closestMatchingAncestor(node);
+ };
+
+ this.isCurrent = function SelectorContext_isCurrent(popupNode) {
+ return !!closestMatchingAncestor(popupNode);
+ };
+
+ // Returns node if it matches selector, or the closest ancestor of node that
+ // matches, or null if node and none of its ancestors matches.
+ function closestMatchingAncestor(node) {
+ let cursor = node;
+ while (cursor) {
+ if (cursor.mozMatchesSelector(selector))
+ return cursor;
+ if (cursor instanceof Ci.nsIDOMHTMLHtmlElement)
+ break;
+ cursor = cursor.parentNode;
+ }
+ return null;
+ }
+}
+
+SelectorContext.prototype = new Context();
+
+function SelectionContext() {
+ this.isCurrent = function SelectionContext_isCurrent(popupNode) {
+ let win = popupNode.ownerDocument.defaultView;
+ if (!win)
+ return false;
+
+ let hasSelection = !win.getSelection().isCollapsed;
+ if (!hasSelection) {
+ // window.getSelection doesn't return a selection for text selected in a
+ // form field (see bug 85686), so before returning false we want to check
+ // if the popupNode is a text field.
+ let { selectionStart, selectionEnd } = popupNode;
+ hasSelection = !isNaN(selectionStart) &&
+ !isNaN(selectionEnd) &&
+ selectionStart !== selectionEnd;
+ }
+ return hasSelection;
+ };
+}
+
+SelectionContext.prototype = new Context();
+
+function URLContext(patterns) {
+ let opts = apiUtils.validateOptions({ patterns: patterns }, {
+ patterns: {
+ map: function (v) apiUtils.getTypeOf(v) === "array" ? v : [v],
+ ok: function (v) v.every(function (p) typeof(p) === "string"),
+ msg: "patterns must be a string or an array of strings."
+ }
+ });
+ try {
+ patterns = opts.patterns.map(function (p) new MatchPattern(p));
+ }
+ catch (err) {
+ console.error("Error creating URLContext match pattern:");
+ throw err;
+ }
+
+ const self = this;
+
+ this.isCurrent = function URLContext_isCurrent(popupNode) {
+ return self.isCurrentForURL(popupNode.ownerDocument.URL);
+ };
+
+ this.isCurrentForURL = function URLContext_isCurrentForURL(url) {
+ return patterns.some(function (p) p.test(url));
+ };
+}
+
+URLContext.prototype = new Context();
+
+exports.PageContext = apiUtils.publicConstructor(PageContext);
+exports.SelectorContext = apiUtils.publicConstructor(SelectorContext);
+exports.SelectionContext = apiUtils.publicConstructor(SelectionContext);
+exports.URLContext = apiUtils.publicConstructor(URLContext);
+
+
+// Returns a version of opt validated against the given rule.
+function validateOpt(opt, rule) {
+ return apiUtils.validateOptions({ opt: opt }, { opt: rule }).opt;
+}
+
+// Returns rules for apiUtils.validateOptions() common to Item and Menu.
+function optionsRules() {
+ return {
+ context: {
+ is: ["undefined", "object", "array"],
+ ok: function (v) {
+ if (!v)
+ return true;
+ let arr = apiUtils.getTypeOf(v) === "array" ? v : [v];
+ return arr.every(function (o) o instanceof Context);
+ },
+ msg: "The 'context' option must be a Context object or an array of " +
+ "Context objects."
+ },
+ label: {
+ map: function (v) v.toString(),
+ is: ["string"],
+ ok: function (v) !!v,
+ msg: "The item must have a non-empty string label."
+ },
+ image: {
+ map: function (v) v.toString(),
+ is: ["string", "undefined", "null"]
+ },
+ contentScript: {
+ is: ["string", "array", "undefined"],
+ ok: function (v) {
+ return apiUtils.getTypeOf(v) !== "array" ||
+ v.every(function (s) typeof(s) === "string");
+ }
+ },
+ contentScriptFile: {
+ is: ["string", "array", "undefined"],
+ ok: function (v) {
+ if (!v)
+ return true;
+ let arr = apiUtils.getTypeOf(v) === "array" ? v : [v];
+ try {
+ return arr.every(function (s) {
+ return apiUtils.getTypeOf(s) === "string" &&
+ URL(s).scheme === 'resource';
+ });
+ }
+ catch (err) {}
+ return false;
+ },
+ msg: "The 'contentScriptFile' option must be a local file URL or " +
+ "an array of local file URLs."
+ },
+ onMessage: {
+ is: ["function", "undefined"]
+ }
+ };
+}
+
+// Does a binary search on elts, a NodeList, and returns the DOM element
+// before which an item with targetLabel should be inserted. null is returned
+// if the new item should be inserted at the end.
+function insertionPoint(targetLabel, elts) {
+ let from = 0;
+ let to = elts.length - 1;
+
+ while (from <= to) {
+ let i = Math.floor((from + to) / 2);
+ let comp = targetLabel.localeCompare(elts[i].getAttribute("label"));
+ if (comp < 0)
+ to = i - 1;
+ else if (comp > 0)
+ from = i + 1;
+ else
+ return elts[i];
+ }
+ return elts[from] || null;
+}
+
+// Builds an ID suitable for a DOM element from the given item ID.
+// isInOverflowSubtree should be true if the returned element will be inserted
+// into the DOM subtree rooted at the overflow menu.
+function domEltIDFromItemID(itemID, isInOverflowSubtree) {
+ let suffix = isInOverflowSubtree ? "-overflow" : "";
+ return jpSelf.id + "-context-menu-item-" + itemID + suffix;
+}
+
+// Parses the item ID out of the given DOM element ID and returns it. If the
+// element's ID is malformed or it indicates that the element was not created by
+// the instance of the module calling this function, returns -1.
+function itemIDFromDOMEltID(domEltID) {
+ let match = /^(.+?)-context-menu-item-([0-9]+)[-a-z]*$/.exec(domEltID);
+ return !match || match[1] !== jpSelf.id ? -1 : match[2];
+}
+
+// Returns the private version of the given public reflection.
+function privateItem(publicItem) {
+ return publicItem.valueOf(PRIVATE_PROPS_KEY);
+}
+
+
+// A type of Worker tailored to our uses.
+const ContextMenuWorker = Worker.compose({
+ destroy: Worker.required,
+
+ // Returns true if any context listeners are defined in the worker's port.
+ anyContextListeners: function CMW_anyContextListeners() {
+ return this._contentWorker.hasListenerFor("context");
+ },
+
+ // Returns the first string or truthy value returned by a context listener in
+ // the worker's port. If none return a string or truthy value or if there are
+ // no context listeners, returns false. popupNode is the node that was
+ // context-clicked.
+ isAnyContextCurrent: function CMW_isAnyContextCurrent(popupNode) {
+ let results = this._contentWorker.emitSync("context", popupNode);
+ for (let i = 0; i < results.length; i++) {
+ let val = results[i];
+ if (typeof val === "string" || val)
+ return val;
+ }
+ return false;
+ },
+
+ // Emits a click event in the worker's port. popupNode is the node that was
+ // context-clicked, and clickedItemData is the data of the item that was
+ // clicked.
+ fireClick: function CMW_fireClick(popupNode, clickedItemData) {
+ this._contentWorker.emitSync("click", popupNode, clickedItemData);
+ }
+});
+
+
+// This class creates and stores content workers for pairs of menu items and
+// content windows. Use one instance for each item. Not all pairs need a
+// worker: if an item has a URL context that does not match a window's page,
+// then no worker is created for the pair.
+function WorkerRegistry(item) {
+ this.item = item;
+
+ // inner window ID => { win, worker }
+ this.winWorkers = {};
+
+ // inner window ID => content window
+ this.winsWithoutWorkers = {};
+}
+
+WorkerRegistry.prototype = {
+
+ // Registers a content window, creating a worker for it if it needs one.
+ registerContentWin: function WR_registerContentWin(win) {
+ let innerWinID = getInnerId(win);
+ if ((innerWinID in this.winWorkers) ||
+ (innerWinID in this.winsWithoutWorkers))
+ return;
+ if (this._doesURLNeedWorker(win.document.URL))
+ this.winWorkers[innerWinID] = { win: win, worker: this._makeWorker(win) };
+ else
+ this.winsWithoutWorkers[innerWinID] = win;
+ },
+
+ // Unregisters a content window, destroying its related worker if it has one.
+ unregisterContentWin: function WR_unregisterContentWin(innerWinID) {
+ if (innerWinID in this.winWorkers) {
+ let winWorker = this.winWorkers[innerWinID];
+ winWorker.worker.destroy();
+ delete winWorker.worker;
+ delete winWorker.win;
+ delete this.winWorkers[innerWinID];
+ }
+ else
+ delete this.winsWithoutWorkers[innerWinID];
+ },
+
+ // Creates a worker for each window that needs a worker but doesn't have one.
+ createNeededWorkers: function WR_createNeededWorkers() {
+ for (let [innerWinID, win] in Iterator(this.winsWithoutWorkers)) {
+ delete this.winsWithoutWorkers[innerWinID];
+ this.registerContentWin(win);
+ }
+ },
+
+ // Destroys the worker for each window that has a worker but doesn't need it.
+ destroyUnneededWorkers: function WR_destroyUnneededWorkers() {
+ for (let [innerWinID, winWorker] in Iterator(this.winWorkers)) {
+ if (!this._doesURLNeedWorker(winWorker.win.document.URL)) {
+ this.unregisterContentWin(innerWinID);
+ this.winsWithoutWorkers[innerWinID] = winWorker.win;
+ }
+ }
+ },
+
+ // Returns the worker for the item-window pair or null if none exists.
+ find: function WR_find(contentWin) {
+ let innerWinID = getInnerId(contentWin);
+ return (innerWinID in this.winWorkers) ?
+ this.winWorkers[innerWinID].worker :
+ null;
+ },
+
+ // Unregisters all content windows from the registry, which destroys all
+ // workers.
+ destroy: function WR_destroy() {
+ for (let innerWinID in this.winWorkers)
+ this.unregisterContentWin(innerWinID);
+ for (let innerWinID in this.winsWithoutWorkers)
+ this.unregisterContentWin(innerWinID);
+ },
+
+ // Returns false if the item has a URL context that does not match the given
+ // URL.
+ _doesURLNeedWorker: function WR__doesURLNeedWorker(url) {
+ for (let ctxt in this.item.context)
+ if ((ctxt instanceof URLContext) && !ctxt.isCurrentForURL(url))
+ return false;
+ return true;
+ },
+
+ _makeWorker: function WR__makeWorker(win) {
+ let worker = ContextMenuWorker({
+ window: win,
+ contentScript: this.item.contentScript,
+ contentScriptFile: this.item.contentScriptFile,
+ onError: function (err) console.exception(err)
+ });
+ let item = this.item;
+ worker.on("message", function workerOnMessage(msg) {
+ try {
+ privateItem(item)._emitOnObject(item, "message", msg);
+ }
+ catch (err) {
+ console.exception(err);
+ }
+ });
+ return worker;
+ }
+};
+
+
+// Mirrors state across all browser windows. Also responsible for detecting
+// all content window loads and unloads.
+let browserManager = {
+ topLevelItems: [],
+ browserWins: [],
+
+ // inner window ID => content window
+ contentWins: {},
+
+ // Call this when a new item is created, top-level or not.
+ registerItem: function BM_registerItem(item) {
+ this.browserWins.forEach(function (w) w.registerItem(item));
+ },
+
+ // Call this when an item is destroyed and won't be used again, top-level or
+ // not.
+ unregisterItem: function BM_unregisterItem(item) {
+ this.browserWins.forEach(function (w) w.unregisterItem(item));
+ },
+
+ addTopLevelItem: function BM_addTopLevelItem(item) {
+ this.topLevelItems.push(item);
+ this.browserWins.forEach(function (w) w.addTopLevelItem(item));
+
+ // Create the item's worker registry and register all currently loaded
+ // content windows with it.
+ let privates = privateItem(item);
+ privates._isTopLevel = true;
+ for each (let win in this.contentWins)
+ privates._workerReg.registerContentWin(win);
+ },
+
+ removeTopLevelItem: function BM_removeTopLevelItem(item) {
+ let idx = this.topLevelItems.indexOf(item);
+ if (idx < 0)
+ throw new Error("Internal error: item not in top-level menu: " + item);
+ this.topLevelItems.splice(idx, 1);
+ this.browserWins.forEach(function (w) w.removeTopLevelItem(item));
+ privateItem(item)._isTopLevel = false;
+ },
+
+ addItemToMenu: function BM_addItemToMenu(item, parentMenu) {
+ this.browserWins.forEach(function (w) w.addItemToMenu(item, parentMenu));
+ },
+
+ removeItemFromMenu: function BM_removeItemFromMenu(item, parentMenu) {
+ this.browserWins.forEach(function (w) w.removeItemFromMenu(item,
+ parentMenu));
+ },
+
+ setItemLabel: function BM_setItemLabel(item, label) {
+ this.browserWins.forEach(function (w) w.setItemLabel(item, label));
+ },
+
+ setItemImage: function BM_setItemImage(item, imageURL) {
+ this.browserWins.forEach(function (w) w.setItemImage(item, imageURL));
+ },
+
+ setItemData: function BM_setItemData(item, data) {
+ this.browserWins.forEach(function (w) w.setItemData(item, data));
+ },
+
+ // Note that calling this method will cause onTrack to be called immediately
+ // for each currently open browser window.
+ init: function BM_init() {
+ require("api-utils/unload").ensure(this);
+ let windowTracker = winUtils.WindowTracker(this);
+
+ // Register content windows on content-document-global-created and
+ // unregister them on inner-window-destroyed. For rationale, see bug 667957
+ // for the former and bug 642004 for the latter.
+ observerServ.add("content-document-global-created",
+ this._onDocGlobalCreated, this);
+ observerServ.add("inner-window-destroyed",
+ this._onInnerWinDestroyed, this);
+ },
+
+ _onDocGlobalCreated: function BM__onDocGlobalCreated(contentWin) {
+ let doc = contentWin.document;
+ if (doc.readyState == "loading") {
+ const self = this;
+ doc.addEventListener("readystatechange", function onReadyStateChange(e) {
+ if (e.target != doc || doc.readyState != "complete")
+ return;
+ doc.removeEventListener("readystatechange", onReadyStateChange, false);
+ self._registerContentWin(contentWin);
+ }, false);
+ }
+ else if (doc.readyState == "complete")
+ this._registerContentWin(contentWin);
+ },
+
+ _onInnerWinDestroyed: function BM__onInnerWinDestroyed(subj) {
+ this._unregisterContentWin(
+ subj.QueryInterface(Ci.nsISupportsPRUint64).data);
+ },
+
+ // Stores the given content window with the manager and registers it with each
+ // top-level item's worker registry.
+ _registerContentWin: function BM__registerContentWin(win) {
+ let innerID = getInnerId(win);
+
+ // It's an error to call this method for the same window more than once, but
+ // we allow it in one case: when onTrack races _onDocGlobalCreated. (See
+ // the comment in onTrack.) Make sure the window is registered only once.
+ if (innerID in this.contentWins)
+ return;
+
+ this.contentWins[innerID] = win;
+ this.topLevelItems.forEach(function (item) {
+ privateItem(item)._workerReg.registerContentWin(win);
+ });
+ },
+
+ // Removes the given content window from the manager and unregisters it from
+ // each top-level item's worker registry.
+ _unregisterContentWin: function BM__unregisterContentWin(innerID) {
+ delete this.contentWins[innerID];
+ this.topLevelItems.forEach(function (item) {
+ privateItem(item)._workerReg.unregisterContentWin(innerID);
+ });
+ },
+
+ unload: function BM_unload() {
+ // The window tracker is unloaded at the same time this method is called,
+ // which causes onUntrack to be called for each open browser window, so
+ // there's no need to clean up browser windows here.
+
+ while (this.topLevelItems.length) {
+ let item = this.topLevelItems[0];
+ this.removeTopLevelItem(item);
+ this.unregisterItem(item);
+ }
+ delete this.contentWins;
+ },
+
+ // Registers a browser window with the manager. This is a WindowTracker
+ // callback. Note that this is called in two cases: for each newly opened
+ // chrome window, and for each chrome window that is open when the loader
+ // loads this module.
+ onTrack: function BM_onTrack(window) {
+ if (!this._isBrowserWindow(window))
+ return;
+
+ let browserWin = new BrowserWindow(window);
+ this.browserWins.push(browserWin);
+
+ // Register all loaded content windows in the browser window. Be sure to
+ // include frames and iframes. If onTrack is called as a result of a new
+ // browser window being opened, as opposed to the module being loaded, then
+ // this will race the content-document-global-created notification. That's
+ // OK, since _registerContentWin will not register the same content window
+ // more than once.
+ window.gBrowser.browsers.forEach(function (browser) {
+ let topContentWin = browser.contentWindow;
+ let allContentWins = Array.slice(topContentWin.frames);
+ allContentWins.push(topContentWin);
+ allContentWins.forEach(function (contentWin) {
+ if (contentWin.document.readyState == "complete")
+ this._registerContentWin(contentWin);
+ }, this);
+ }, this);
+
+ // Add all top-level items and, recursively, their child items to the new
+ // browser window.
+ function addItemTree(item, parentMenu) {
+ browserWin.registerItem(item);
+ if (parentMenu)
+ browserWin.addItemToMenu(item, parentMenu);
+ else
+ browserWin.addTopLevelItem(item);
+ if (item instanceof Menu)
+ item.items.forEach(function (subitem) addItemTree(subitem, item));
+ }
+ this.topLevelItems.forEach(function (item) addItemTree(item, null));
+ },
+
+ // Unregisters a browser window from the manager. This is a WindowTracker
+ // callback. Note that this is called in two cases: for each newly closed
+ // chrome window, and for each chrome window that is open when this module is
+ // unloaded.
+ onUntrack: function BM_onUntrack(window) {
+ if (!this._isBrowserWindow(window))
+ return;
+
+ // Remove the window from the window list.
+ let idx = 0;
+ for (; idx < this.browserWins.length; idx++)
+ if (this.browserWins[idx].window == window)
+ break;
+ if (idx == this.browserWins.length)
+ throw new Error("Internal error: browser window not found");
+ let browserWin = this.browserWins.splice(idx, 1)[0];
+
+ // Remove all top-level items from the window.
+ this.topLevelItems.forEach(function (i) browserWin.removeTopLevelItem(i));
+ browserWin.destroy();
+ },
+
+ _isBrowserWindow: function BM__isBrowserWindow(win) {
+ let winType = win.document.documentElement.getAttribute("windowtype");
+ return winType === "navigator:browser";
+ }
+};
+
+
+// Responsible for creating and managing context menu item DOM elements for a
+// browser window. Also responsible for providing a description of the window's
+// current context and determining whether an item matches the current context.
+//
+// TODO: If other apps besides Firefox want to support the context menu in
+// whatever way is appropriate for them, plugging in a substitute for or an
+// adapter to this class should be the way to do it. Make it easy for them.
+// See bug 560716.
+function BrowserWindow(window) {
+ this.window = window;
+ this.doc = window.document;
+
+ let popupDOMElt = this.doc.getElementById("contentAreaContextMenu");
+ if (!popupDOMElt)
+ throw new Error("Internal error: Context menu popup not found.");
+ this.contextMenuPopup = new ContextMenuPopup(popupDOMElt, this);
+
+ // item ID => { item, domElt, overflowDOMElt, popup, overflowPopup }
+ // item may or may not be top-level. domElt is the item's DOM element
+ // contained in the subtree rooted in the top-level context menu.
+ // overflowDOMElt is the item's DOM element contained in the subtree rooted in
+ // the overflow submenu. popup and overflowPopup are only defined if the item
+ // is a Menu; they're the Popup instances containing the Menu's child items,
+ // with the aforementioned distinction between top-level and overflow
+ // subtrees.
+ this.items = {};
+}
+
+BrowserWindow.prototype = {
+
+ // Creates and stores DOM elements for the given item, top-level or not.
+ registerItem: function BW_registerItem(item) {
+ // this.items[id] is referenced by _makeMenu, so it needs to be defined
+ // before _makeDOMElt is called.
+ let props = { item: item };
+ this.items[privateItem(item)._id] = props;
+ props.domElt = this._makeDOMElt(item, false);
+ props.overflowDOMElt = this._makeDOMElt(item, true);
+ },
+
+ // Removes the given item's DOM elements from the store.
+ unregisterItem: function BW_unregisterItem(item) {
+ delete this.items[privateItem(item)._id];
+ },
+
+ addTopLevelItem: function BW_addTopLevelItem(item) {
+ this.contextMenuPopup.addItem(item);
+ },
+
+ removeTopLevelItem: function BW_removeTopLevelItem(item) {
+ this.contextMenuPopup.removeItem(item);
+ },
+
+ addItemToMenu: function BW_addItemToMenu(item, parentMenu) {
+ let { popup, overflowPopup } = this.items[privateItem(parentMenu)._id];
+ popup.addItem(item);
+ overflowPopup.addItem(item);
+ },
+
+ removeItemFromMenu: function BW_removeItemFromMenu(item, parentMenu) {
+ let { popup, overflowPopup } = this.items[privateItem(parentMenu)._id];
+ popup.removeItem(item);
+ overflowPopup.removeItem(item);
+ },
+
+ setItemLabel: function BW_setItemLabel(item, label) {
+ let privates = privateItem(item);
+ let { domElt, overflowDOMElt } = this.items[privates._id];
+ this._setDOMEltLabel(domElt, label);
+ this._setDOMEltLabel(overflowDOMElt, label);
+ if (!item.parentMenu && privates._hasFinishedInit)
+ this.contextMenuPopup.itemLabelDidChange(item);
+ },
+
+ _setDOMEltLabel: function BW__setDOMEltLabel(domElt, label) {
+ domElt.setAttribute("label", label);
+ },
+
+ setItemImage: function BW_setItemImage(item, imageURL) {
+ let { domElt, overflowDOMElt } = this.items[privateItem(item)._id];
+ let isMenu = item instanceof Menu;
+ this._setDOMEltImage(domElt, imageURL, isMenu);
+ this._setDOMEltImage(overflowDOMElt, imageURL, isMenu);
+ },
+
+ _setDOMEltImage: function BW__setDOMEltImage(domElt, imageURL, isMenu) {
+ if (!imageURL) {
+ domElt.removeAttribute("image");
+ domElt.classList.remove("menu-iconic");
+ domElt.classList.remove("menuitem-iconic");
+ }
+ else {
+ domElt.setAttribute("image", imageURL);
+ domElt.classList.add(isMenu ? "menu-iconic" : "menuitem-iconic");
+ }
+ },
+
+ setItemData: function BW_setItemData(item, data) {
+ let { domElt, overflowDOMElt } = this.items[privateItem(item)._id];
+ this._setDOMEltData(domElt, data);
+ this._setDOMEltData(overflowDOMElt, data);
+ },
+
+ _setDOMEltData: function BW__setDOMEltData(domElt, data) {
+ domElt.setAttribute("value", data);
+ },
+
+ // The context specified for a top-level item may not match exactly the real
+ // context that triggers it. For example, if the user context-clicks a span
+ // inside an anchor, we want items that specify an anchor context to be
+ // triggered, but the real context will indicate that the span was clicked,
+ // not the anchor. Where the real context and an item's context conflict,
+ // clients should be given the item's context, and this method can be used to
+ // make such adjustments. Returns an adjusted popupNode.
+ adjustPopupNode: function BW_adjustPopupNode(popupNode, topLevelItem) {
+ for (let ctxt in topLevelItem.context) {
+ if (typeof(ctxt.adjustPopupNode) === "function") {
+ let ctxtNode = ctxt.adjustPopupNode(popupNode);
+ if (ctxtNode) {
+ popupNode = ctxtNode;
+ break;
+ }
+ }
+ }
+ return popupNode;
+ },
+
+ // Returns true if all of item's contexts are current in the window.
+ areAllContextsCurrent: function BW_areAllContextsCurrent(item, popupNode) {
+ let win = popupNode.ownerDocument.defaultView;
+ let worker = privateItem(item)._workerReg.find(win);
+
+ // If the worker for the item-window pair doesn't exist (e.g., because the
+ // page hasn't loaded yet), we can't really make a good decision since the
+ // content script may have a context listener. So just don't show the item
+ // at all.
+ if (!worker)
+ return false;
+
+ // If there are no contexts given at all, the page context applies.
+ let hasContentContext = worker.anyContextListeners();
+ if (!hasContentContext && !item.context.length)
+ return new PageContext().isCurrent(popupNode);
+
+ // Otherwise, determine if all given contexts are current. Evaluate the
+ // declarative contexts first and the worker's context listeners last. That
+ // way the listener might be able to avoid some work.
+ let curr = true;
+ for (let ctxt in item.context) {
+ curr = curr && ctxt.isCurrent(popupNode);
+ if (!curr)
+ return false;
+ }
+ return !hasContentContext || worker.isAnyContextCurrent(popupNode);
+ },
+
+ // Returns the node the user context-clicked to invoke the context menu.
+ // For Gecko 2.0 and later, triggerNode is this node;
+ // if it's falsey, document.popupNode is used.
+ capturePopupNode: function BW_capturePopupNode(triggerNode) {
+ var popupNode = triggerNode || this.doc.popupNode;
+ if (!popupNode)
+ console.warn("popupNode is null.");
+ return popupNode;
+ },
+
+ destroy: function BW_destroy() {
+ this.contextMenuPopup.destroy();
+ delete this.window;
+ delete this.doc;
+ delete this.items;
+ },
+
+ // Emits a click event in the port of the content worker related to given top-
+ // level item and popupNode's content window. Listeners will be passed
+ // popupNode and clickedItemData.
+ fireClick: function BW_fireClick(topLevelItem, popupNode, clickedItemData) {
+ let win = popupNode.ownerDocument.defaultView;
+ let worker = privateItem(topLevelItem)._workerReg.find(win);
+ if (worker)
+ worker.fireClick(popupNode, clickedItemData);
+ },
+
+ _makeDOMElt: function BW__makeDOMElt(item, isInOverflowSubtree) {
+ let elt = item instanceof Item ? this._makeMenuitem(item) :
+ item instanceof Menu ? this._makeMenu(item, isInOverflowSubtree) :
+ item instanceof Separator ? this._makeSeparator() :
+ null;
+ if (!elt)
+ throw new Error("Internal error: can't make element, unknown item type");
+
+ elt.id = domEltIDFromItemID(privateItem(item)._id, isInOverflowSubtree);
+ elt.classList.add(ITEM_CLASS);
+ return elt;
+ },
+
+ // Returns a new xul:menu representing the menu.
+ _makeMenu: function BW__makeMenu(menu, isInOverflowSubtree) {
+ let menuElt = this.doc.createElement("menu");
+ this._setDOMEltLabel(menuElt, menu.label);
+ if (menu.image)
+ this._setDOMEltImage(menuElt, menu.image, true);
+ let popupElt = this.doc.createElement("menupopup");
+ menuElt.appendChild(popupElt);
+
+ let popup = new Popup(popupElt, this, isInOverflowSubtree);
+ let props = this.items[privateItem(menu)._id];
+ if (isInOverflowSubtree)
+ props.overflowPopup = popup;
+ else
+ props.popup = popup;
+
+ return menuElt;
+ },
+
+ // Returns a new xul:menuitem representing the item.
+ _makeMenuitem: function BW__makeMenuitem(item) {
+ let elt = this.doc.createElement("menuitem");
+ this._setDOMEltLabel(elt, item.label);
+ if (item.image)
+ this._setDOMEltImage(elt, item.image, false);
+ if (item.data)
+ this._setDOMEltData(elt, item.data);
+ return elt;
+ },
+
+ // Returns a new xul:menuseparator.
+ _makeSeparator: function BW__makeSeparator() {
+ return this.doc.createElement("menuseparator");
+ }
+};
+
+
+// Responsible for adding DOM elements to and removing them from poupDOMElt.
+function Popup(popupDOMElt, browserWin, isInOverflowSubtree) {
+ this.popupDOMElt = popupDOMElt;
+ this.browserWin = browserWin;
+ this.isInOverflowSubtree = isInOverflowSubtree;
+}
+
+Popup.prototype = {
+
+ addItem: function Popup_addItem(item) {
+ let props = this.browserWin.items[privateItem(item)._id];
+ let elt = this.isInOverflowSubtree ? props.overflowDOMElt : props.domElt;
+ this.popupDOMElt.appendChild(elt);
+ },
+
+ removeItem: function Popup_removeItem(item) {
+ let props = this.browserWin.items[privateItem(item)._id];
+ let elt = this.isInOverflowSubtree ? props.overflowDOMElt : props.domElt;
+ this.popupDOMElt.removeChild(elt);
+ }
+};
+
+
+// Represents a browser window's context menu popup. Responsible for hiding and
+// showing items according to the browser window's current context and for
+// handling item clicks.
+function ContextMenuPopup(popupDOMElt, browserWin) {
+ this.popupDOMElt = popupDOMElt;
+ this.browserWin = browserWin;
+ this.doc = popupDOMElt.ownerDocument;
+
+ // item ID => item
+ // Calling this variable "topLevelItems" is redundant, since Popup and
+ // ContextMenuPopup are only responsible for their child items, not all their
+ // descendant items. But calling it "items" might encourage one to believe
+ // otherwise, so topLevelItems it is.
+ this.topLevelItems = {};
+
+ popupDOMElt.addEventListener("popupshowing", this, false);
+ popupDOMElt.addEventListener("command", this, false);
+}
+
+ContextMenuPopup.prototype = {
+
+ addItem: function CMP_addItem(item) {
+ this._ensureStaticEltsExist();
+ let itemID = privateItem(item)._id;
+ this.topLevelItems[itemID] = item;
+ let props = this.browserWin.items[itemID];
+ props.domElt.classList.add(TOPLEVEL_ITEM_CLASS);
+ props.overflowDOMElt.classList.add(OVERFLOW_ITEM_CLASS);
+ this._insertItemInSortedOrder(item);
+ },
+
+ removeItem: function CMP_removeItem(item) {
+ let itemID = privateItem(item)._id;
+ delete this.topLevelItems[itemID];
+ let { domElt, overflowDOMElt } = this.browserWin.items[itemID];
+ domElt.classList.remove(TOPLEVEL_ITEM_CLASS);
+ overflowDOMElt.classList.remove(OVERFLOW_ITEM_CLASS);
+ this.popupDOMElt.removeChild(domElt);
+ this._overflowPopup.removeChild(overflowDOMElt);
+ },
+
+ // Call this after the item's label changes. This re-inserts the item into
+ // the popup so that it remains in sorted order.
+ itemLabelDidChange: function CMP_itemLabelDidChange(item) {
+ let itemID = privateItem(item)._id;
+ let { domElt, overflowDOMElt } = this.browserWin.items[itemID];
+ this.popupDOMElt.removeChild(domElt);
+ this._overflowPopup.removeChild(overflowDOMElt);
+ this._insertItemInSortedOrder(item);
+ },
+
+ destroy: function CMP_destroy() {
+ // If there are no more items from any instance of the module, remove the
+ // separator and overflow submenu, if they exist.
+ let elts = this._topLevelElts;
+ if (!elts.length) {
+ let submenu = this._overflowMenu;
+ if (submenu)
+ this.popupDOMElt.removeChild(submenu);
+
+ let sep = this._separator;
+ if (sep)
+ this.popupDOMElt.removeChild(sep);
+ }
+
+ this.popupDOMElt.removeEventListener("popupshowing", this, false);
+ this.popupDOMElt.removeEventListener("command", this, false);
+ },
+
+ handleEvent: function CMP_handleEvent(event) {
+ try {
+ if (event.type === "command")
+ this._handleClick(event.target);
+ else if (event.type === "popupshowing" &&
+ event.target === this.popupDOMElt)
+ this._handlePopupShowing();
+ }
+ catch (err) {
+ console.exception(err);
+ }
+ },
+
+ // command events bubble to the context menu's top-level xul:menupopup and are
+ // caught here.
+ _handleClick: function CMP__handleClick(clickedDOMElt) {
+ if (!clickedDOMElt.classList.contains(ITEM_CLASS))
+ return;
+ let itemID = itemIDFromDOMEltID(clickedDOMElt.id);
+ if (itemID < 0)
+ return;
+ let { item, domElt, overflowDOMElt } = this.browserWin.items[itemID];
+
+ // Bail if the DOM element was not created by this module instance. In
+ // real-world add-ons, the itemID < 0 check above is sufficient, but for the
+ // unit test the JID never changes, making this necessary.
+ if (clickedDOMElt != domElt && clickedDOMElt != overflowDOMElt)
+ return;
+
+ let topLevelItem = privateItem(item)._topLevelItem;
+ let popupNode = this.browserWin.adjustPopupNode(this._getPopupNode(),
+ topLevelItem);
+ this.browserWin.fireClick(topLevelItem, popupNode, item.data);
+ },
+
+ _getPopupNode: function CMP__getPopupNode() {
+ // popupDOMElt.triggerNode was added in Gecko 2.0 by bug 383930. The || is
+ // to avoid a Spidermonkey strict warning on earlier versions.
+ let triggerNode = this.popupDOMElt.triggerNode || undefined;
+ return this.browserWin.capturePopupNode(triggerNode);
+ },
+
+ // popupshowing is used to show top-level items that match the browser
+ // window's current context and hide items that don't. Each module instance
+ // is responsible for showing and hiding the items it owns.
+ _handlePopupShowing: function CMP__handlePopupShowing() {
+
+ // If there are items queued up to finish initializing, let them go first.
+ // Otherwise the overflow submenu and menu separator may end up in an
+ // inappropriate state when those items are later added to the menu.
+ if (numItemsWithUnfinishedInit) {
+ const self = this;
+ timer.setTimeout(function popupShowingTryAgain() {
+ self._handlePopupShowing();
+ }, 0);
+ return;
+ }
+
+ let popupNode = this._getPopupNode();
+ // Show and hide items. Set a "jetpackContextCurrent" property on the
+ // DOM elements to signal which of our items match the current context.
+ for (let [itemID, item] in Iterator(this.topLevelItems)) {
+ let areContextsCurr =
+ this.browserWin.areAllContextsCurrent(item, popupNode);
+
+ // Change the item's label if the return value was a string.
+ if (typeof(areContextsCurr) === "string") {
+ item.label = areContextsCurr;
+ areContextsCurr = true;
+ }
+
+ let { domElt, overflowDOMElt } = this.browserWin.items[itemID];
+ domElt.jetpackContextCurrent = areContextsCurr;
+ domElt.hidden = !areContextsCurr;
+ overflowDOMElt.jetpackContextCurrent = areContextsCurr;
+ overflowDOMElt.hidden = !areContextsCurr;
+ }
+
+ // Get the total number of items that match the current context. It's a
+ // little tricky: There may be other instances of this module loaded,
+ // each hiding and showing their items. So we can't base this number on
+ // only our items, or on the hidden state of items. That's why we set
+ // the jetpackContextCurrent property above. The last instance to run
+ // will leave the menupopup in the correct state.
+ let elts = this._topLevelElts;
+ let numShown = Array.reduce(elts, function (total, elt) {
+ return total + (elt.jetpackContextCurrent ? 1 : 0);
+ }, 0);
+
+ // If too many items are shown, show the submenu and hide the top-level
+ // items. Otherwise, hide the submenu and show the top-level items.
+ let overflow = numShown > this._overflowThreshold;
+ if (overflow)
+ Array.forEach(elts, function (e) e.hidden = true);
+
+ let submenu = this._overflowMenu;
+ if (submenu)
+ submenu.hidden = !overflow;
+
+ // If no items are shown, hide the menu separator.
+ let sep = this._separator;
+ if (sep)
+ sep.hidden = numShown === 0;
+ },
+
+ // Adds the menu separator and overflow submenu if they don't exist.
+ _ensureStaticEltsExist: function CMP__ensureStaticEltsExist() {
+ let sep = this._separator;
+ if (!sep) {
+ sep = this._makeSeparator();
+ this.popupDOMElt.appendChild(sep);
+ }
+
+ let submenu = this._overflowMenu;
+ if (!submenu) {
+ submenu = this._makeOverflowMenu();
+ submenu.hidden = true;
+ this.popupDOMElt.insertBefore(submenu, sep.nextSibling);
+ }
+ },
+
+ // Inserts the given item's DOM element into the popup in sorted order.
+ _insertItemInSortedOrder: function CMP__insertItemInSortedOrder(item) {
+ let props = this.browserWin.items[privateItem(item)._id];
+ this.popupDOMElt.insertBefore(
+ props.domElt, insertionPoint(item.label, this._topLevelElts));
+ this._overflowPopup.insertBefore(
+ props.overflowDOMElt, insertionPoint(item.label, this._overflowElts));
+ },
+
+ // Creates and returns the xul:menu that's shown when too many items are added
+ // to the popup.
+ _makeOverflowMenu: function CMP__makeOverflowMenu() {
+ let submenu = this.doc.createElement("menu");
+ submenu.id = OVERFLOW_MENU_ID;
+ submenu.setAttribute("label", OVERFLOW_MENU_LABEL);
+ let popup = this.doc.createElement("menupopup");
+ popup.id = OVERFLOW_POPUP_ID;
+ submenu.appendChild(popup);
+ return submenu;
+ },
+
+ // Creates and returns the xul:menuseparator that separates the standard
+ // context menu items from our items.
+ _makeSeparator: function CMP__makeSeparator() {
+ let elt = this.doc.createElement("menuseparator");
+ elt.id = SEPARATOR_ID;
+ return elt;
+ },
+
+ // Returns the item elements contained in the overflow menu, a NodeList.
+ get _overflowElts() {
+ return this._overflowPopup.getElementsByClassName(OVERFLOW_ITEM_CLASS);
+ },
+
+ // Returns the overflow xul:menu.
+ get _overflowMenu() {
+ return this.doc.getElementById(OVERFLOW_MENU_ID);
+ },
+
+ // Returns the overflow xul:menupopup.
+ get _overflowPopup() {
+ return this.doc.getElementById(OVERFLOW_POPUP_ID);
+ },
+
+ // Returns the OVERFLOW_THRESH_PREF pref value if it exists or
+ // OVERFLOW_THRESH_DEFAULT if it doesn't.
+ get _overflowThreshold() {
+ let prefs = require("api-utils/preferences-service");
+ return prefs.get(OVERFLOW_THRESH_PREF, OVERFLOW_THRESH_DEFAULT);
+ },
+
+ // Returns the xul:menuseparator.
+ get _separator() {
+ return this.doc.getElementById(SEPARATOR_ID);
+ },
+
+ // Returns the item elements contained in the top-level menu, a NodeList.
+ get _topLevelElts() {
+ return this.popupDOMElt.getElementsByClassName(TOPLEVEL_ITEM_CLASS);
+ }
+};
+
+
+// Init the browserManager only after setting prototypes and such above, because
+// it will cause browserManager.onTrack to be called immediately if there are
+// open windows.
+browserManager.init();
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/lib/hotkeys.js b/tools/addon-sdk-1.7/packages/addon-kit/lib/hotkeys.js
new file mode 100644
index 0000000..f864f1f
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/lib/hotkeys.js
@@ -0,0 +1,37 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const INVALID_HOTKEY = "Hotkey must have at least one modifier.";
+
+const { toJSON: jsonify, toString: stringify,
+ isFunctionKey } = require("api-utils/keyboard/utils");
+const { register, unregister } = require("api-utils/keyboard/hotkeys");
+
+const Hotkey = exports.Hotkey = function Hotkey(options) {
+ if (!(this instanceof Hotkey))
+ return new Hotkey(options);
+
+ // Parsing key combination string.
+ let hotkey = jsonify(options.combo);
+ if (!isFunctionKey(hotkey.key) && !hotkey.modifiers.length) {
+ throw new TypeError(INVALID_HOTKEY);
+ }
+
+ this.onPress = options.onPress;
+ this.toString = stringify.bind(null, hotkey);
+ // Registering listener on keyboard combination enclosed by this hotkey.
+ // Please note that `this.toString()` is a normalized version of
+ // `options.combination` where order of modifiers is sorted and `accel` is
+ // replaced with platform specific key.
+ register(this.toString(), this.onPress);
+ // We freeze instance before returning it in order to make it's properties
+ // read-only.
+ return Object.freeze(this);
+};
+Hotkey.prototype.destroy = function destroy() {
+ unregister(this.toString(), this.onPress);
+};
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/lib/l10n.js b/tools/addon-sdk-1.7/packages/addon-kit/lib/l10n.js
new file mode 100644
index 0000000..198f711
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/lib/l10n.js
@@ -0,0 +1,149 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const { Cc, Ci } = require("chrome");
+const { getPreferedLocales, findClosestLocale } = require("api-utils/l10n/locale");
+const { getRulesForLocale } = require("api-utils/l10n/plural-rules");
+
+// Get URI for the addon root folder:
+const { rootURI } = require("@packaging");
+
+let globalHash = {};
+let pluralMappingFunction = getRulesForLocale("en");
+
+exports.get = function get(k) {
+
+ // For now, we only accept a "string" as first argument
+ // TODO: handle plural forms in gettext pattern
+ if (typeof k !== "string")
+ throw new Error("First argument of localization method should be a string");
+
+ // Get translation from big hashmap or default to hard coded string:
+ let localized = globalHash[k] || k;
+
+ // # Simplest usecase:
+ // // String hard coded in source code:
+ // _("Hello world")
+ // // Identifier of a key stored in properties file
+ // _("helloString")
+ if (arguments.length <= 1)
+ return localized;
+
+ let args = arguments;
+
+ if (typeof localized == "object" && "other" in localized) {
+ // # Plural form:
+ // // Strings hard coded in source code:
+ // _(["One download", "%d downloads"], 10);
+ // // Identifier of a key stored in properties file
+ // _("downloadNumber", 0);
+ let n = arguments[1];
+
+ // First handle simple universal forms that may not be mandatory
+ // for each language, (i.e. not different than 'other' form,
+ // but still usefull for better phrasing)
+ // For example 0 in english is the same form than 'other'
+ // but we accept 'zero' form if specified in localization file
+ if (n === 0 && "zero" in localized)
+ localized = localized["zero"];
+ else if (n === 1 && "one" in localized)
+ localized = localized["one"];
+ else if (n === 2 && "two" in localized)
+ localized = localized["two"];
+ else {
+ let pluralForm = pluralMappingFunction(n);
+ if (pluralForm in localized)
+ localized = localized[pluralForm];
+ else // Fallback in case of error: missing plural form
+ localized = localized["other"];
+ }
+
+ // Simulate a string with one placeholder:
+ args = [null, n];
+ }
+
+ // # String with placeholders:
+ // // Strings hard coded in source code:
+ // _("Hello %s", username)
+ // // Identifier of a key stored in properties file
+ // _("helloString", username)
+ // * We supports `%1s`, `%2s`, ... pattern in order to change arguments order
+ // in translation.
+ // * In case of plural form, we has `%d` instead of `%s`.
+ let offset = 1;
+ localized = localized.replace(/%(\d*)(s|d)/g, function (v, n) {
+ let rv = args[n != "" ? n : offset];
+ offset++;
+ return rv;
+ });
+
+ return localized;
+}
+
+function readURI(uri) {
+ let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
+ createInstance(Ci.nsIXMLHttpRequest);
+ request.open('GET', uri, false);
+ request.overrideMimeType('text/plain');
+ request.send();
+ return request.responseText;
+}
+
+function readJsonUri(uri) {
+ try {
+ return JSON.parse(readURI(uri));
+ }
+ catch(e) {
+ console.error("Error while reading locale file:\n" + uri + "\n" + e);
+ }
+ return {};
+}
+
+// Returns the array stored in `locales.json` manifest that list available
+// locales files
+function getAvailableLocales() {
+ let uri = rootURI + "locales.json";
+ let manifest = readJsonUri(uri);
+
+ return "locales" in manifest && Array.isArray(manifest.locales) ?
+ manifest.locales : [];
+}
+
+// Returns URI of the best locales file to use from the XPI
+function getBestLocaleFile() {
+
+ // Read localization manifest file that contains list of available languages
+ let availableLocales = getAvailableLocales();
+
+ // Retrieve list of prefered locales to use
+ let preferedLocales = getPreferedLocales();
+
+ // Compute the most preferable locale to use by using these two lists
+ let bestMatchingLocale = findClosestLocale(availableLocales, preferedLocales);
+
+ // It may be null if the addon doesn't have any locale file
+ if (!bestMatchingLocale)
+ return null;
+
+ // Retrieve the related plural mapping function
+ let shortLocaleCode = bestMatchingLocale.split("-")[0].toLowerCase();
+ pluralMappingFunction = getRulesForLocale(shortLocaleCode);
+
+ return rootURI + "locale/" + bestMatchingLocale + ".json";
+}
+
+function init() {
+ // First, search for a locale file:
+ let localeURI = getBestLocaleFile();
+ if (!localeURI)
+ return;
+
+ // Locale files only contains one big JSON object that is used as
+ // an hashtable of: "key to translate" => "translated key"
+ // TODO: We are likely to change this in order to be able to overload
+ // a specific key translation. For a specific package, module or line?
+ globalHash = readJsonUri(localeURI);
+}
+init();
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/lib/notifications.js b/tools/addon-sdk-1.7/packages/addon-kit/lib/notifications.js
new file mode 100644
index 0000000..8e66355
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/lib/notifications.js
@@ -0,0 +1,79 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim:set ts=2 sw=2 sts=2 et filetype=javascript
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Cc, Ci, Cr } = require("chrome");
+const apiUtils = require("api-utils/api-utils");
+const errors = require("api-utils/errors");
+
+try {
+ let alertServ = Cc["@mozilla.org/alerts-service;1"].
+ getService(Ci.nsIAlertsService);
+
+ // The unit test sets this to a mock notification function.
+ var notify = alertServ.showAlertNotification.bind(alertServ);
+}
+catch (err) {
+ // An exception will be thrown if the platform doesn't provide an alert
+ // service, e.g., if Growl is not installed on OS X. In that case, use a
+ // mock notification function that just logs to the console.
+ notify = notifyUsingConsole;
+}
+
+exports.notify = function notifications_notify(options) {
+ let valOpts = validateOptions(options);
+ let clickObserver = !valOpts.onClick ? null : {
+ observe: function notificationClickObserved(subject, topic, data) {
+ if (topic === "alertclickcallback")
+ errors.catchAndLog(valOpts.onClick).call(exports, valOpts.data);
+ }
+ };
+ function notifyWithOpts(notifyFn) {
+ notifyFn(valOpts.iconURL, valOpts.title, valOpts.text, !!clickObserver,
+ valOpts.data, clickObserver);
+ }
+ try {
+ notifyWithOpts(notify);
+ }
+ catch (err if err instanceof Ci.nsIException &&
+ err.result == Cr.NS_ERROR_FILE_NOT_FOUND) {
+ console.warn("The notification icon named by " + valOpts.iconURL +
+ " does not exist. A default icon will be used instead.");
+ delete valOpts.iconURL;
+ notifyWithOpts(notify);
+ }
+ catch (err) {
+ notifyWithOpts(notifyUsingConsole);
+ }
+};
+
+function notifyUsingConsole(iconURL, title, text) {
+ title = title ? "[" + title + "]" : "";
+ text = text || "";
+ let str = [title, text].filter(function (s) s).join(" ");
+ console.log(str);
+}
+
+function validateOptions(options) {
+ return apiUtils.validateOptions(options, {
+ data: {
+ is: ["string", "undefined"]
+ },
+ iconURL: {
+ is: ["string", "undefined"]
+ },
+ onClick: {
+ is: ["function", "undefined"]
+ },
+ text: {
+ is: ["string", "undefined"]
+ },
+ title: {
+ is: ["string", "undefined"]
+ }
+ });
+}
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/lib/page-mod.js b/tools/addon-sdk-1.7/packages/addon-kit/lib/page-mod.js
new file mode 100644
index 0000000..2cc75f9
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/lib/page-mod.js
@@ -0,0 +1,319 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const observers = require("api-utils/observer-service");
+const { Worker, Loader } = require('api-utils/content');
+const { EventEmitter } = require('api-utils/events');
+const { List } = require('api-utils/list');
+const { Registry } = require('api-utils/utils/registry');
+const xulApp = require("api-utils/xul-app");
+const { MatchPattern } = require('api-utils/match-pattern');
+const { validateOptions : validate } = require('api-utils/api-utils');
+const { validationAttributes } = require('api-utils/content/loader');
+const { Cc, Ci } = require('chrome');
+const { merge } = require('api-utils/utils/object');
+
+// Whether or not the host application dispatches a document-element-inserted
+// notification when the document element is inserted into the DOM of a page.
+// The notification was added in Gecko 2.0b6, it's a better time to attach
+// scripts with contentScriptWhen "start" than content-document-global-created,
+// since libraries like jQuery assume the presence of the document element.
+const HAS_DOCUMENT_ELEMENT_INSERTED =
+ xulApp.versionInRange(xulApp.platformVersion, "2.0b6", "*");
+const ON_CONTENT = HAS_DOCUMENT_ELEMENT_INSERTED ? 'document-element-inserted' :
+ 'content-document-global-created';
+
+// Workaround bug 642145: document-element-inserted is fired multiple times.
+// This bug is fixed in Firefox 4.0.1, but we want to keep FF 4.0 compatibility
+// Tracking bug 641457. To be removed when 4.0 has disappeared from earth.
+const HAS_BUG_642145_FIXED =
+ xulApp.versionInRange(xulApp.platformVersion, "2.0.1", "*");
+
+const styleSheetService = Cc["@mozilla.org/content/style-sheet-service;1"].
+ getService(Ci.nsIStyleSheetService);
+
+const USER_SHEET = styleSheetService.USER_SHEET;
+
+const io = Cc['@mozilla.org/network/io-service;1'].
+ getService(Ci.nsIIOService);
+
+// contentStyle* / contentScript* are sharing the same validation constraints,
+// so they can be mostly reused, except for the messages.
+const validStyleOptions = {
+ contentStyle: merge(Object.create(validationAttributes.contentScript), {
+ msg: 'The `contentStyle` option must be a string or an array of strings.'
+ }),
+ contentStyleFile: merge(Object.create(validationAttributes.contentScriptFile), {
+ msg: 'The `contentStyleFile` option must be a local URL or an array of URLs'
+ })
+};
+
+// rules registry
+const RULES = {};
+
+const Rules = EventEmitter.resolve({ toString: null }).compose(List, {
+ add: function() Array.slice(arguments).forEach(function onAdd(rule) {
+ if (this._has(rule))
+ return;
+ // registering rule to the rules registry
+ if (!(rule in RULES))
+ RULES[rule] = new MatchPattern(rule);
+ this._add(rule);
+ this._emit('add', rule);
+ }.bind(this)),
+ remove: function() Array.slice(arguments).forEach(function onRemove(rule) {
+ if (!this._has(rule))
+ return;
+ this._remove(rule);
+ this._emit('remove', rule);
+ }.bind(this)),
+});
+
+/**
+ * Returns the content of the uri given
+ */
+function readURI(uri) {
+ let channel = io.newChannel(uri, null, null);
+
+ let stream = Cc["@mozilla.org/scriptableinputstream;1"].
+ createInstance(Ci.nsIScriptableInputStream);
+
+ stream.init(channel.open());
+
+ let data = stream.read(stream.available());
+
+ stream.close();
+
+ return data;
+}
+
+/**
+ * PageMod constructor (exported below).
+ * @constructor
+ */
+const PageMod = Loader.compose(EventEmitter, {
+ on: EventEmitter.required,
+ _listeners: EventEmitter.required,
+ contentScript: Loader.required,
+ contentScriptFile: Loader.required,
+ contentScriptWhen: Loader.required,
+ include: null,
+ constructor: function PageMod(options) {
+ this._onContent = this._onContent.bind(this);
+ options = options || {};
+
+ let { contentStyle, contentStyleFile } = validate(options, validStyleOptions);
+
+ if ('contentScript' in options)
+ this.contentScript = options.contentScript;
+ if ('contentScriptFile' in options)
+ this.contentScriptFile = options.contentScriptFile;
+ if ('contentScriptWhen' in options)
+ this.contentScriptWhen = options.contentScriptWhen;
+ if ('onAttach' in options)
+ this.on('attach', options.onAttach);
+ if ('onError' in options)
+ this.on('error', options.onError);
+
+ let include = options.include;
+ let rules = this.include = Rules();
+ rules.on('add', this._onRuleAdd = this._onRuleAdd.bind(this));
+ rules.on('remove', this._onRuleRemove = this._onRuleRemove.bind(this));
+
+ if (Array.isArray(include))
+ rules.add.apply(null, include);
+ else
+ rules.add(include);
+
+ let styleRules = "";
+
+ if (contentStyleFile)
+ styleRules = [].concat(contentStyleFile).map(readURI).join("");
+
+ if (contentStyle)
+ styleRules += [].concat(contentStyle).join("");
+
+ if (styleRules) {
+ this._onRuleUpdate = this._onRuleUpdate.bind(this);
+
+ this._styleRules = styleRules;
+
+ this._registerStyleSheet();
+ rules.on('add', this._onRuleUpdate);
+ rules.on('remove', this._onRuleUpdate);
+ }
+
+ this.on('error', this._onUncaughtError = this._onUncaughtError.bind(this));
+ pageModManager.add(this._public);
+
+ this._loadingWindows = [];
+ },
+
+ destroy: function destroy() {
+
+ this._unregisterStyleSheet();
+
+ this.include.removeListener('add', this._onRuleUpdate);
+ this.include.removeListener('remove', this._onRuleUpdate);
+
+ for each (let rule in this.include)
+ this.include.remove(rule);
+ pageModManager.remove(this._public);
+ this._loadingWindows = [];
+
+ },
+
+ _loadingWindows: [],
+
+ _onContent: function _onContent(window) {
+ // not registered yet
+ if (!pageModManager.has(this))
+ return;
+
+ if (!HAS_BUG_642145_FIXED) {
+ if (this._loadingWindows.indexOf(window) != -1)
+ return;
+ this._loadingWindows.push(window);
+ }
+
+ if ('start' == this.contentScriptWhen) {
+ this._createWorker(window);
+ return;
+ }
+
+ let eventName = 'end' == this.contentScriptWhen ? 'load' : 'DOMContentLoaded';
+ let self = this;
+ window.addEventListener(eventName, function onReady(event) {
+ if (event.target.defaultView != window)
+ return;
+ window.removeEventListener(eventName, onReady, true);
+
+ self._createWorker(window);
+ }, true);
+ },
+ _createWorker: function _createWorker(window) {
+ let worker = Worker({
+ window: window,
+ contentScript: this.contentScript,
+ contentScriptFile: this.contentScriptFile,
+ onError: this._onUncaughtError
+ });
+ this._emit('attach', worker);
+ let self = this;
+ worker.once('detach', function detach() {
+ worker.destroy();
+
+ if (!HAS_BUG_642145_FIXED) {
+ let idx = self._loadingWindows.indexOf(window);
+ if (idx != -1)
+ self._loadingWindows.splice(idx, 1);
+ }
+ });
+ },
+ _onRuleAdd: function _onRuleAdd(url) {
+ pageModManager.on(url, this._onContent);
+ },
+ _onRuleRemove: function _onRuleRemove(url) {
+ pageModManager.off(url, this._onContent);
+ },
+ _onUncaughtError: function _onUncaughtError(e) {
+ if (this._listeners('error').length == 1)
+ console.exception(e);
+ },
+ _onRuleUpdate: function _onRuleUpdate(){
+ this._registerStyleSheet();
+ },
+
+ _registerStyleSheet : function _registerStyleSheet() {
+ let rules = this.include;
+ let styleRules = this._styleRules;
+
+ let documentRules = [];
+
+ this._unregisterStyleSheet();
+
+ for each (let rule in rules) {
+ let pattern = RULES[rule];
+
+ if (!pattern)
+ continue;
+
+ if (pattern.regexp)
+ documentRules.push("regexp(\"" + pattern.regexp.source + "\")")
+ else if (pattern.exactURL)
+ documentRules.push("url(" + pattern.exactURL + ")")
+ else if (pattern.domain)
+ documentRules.push("domain(" + pattern.domain + ")")
+ else if (pattern.urlPrefix)
+ documentRules.push("url-prefix(" + pattern.urlPrefix + ")")
+ else if (pattern.anyWebPage) {
+ documentRules.length = 0;
+ break;
+ }
+ }
+
+ let uri = "data:text/css,";
+ if (documentRules.length > 0)
+ uri += encodeURIComponent("@-moz-document " +
+ documentRules.join(",") + " {" + styleRules + "}");
+ else
+ uri += encodeURIComponent(styleRules);
+
+ this._registeredStyleURI = io.newURI(uri, null, null);
+
+ styleSheetService.loadAndRegisterSheet(
+ this._registeredStyleURI,
+ USER_SHEET
+ );
+ },
+
+ _unregisterStyleSheet : function () {
+ let uri = this._registeredStyleURI;
+
+ if (uri && styleSheetService.sheetRegistered(uri, USER_SHEET))
+ styleSheetService.unregisterSheet(uri, USER_SHEET);
+
+ this._registeredStyleURI = null;
+ }
+});
+exports.PageMod = function(options) PageMod(options)
+exports.PageMod.prototype = PageMod.prototype;
+
+const PageModManager = Registry.resolve({
+ constructor: '_init',
+ _destructor: '_registryDestructor'
+}).compose({
+ constructor: function PageModRegistry(constructor) {
+ this._init(PageMod);
+ observers.add(
+ ON_CONTENT, this._onContentWindow = this._onContentWindow.bind(this)
+ );
+ },
+ _destructor: function _destructor() {
+ observers.remove(ON_CONTENT, this._onContentWindow);
+ this._removeAllListeners();
+ for (let rule in RULES) {
+ delete RULES[rule];
+ }
+ this._registryDestructor();
+ },
+ _onContentWindow: function _onContentWindow(domObj) {
+ let window = HAS_DOCUMENT_ELEMENT_INSERTED ? domObj.defaultView : domObj;
+ // XML documents don't have windows, and we don't yet support them.
+ if (!window)
+ return;
+ for (let rule in RULES)
+ if (RULES[rule].test(window.document.URL))
+ this._emit(rule, window);
+ },
+ off: function off(topic, listener) {
+ this.removeListener(topic, listener);
+ if (!this._listeners(topic).length)
+ delete RULES[topic];
+ }
+});
+const pageModManager = PageModManager(); \ No newline at end of file
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/lib/page-worker.js b/tools/addon-sdk-1.7/packages/addon-kit/lib/page-worker.js
new file mode 100644
index 0000000..7e7b73e
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/lib/page-worker.js
@@ -0,0 +1,65 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const { Symbiont } = require("api-utils/content");
+const { Trait } = require("api-utils/traits");
+
+if (!require("api-utils/xul-app").isOneOf(["Firefox", "Thunderbird"])) {
+ throw new Error([
+ "The page-worker module currently supports only Firefox and Thunderbird. ",
+ "In the future, we would like it to support other applications, however. ",
+ "Please see https://bugzilla.mozilla.org/show_bug.cgi?id=546740 for more ",
+ "information."
+ ].join(""));
+}
+
+const Page = Trait.compose(
+ Symbiont.resolve({
+ constructor: '_initSymbiont'
+ }),
+ {
+ _frame: Trait.required,
+ _initFrame: Trait.required,
+ postMessage: Symbiont.required,
+ on: Symbiont.required,
+ destroy: Symbiont.required,
+
+ constructor: function Page(options) {
+ options = options || {};
+
+ this.contentURL = 'contentURL' in options ? options.contentURL
+ : 'about:blank';
+ if ('contentScriptWhen' in options)
+ this.contentScriptWhen = options.contentScriptWhen;
+ if ('contentScriptFile' in options)
+ this.contentScriptFile = options.contentScriptFile;
+ if ('contentScript' in options)
+ this.contentScript = options.contentScript;
+ if ('allow' in options)
+ this.allow = options.allow;
+ if ('onError' in options)
+ this.on('error', options.onError);
+ if ('onMessage' in options)
+ this.on('message', options.onMessage);
+
+ this.on('propertyChange', this._onChange.bind(this));
+
+ this._initSymbiont();
+ },
+
+ _onChange: function _onChange(e) {
+ if ('contentURL' in e && this._frame) {
+ // Cleanup the worker before injecting the content script in the new
+ // document
+ this._workerCleanup();
+ this._initFrame(this._frame);
+ }
+ }
+ }
+);
+exports.Page = function(options) Page(options);
+exports.Page.prototype = Page.prototype;
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/lib/panel.js b/tools/addon-sdk-1.7/packages/addon-kit/lib/panel.js
new file mode 100644
index 0000000..5593276
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/lib/panel.js
@@ -0,0 +1,381 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+if (!require("api-utils/xul-app").is("Firefox")) {
+ throw new Error([
+ "The panel module currently supports only Firefox. In the future ",
+ "we would like it to support other applications, however. Please see ",
+ "https://bugzilla.mozilla.org/show_bug.cgi?id=jetpack-panel-apps ",
+ "for more information."
+ ].join(""));
+}
+
+const { Cc, Ci } = require("chrome");
+
+const { validateOptions: valid } = require("api-utils/api-utils");
+const { Symbiont } = require("api-utils/content");
+const { EventEmitter } = require('api-utils/events');
+const timer = require("api-utils/timer");
+const runtime = require("api-utils/runtime");
+
+const windowMediator = Cc['@mozilla.org/appshell/window-mediator;1'].
+ getService(Ci.nsIWindowMediator);
+
+const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
+ ON_SHOW = 'popupshown',
+ ON_HIDE = 'popuphidden',
+ validNumber = { is: ['number', 'undefined', 'null'] };
+
+/**
+ * Emits show and hide events.
+ */
+const Panel = Symbiont.resolve({
+ constructor: '_init',
+ _onInit: '_onSymbiontInit',
+ destroy: '_symbiontDestructor',
+ _documentUnload: '_workerDocumentUnload'
+}).compose({
+ _frame: Symbiont.required,
+ _init: Symbiont.required,
+ _onSymbiontInit: Symbiont.required,
+ _symbiontDestructor: Symbiont.required,
+ _emit: Symbiont.required,
+ on: Symbiont.required,
+ removeListener: Symbiont.required,
+
+ _inited: false,
+
+ /**
+ * If set to `true` frame loaders between xul panel frame and
+ * hidden frame are swapped. If set to `false` frame loaders are
+ * set back to normal. Setting the value that was already set will
+ * have no effect.
+ */
+ set _frameLoadersSwapped(value) {
+ if (this.__frameLoadersSwapped == value) return;
+ this._frame.QueryInterface(Ci.nsIFrameLoaderOwner)
+ .swapFrameLoaders(this._viewFrame);
+ this.__frameLoadersSwapped = value;
+ },
+ __frameLoadersSwapped: false,
+
+ constructor: function Panel(options) {
+ this._onShow = this._onShow.bind(this);
+ this._onHide = this._onHide.bind(this);
+ this.on('inited', this._onSymbiontInit.bind(this));
+ this.on('propertyChange', this._onChange.bind(this));
+
+ options = options || {};
+ if ('onShow' in options)
+ this.on('show', options.onShow);
+ if ('onHide' in options)
+ this.on('hide', options.onHide);
+ if ('width' in options)
+ this.width = options.width;
+ if ('height' in options)
+ this.height = options.height;
+ if ('contentURL' in options)
+ this.contentURL = options.contentURL;
+
+ this._init(options);
+ },
+ _destructor: function _destructor() {
+ this.hide();
+ this._removeAllListeners('show');
+ this._removeAllListeners('hide');
+ this._removeAllListeners('propertyChange');
+ this._removeAllListeners('inited');
+ // defer cleanup to be performed after panel gets hidden
+ this._xulPanel = null;
+ this._symbiontDestructor(this);
+ this._removeAllListeners();
+ },
+ destroy: function destroy() {
+ this._destructor();
+ },
+ /* Public API: Panel.width */
+ get width() this._width,
+ set width(value)
+ this._width = valid({ $: value }, { $: validNumber }).$ || this._width,
+ _width: 320,
+ /* Public API: Panel.height */
+ get height() this._height,
+ set height(value)
+ this._height = valid({ $: value }, { $: validNumber }).$ || this._height,
+ _height: 240,
+
+ /* Public API: Panel.isShowing */
+ get isShowing() !!this._xulPanel && this._xulPanel.state == "open",
+
+ /* Public API: Panel.show */
+ show: function show(anchor) {
+ anchor = anchor || null;
+ let document = getWindow(anchor).document;
+ let xulPanel = this._xulPanel;
+ if (!xulPanel) {
+ xulPanel = this._xulPanel = document.createElementNS(XUL_NS, 'panel');
+ xulPanel.setAttribute("type", "arrow");
+
+ // One anonymous node has a big padding that doesn't work well with
+ // Jetpack, as we would like to display an iframe that completely fills
+ // the panel.
+ // -> Use a XBL wrapper with inner stylesheet to remove this padding.
+ let css = ".panel-inner-arrowcontent, .panel-arrowcontent {padding: 0;}";
+ let originalXBL = "chrome://global/content/bindings/popup.xml#arrowpanel";
+ let binding =
+ '<bindings xmlns="http://www.mozilla.org/xbl">' +
+ '<binding id="id" extends="' + originalXBL + '">' +
+ '<resources>' +
+ '<stylesheet src="data:text/css,' +
+ document.defaultView.encodeURIComponent(css) + '"/>' +
+ '</resources>' +
+ '</binding>' +
+ '</bindings>';
+ xulPanel.style.MozBinding = 'url("data:text/xml,' +
+ document.defaultView.encodeURIComponent(binding) + '")';
+
+ let frame = document.createElementNS(XUL_NS, 'iframe');
+ frame.setAttribute('type', 'content');
+ frame.setAttribute('flex', '1');
+ frame.setAttribute('transparent', 'transparent');
+ if (runtime.OS === "Darwin") {
+ frame.style.borderRadius = "6px";
+ frame.style.padding = "1px";
+ }
+
+ // Load an empty document in order to have an immediatly loaded iframe,
+ // so swapFrameLoaders is going to work without having to wait for load.
+ frame.setAttribute("src","data:,");
+
+ xulPanel.appendChild(frame);
+ document.getElementById("mainPopupSet").appendChild(xulPanel);
+ }
+ let { width, height } = this, x, y, position;
+
+ if (!anchor) {
+ // Open the popup in the middle of the window.
+ x = document.documentElement.clientWidth / 2 - width / 2;
+ y = document.documentElement.clientHeight / 2 - height / 2;
+ position = null;
+ }
+ else {
+ // Open the popup by the anchor.
+ let rect = anchor.getBoundingClientRect();
+
+ let window = anchor.ownerDocument.defaultView;
+
+ let zoom = window.mozScreenPixelsPerCSSPixel;
+ let screenX = rect.left + window.mozInnerScreenX * zoom;
+ let screenY = rect.top + window.mozInnerScreenY * zoom;
+
+ // Set up the vertical position of the popup relative to the anchor
+ // (always display the arrow on anchor center)
+ let horizontal, vertical;
+ if (screenY > window.screen.availHeight / 2 + height)
+ vertical = "top";
+ else
+ vertical = "bottom";
+
+ if (screenY > window.screen.availWidth / 2 + width)
+ horizontal = "left";
+ else
+ horizontal = "right";
+
+ let verticalInverse = vertical == "top" ? "bottom" : "top";
+ position = vertical + "center " + verticalInverse + horizontal;
+
+ // Allow panel to flip itself if the panel can't be displayed at the
+ // specified position (useful if we compute a bad position or if the
+ // user moves the window and panel remains visible)
+ xulPanel.setAttribute("flip","both");
+ }
+
+ // Resize the iframe instead of using panel.sizeTo
+ // because sizeTo doesn't work with arrow panels
+ xulPanel.firstChild.style.width = width + "px";
+ xulPanel.firstChild.style.height = height + "px";
+
+ // Wait for the XBL binding to be constructed
+ function waitForBinding() {
+ if (!xulPanel.openPopup) {
+ timer.setTimeout(waitForBinding, 50);
+ return;
+ }
+ xulPanel.openPopup(anchor, position, x, y);
+ }
+ waitForBinding();
+
+ return this._public;
+ },
+ /* Public API: Panel.hide */
+ hide: function hide() {
+ // The popuphiding handler takes care of swapping back the frame loaders
+ // and removing the XUL panel from the application window, we just have to
+ // trigger it by hiding the popup.
+ // XXX Sometimes I get "TypeError: xulPanel.hidePopup is not a function"
+ // when quitting the host application while a panel is visible. To suppress
+ // them, this now checks for "hidePopup" in xulPanel before calling it.
+ // It's not clear if there's an actual issue or the error is just normal.
+ let xulPanel = this._xulPanel;
+ if (xulPanel && "hidePopup" in xulPanel)
+ xulPanel.hidePopup();
+ return this._public;
+ },
+
+ /* Public API: Panel.resize */
+ resize: function resize(width, height) {
+ this.width = width;
+ this.height = height;
+ // Resize the iframe instead of using panel.sizeTo
+ // because sizeTo doesn't work with arrow panels
+ let xulPanel = this._xulPanel;
+ if (xulPanel) {
+ xulPanel.firstChild.style.width = width + "px";
+ xulPanel.firstChild.style.height = height + "px";
+ }
+ },
+
+ // While the panel is visible, this is the XUL <panel> we use to display it.
+ // Otherwise, it's null.
+ get _xulPanel() this.__xulPanel,
+ set _xulPanel(value) {
+ let xulPanel = this.__xulPanel;
+ if (value === xulPanel) return;
+ if (xulPanel) {
+ xulPanel.removeEventListener(ON_HIDE, this._onHide, false);
+ xulPanel.removeEventListener(ON_SHOW, this._onShow, false);
+ xulPanel.parentNode.removeChild(xulPanel);
+ }
+ if (value) {
+ value.addEventListener(ON_HIDE, this._onHide, false);
+ value.addEventListener(ON_SHOW, this._onShow, false);
+ }
+ this.__xulPanel = value;
+ },
+ __xulPanel: null,
+ get _viewFrame() this.__xulPanel.children[0],
+ /**
+ * When the XUL panel becomes hidden, we swap frame loaders back to move
+ * the content of the panel to the hidden frame & remove panel element.
+ */
+ _onHide: function _onHide() {
+ try {
+ this._frameLoadersSwapped = false;
+ this._xulPanel = null;
+ this._emit('hide');
+ } catch(e) {
+ this._emit('error', e);
+ }
+ },
+ /**
+ * When the XUL panel becomes shown, we swap frame loaders between panel
+ * frame and hidden frame to preserve state of the content dom.
+ */
+ _onShow: function _onShow() {
+ try {
+ if (!this._inited) { // defer if not initialized yet
+ this.on('inited', this._onShow.bind(this));
+ } else {
+ this._frameLoadersSwapped = true;
+
+ // Retrieve computed text color style in order to apply to the iframe
+ // document. As MacOS background is dark gray, we need to use skin's
+ // text color.
+ let win = this._xulPanel.ownerDocument.defaultView;
+ let node = win.document.getAnonymousElementByAttribute(this._xulPanel,
+ "class", "panel-inner-arrowcontent");
+ let textColor = win.getComputedStyle(node).getPropertyValue("color");
+ let doc = this._xulPanel.firstChild.contentDocument;
+ let style = doc.createElement("style");
+ style.textContent = "body { color: " + textColor + "; }";
+ let container = doc.head ? doc.head : doc.documentElement;
+
+ if (container.firstChild)
+ container.insertBefore(style, container.firstChild);
+ else
+ container.appendChild(style);
+
+ this._emit('show');
+ }
+ } catch(e) {
+ this._emit('error', e);
+ }
+ },
+ /**
+ * Notification that panel was fully initialized.
+ */
+ _onInit: function _onInit() {
+ this._inited = true;
+
+ // Avoid panel document from resizing the browser window
+ // New platform capability added through bug 635673
+ if ("allowWindowControl" in this._frame.docShell)
+ this._frame.docShell.allowWindowControl = false;
+
+ // perform all deferred tasks like initSymbiont, show, hide ...
+ // TODO: We're publicly exposing a private event here; this
+ // 'inited' event should really be made private, somehow.
+ this._emit('inited');
+ },
+
+ // Catch document unload event in order to rebind load event listener with
+ // Symbiont._initFrame if Worker._documentUnload destroyed the worker
+ _documentUnload: function(subject, topic, data) {
+ if (this._workerDocumentUnload(subject, topic, data)) {
+ this._initFrame(this._frame);
+ return true;
+ }
+ return false;
+ },
+
+ _onChange: function _onChange(e) {
+ if ('contentURL' in e && this._frame) {
+ // Cleanup the worker before injecting the content script in the new
+ // document
+ this._workerCleanup();
+ this._initFrame(this._frame);
+ }
+ }
+});
+exports.Panel = function(options) Panel(options)
+exports.Panel.prototype = Panel.prototype;
+
+function getWindow(anchor) {
+ let window;
+
+ if (anchor) {
+ let anchorWindow = anchor.ownerDocument.defaultView.top;
+ let anchorDocument = anchorWindow.document;
+
+ let enumerator = windowMediator.getEnumerator("navigator:browser");
+ while (enumerator.hasMoreElements()) {
+ let enumWindow = enumerator.getNext();
+
+ // Check if the anchor is in this browser window.
+ if (enumWindow == anchorWindow) {
+ window = anchorWindow;
+ break;
+ }
+
+ // Check if the anchor is in a browser tab in this browser window.
+ let browser = enumWindow.gBrowser.getBrowserForDocument(anchorDocument);
+ if (browser) {
+ window = enumWindow;
+ break;
+ }
+
+ // Look in other subdocuments (sidebar, etc.)?
+ }
+ }
+
+ // If we didn't find the anchor's window (or we have no anchor),
+ // return the most recent browser window.
+ if (!window)
+ window = windowMediator.getMostRecentWindow("navigator:browser");
+
+ return window;
+}
+
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/lib/passwords.js b/tools/addon-sdk-1.7/packages/addon-kit/lib/passwords.js
new file mode 100644
index 0000000..3da63ad
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/lib/passwords.js
@@ -0,0 +1,59 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { search, remove, store } = require("api-utils/passwords/utils");
+const { defer, delay } = require("api-utils/functional");
+
+/**
+ * Utility function that returns `onComplete` and `onError` callbacks form the
+ * given `options` objects. Also properties are removed from the passed
+ * `options` objects.
+ * @param {Object} options
+ * Object that is passed to the exported functions of this module.
+ * @returns {Function[]}
+ * Array with two elements `onComplete` and `onError` functions.
+ */
+function getCallbacks(options) {
+ let value = [
+ 'onComplete' in options ? options.onComplete : null,
+ 'onError' in options ? defer(options.onError) : console.exception
+ ];
+
+ delete options.onComplete;
+ delete options.onError;
+
+ return value;
+};
+
+/**
+ * Creates a wrapper function that tries to call `onComplete` with a return
+ * value of the wrapped function or falls back to `onError` if wrapped function
+ * throws an exception.
+ */
+function createWrapperMethod(wrapped) {
+ return function (options) {
+ let [ onComplete, onError ] = getCallbacks(options);
+ try {
+ let value = wrapped(options);
+ if (onComplete) {
+ delay(function() {
+ try {
+ onComplete(value);
+ } catch (exception) {
+ onError(exception);
+ }
+ });
+ }
+ } catch (exception) {
+ onError(exception);
+ }
+ };
+}
+
+exports.search = createWrapperMethod(search);
+exports.store = createWrapperMethod(store);
+exports.remove = createWrapperMethod(remove);
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/lib/private-browsing.js b/tools/addon-sdk-1.7/packages/addon-kit/lib/private-browsing.js
new file mode 100644
index 0000000..ff40c98
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/lib/private-browsing.js
@@ -0,0 +1,61 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Cc, Ci } = require("chrome");
+const { emit, on, once, off } = require("api-utils/event/core");
+const { defer } = require("api-utils/functional");
+const { when: unload } = require("api-utils/unload");
+const observers = require("api-utils/observer-service");
+
+// Model holding a state.
+const model = { active: false };
+
+let deferredEmit = defer(emit);
+
+let pbService;
+// Currently, only Firefox implements the private browsing service.
+if (require("api-utils/xul-app").is("Firefox")) {
+ pbService = Cc["@mozilla.org/privatebrowsing;1"].
+ getService(Ci.nsIPrivateBrowsingService);
+
+ // Update model state.
+ model.active = pbService.privateBrowsingEnabled;
+
+ // set up an observer for private browsing switches.
+ observers.add('private-browsing-transition-complete', function onChange() {
+ // Update model state.
+ model.active = pbService.privateBrowsingEnabled;
+ // Emit event with in next turn of event loop.
+ deferredEmit(exports, model.active ? 'start' : 'stop');
+ });
+}
+
+let setMode = defer(function setMode(value) {
+ // We toggle private browsing mode asynchronously in order to work around
+ // bug 659629. Since private browsing transitions are asynchronous
+ // anyway, this doesn't significantly change the behavior of the API.
+ pbService.privateBrowsingEnabled = !!value
+});
+
+
+// Make sure listeners are cleaned up.
+unload(function() off(exports));
+
+Object.defineProperty(exports, "isActive", { get: function() model.active });
+exports.activate = function activate() pbService && setMode(true)
+exports.deactivate = function deactivate() pbService && setMode(false)
+exports.on = on.bind(null, exports);
+exports.once = once.bind(null, exports);
+exports.removeListener = function removeListener(type, listener) {
+ // Note: We can't just bind `off` as we do it for other methods cause skipping
+ // a listener argument will remove all listeners for the given event type
+ // causing misbehavior. This way we make sure all arguments are passed.
+ off(exports, type, listener);
+};
+
+// This is workaround making sure that exports is wrapped before it's
+// frozen, which needs to happen in order to workaround Bug 673468.
+off(exports, 'workaround-bug-673468');
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/lib/request.js b/tools/addon-sdk-1.7/packages/addon-kit/lib/request.js
new file mode 100644
index 0000000..b213af8
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/lib/request.js
@@ -0,0 +1,208 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Base, Class } = require("api-utils/base");
+const { ns } = require("api-utils/namespace");
+const { emit } = require("api-utils/event/core");
+const { merge } = require("api-utils/utils/object");
+const { stringify } = require("api-utils/querystring");
+const { EventTarget } = require("api-utils/event/target");
+const { XMLHttpRequest } = require("api-utils/xhr");
+const apiUtils = require("api-utils/api-utils");
+
+const response = ns();
+const request = ns();
+
+// Instead of creating a new validator for each request, just make one and
+// reuse it.
+const { validateOptions, validateSingleOption } = new OptionsValidator({
+ url: {
+ //XXXzpao should probably verify that url is a valid url as well
+ is: ["string"]
+ },
+ headers: {
+ map: function (v) v || {},
+ is: ["object"],
+ },
+ content: {
+ map: function (v) v || null,
+ is: ["string", "object", "null"],
+ },
+ contentType: {
+ map: function (v) v || "application/x-www-form-urlencoded",
+ is: ["string"],
+ },
+ overrideMimeType: {
+ map: function(v) v || null,
+ is: ["string", "null"],
+ }
+});
+
+const REUSE_ERROR = "This request object has been used already. You must " +
+ "create a new one to make a new request."
+
+// Utility function to prep the request since it's the same between GET and
+// POST
+function runRequest(mode, target) {
+ let source = request(target)
+ let { xhr, url, content, contentType, headers, overrideMimeType } = source;
+
+ // If this request has already been used, then we can't reuse it.
+ // Throw an error.
+ if (xhr)
+ throw new Error(REUSE_ERROR);
+
+ xhr = source.xhr = new XMLHttpRequest();
+
+ // Build the data to be set. For GET requests, we want to append that to
+ // the URL before opening the request.
+ let data = stringify(content);
+ // If the URL already has ? in it, then we want to just use &
+ if (mode == "GET" && data)
+ url = url + (/\?/.test(url) ? "&" : "?") + data;
+
+ // open the request
+ xhr.open(mode, url);
+
+ // request header must be set after open, but before send
+ xhr.setRequestHeader("Content-Type", contentType);
+
+ // set other headers
+ Object.keys(headers).forEach(function(name) {
+ xhr.setRequestHeader(name, headers[name]);
+ });
+
+ // set overrideMimeType
+ if (overrideMimeType)
+ xhr.overrideMimeType(overrideMimeType);
+
+ // handle the readystate, create the response, and call the callback
+ xhr.onreadystatechange = function onreadystatechange() {
+ if (xhr.readyState === 4) {
+ let response = Response.new(xhr);
+ source.response = response;
+ emit(target, 'complete', response);
+ }
+ };
+
+ // actually send the request.
+ // We don't want to send data on GET requests.
+ xhr.send(mode !== "GET" ? data : null);
+}
+
+const Request = EventTarget.extend({
+ initialize: function initialize(options) {
+ // `EventTarget.initialize` will set event listeners that are named
+ // like `onEvent` in this case `onComplete` listener will be set to
+ // `complete` event.
+ EventTarget.initialize.call(this, options);
+
+ // Copy normalized options.
+ merge(request(this), validateOptions(options));
+ },
+ get url() { return request(this).url; },
+ set url(value) { request(this).url = validateSingleOption('url', value); },
+ get headers() { return request(this).headers; },
+ set headers(value) {
+ return request(this).headers = validateSingleOption('headers', value);
+ },
+ get content() { return request(this).content; },
+ set content(value) {
+ request(this).content = validateSingleOption('content', value);
+ },
+ get contentType() { return request(this).contentType; },
+ set contentType(value) {
+ request(this).contentType = validateSingleOption('contentType', value);
+ },
+ get response() { return request(this).response; },
+ get: function() {
+ runRequest('GET', this);
+ return this;
+ },
+ post: function() {
+ runRequest('POST', this);
+ return this;
+ },
+ put: function() {
+ runRequest('PUT', this);
+ return this;
+ }
+});
+exports.Request = Class(Request);
+
+const Response = Base.extend({
+ initialize: function initialize(request) {
+ response(this).request = request;
+ },
+ get text() response(this).request.responseText,
+ get xml() {
+ throw new Error("Sorry, the 'xml' property is no longer available. " +
+ "see bug 611042 for more information.");
+ },
+ get status() response(this).request.status,
+ get statusText() response(this).request.statusText,
+ get json() {
+ try {
+ return JSON.parse(this.text);
+ } catch(error) {
+ return null;
+ }
+ },
+ get headers() {
+ let headers = {}, lastKey;
+ // Since getAllResponseHeaders() will return null if there are no headers,
+ // defend against it by defaulting to ""
+ let rawHeaders = response(this).request.getAllResponseHeaders() || "";
+ rawHeaders.split("\n").forEach(function (h) {
+ // According to the HTTP spec, the header string is terminated by an empty
+ // line, so we can just skip it.
+ if (!h.length) {
+ return;
+ }
+
+ let index = h.indexOf(":");
+ // The spec allows for leading spaces, so instead of assuming a single
+ // leading space, just trim the values.
+ let key = h.substring(0, index).trim(),
+ val = h.substring(index + 1).trim();
+
+ // For empty keys, that means that the header value spanned multiple lines.
+ // In that case we should append the value to the value of lastKey with a
+ // new line. We'll assume lastKey will be set because there should never
+ // be an empty key on the first pass.
+ if (key) {
+ headers[key] = val;
+ lastKey = key;
+ }
+ else {
+ headers[lastKey] += "\n" + val;
+ }
+ });
+ return headers;
+ }
+});
+
+// apiUtils.validateOptions doesn't give the ability to easily validate single
+// options, so this is a wrapper that provides that ability.
+function OptionsValidator(rules) {
+ return {
+ validateOptions: function (options) {
+ return apiUtils.validateOptions(options, rules);
+ },
+ validateSingleOption: function (field, value) {
+ // We need to create a single rule object from our listed rules. To avoid
+ // JavaScript String warnings, check for the field & default to an empty object.
+ let singleRule = {};
+ if (field in rules) {
+ singleRule[field] = rules[field];
+ }
+ let singleOption = {};
+ singleOption[field] = value;
+ // This should throw if it's invalid, which will bubble up & out.
+ return apiUtils.validateOptions(singleOption, singleRule)[field];
+ }
+ };
+}
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/lib/selection.js b/tools/addon-sdk-1.7/packages/addon-kit/lib/selection.js
new file mode 100644
index 0000000..f10d890
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/lib/selection.js
@@ -0,0 +1,421 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+if (!require("api-utils/xul-app").is("Firefox")) {
+ throw new Error([
+ "The selection module currently supports only Firefox. In the future ",
+ "we would like it to support other applications, however. Please see ",
+ "https://bugzilla.mozilla.org/show_bug.cgi?id=560716 for more information."
+ ].join(""));
+}
+
+let { Ci, Cc } = require("chrome"),
+ { setTimeout } = require("api-utils/timer"),
+ { emit, off } = require("api-utils/event/core"),
+ { Unknown } = require("api-utils/xpcom"),
+ { Base } = require("api-utils/base"),
+ { EventTarget } = require("api-utils/event/target");
+
+
+const windowMediator = Cc["@mozilla.org/appshell/window-mediator;1"].
+ getService(Ci.nsIWindowMediator);
+
+
+// The selection type HTML
+const HTML = 0x01;
+
+// The selection type TEXT
+const TEXT = 0x02;
+
+// The selection type DOM (internal use only)
+const DOM = 0x03;
+
+// A more developer-friendly message than the caught exception when is not
+// possible change a selection.
+const ERR_CANNOT_CHANGE_SELECTION =
+ "It isn't possible to change the selection, as there isn't currently a selection";
+
+const Selection = Base.extend({
+ /**
+ * Creates an object from which a selection can be set, get, etc. Each
+ * object has an associated with a range number. Range numbers are the
+ * 0-indexed counter of selection ranges as explained at
+ * https://developer.mozilla.org/en/DOM/Selection.
+ *
+ * @param rangeNumber
+ * The zero-based range index into the selection
+ */
+ initialize: function initialize(rangeNumber) {
+ // In order to hide the private `rangeNumber` argument from API consumers
+ // while still enabling Selection getters/setters to access it, we define
+ // it as non enumerable, non configurable property. While consumers still
+ // may discover it they won't be able to do any harm which is good enough
+ // in this case.
+ Object.defineProperties(this, {
+ rangeNumber: {
+ enumerable: false,
+ configurable: false,
+ value: rangeNumber
+ }
+ });
+ },
+ get text() { return getSelection(TEXT, this.rangeNumber); },
+ set text(value) { setSelection(value, this.rangeNumber); },
+ get html() { return getSelection(HTML, this.rangeNumber); },
+ set html(value) { setSelection(value, this.rangeNumber); },
+ get isContiguous() {
+ let selection = getSelection(DOM);
+
+ // If there are multiple ranges, the selection is definitely discontiguous.
+ // It returns `false` also if there are no selection; and `true` if there is
+ // a single non empty range, or a selection in a text field - contiguous or
+ // not (text field selection APIs doesn't support multiple selections).
+
+ if (selection.rangeCount > 1)
+ return false;
+
+ return !!(safeGetRange(selection, 0) || getElementWithSelection());
+ }
+});
+
+/**
+ * Returns the most recent content window
+ */
+function context() {
+ // Overlay names should probably go into the xul-app module instead of here
+ return windowMediator.getMostRecentWindow("navigator:browser").document.
+ commandDispatcher.focusedWindow;
+}
+
+/**
+ * Returns the current selection from most recent content window. Depending on
+ * the specified |type|, the value returned can be a string of text, stringified
+ * HTML, or a DOM selection object as described at
+ * https://developer.mozilla.org/en/DOM/Selection.
+ *
+ * @param type
+ * Specifies the return type of the selection. Valid values are the one
+ * of the constants HTML, TEXT, or DOM.
+ *
+ * @param rangeNumber
+ * Specifies the zero-based range index of the returned selection.
+ */
+function getSelection(type, rangeNumber) {
+ let window, selection;
+ try {
+ window = context();
+ selection = window.getSelection();
+ }
+ catch (e) {
+ return null;
+ }
+
+ // Get the selected content as the specified type
+ if (type == DOM)
+ return selection;
+ else if (type == TEXT) {
+ let range = safeGetRange(selection, rangeNumber);
+
+ if (range)
+ return range.toString();
+
+ let node = getElementWithSelection(window);
+
+ if (!node)
+ return null;
+
+ return node.value.substring(node.selectionStart, node.selectionEnd);
+ }
+ else if (type == HTML) {
+ let range = safeGetRange(selection, rangeNumber);
+ // Another way, but this includes the xmlns attribute for all elements in
+ // Gecko 1.9.2+ :
+ // return Cc["@mozilla.org/xmlextras/xmlserializer;1"].
+ // createInstance(Ci.nsIDOMSerializer).serializeToSTring(range.
+ // cloneContents());
+ if (!range)
+ return null;
+ let node = window.document.createElement("span");
+ node.appendChild(range.cloneContents());
+ return node.innerHTML;
+ }
+ throw new Error("Type " + type + " is unrecognized.");
+}
+
+/**
+ * Returns the specified range in a selection without throwing an exception.
+ *
+ * @param selection
+ * A selection object as described at
+ * https://developer.mozilla.org/en/DOM/Selection
+ *
+ * @param rangeNumber
+ * Specifies the zero-based range index of the returned selection.
+ */
+function safeGetRange(selection, rangeNumber) {
+ try {
+ let range = selection.getRangeAt(rangeNumber);
+ if (!range || range.toString() == "")
+ return null;
+ return range;
+ }
+ catch (e) {
+ return null;
+ }
+}
+
+/**
+ * Returns a reference of the DOM's active element for the window given, if it
+ * supports the text field selection API and has a text selected.
+ *
+ * Note:
+ * we need this method because window.getSelection doesn't return a selection
+ * for text selected in a form field (see bug 85686)
+ *
+ * @param {nsIWindow} [window]
+ * A reference to a window
+ */
+function getElementWithSelection(window) {
+ let element;
+
+ try {
+ element = (window || context()).document.activeElement;
+ }
+ catch (e) {
+ element = null;
+ }
+
+ if (!element)
+ return null;
+
+ let { value, selectionStart, selectionEnd } = element;
+
+ let hasSelection = typeof value === "string" &&
+ !isNaN(selectionStart) &&
+ !isNaN(selectionEnd) &&
+ selectionStart !== selectionEnd;
+
+ return hasSelection ? element : null;
+}
+/**
+ * Sets the current selection of the most recent content document by changing
+ * the existing selected text/HTML range to the specified value.
+ *
+ * @param val
+ * The value for the new selection
+ *
+ * @param rangeNumber
+ * The zero-based range index of the selection to be set
+ *
+ */
+function setSelection(val, rangeNumber) {
+ // Make sure we have a window context & that there is a current selection.
+ // Selection cannot be set unless there is an existing selection.
+ let window, selection;
+
+ try {
+ window = context();
+ selection = window.getSelection();
+ }
+ catch (e) {
+ throw new Error(ERR_CANNOT_CHANGE_SELECTION);
+ }
+
+ let range = safeGetRange(selection, rangeNumber);
+
+ if (range) {
+ // Get rid of the current selection and insert our own
+ range.deleteContents();
+ let node = window.document.createElement("span");
+ range.surroundContents(node);
+
+ // Some relevant JEP-111 requirements:
+
+ // Setting the text property replaces the selection with the value to
+ // which the property is set and sets the html property to the same value
+ // to which the text property is being set.
+
+ // Setting the html property replaces the selection with the value to
+ // which the property is set and sets the text property to the text version
+ // of the HTML value.
+
+ // This sets both the HTML and text properties.
+ node.innerHTML = val;
+ } else {
+ let node = getElementWithSelection(window);
+
+ if (!node)
+ throw new Error(ERR_CANNOT_CHANGE_SELECTION);
+
+ let { value, selectionStart, selectionEnd } = node;
+
+ let newSelectionEnd = selectionStart + val.length;
+
+ node.value = value.substring(0, selectionStart) +
+ val +
+ value.substring(selectionEnd, value.length);
+
+ node.setSelectionRange(selectionStart, newSelectionEnd);
+ }
+}
+
+function onLoad(event) {
+ SelectionListenerManager.onLoad(event);
+}
+
+function onUnload(event) {
+ SelectionListenerManager.onUnload(event);
+}
+
+function onSelect() {
+ SelectionListenerManager.onSelect();
+}
+
+let SelectionListenerManager = Unknown.extend({
+ interfaces: [ 'nsISelectionListener' ],
+ /**
+ * This is the nsISelectionListener implementation. This function is called
+ * by Gecko when a selection is changed interactively.
+ *
+ * We only pay attention to the SELECTALL, KEYPRESS, and MOUSEUP selection
+ * reasons. All reasons are listed here:
+ *
+ * http://mxr.mozilla.org/mozilla1.9.2/source/content/base/public/
+ * nsISelectionListener.idl
+ *
+ * The other reasons (NO_REASON, DRAG_REASON, MOUSEDOWN_REASON) aren't
+ * applicable to us.
+ */
+ notifySelectionChanged: function notifySelectionChanged(document, selection,
+ reason) {
+ if (!["SELECTALL", "KEYPRESS", "MOUSEUP"].some(function(type) reason &
+ Ci.nsISelectionListener[type + "_REASON"]) || selection.toString() == "")
+ return;
+
+ this.onSelect();
+ },
+
+ onSelect : function onSelect() {
+ setTimeout(emit, 0, module.exports, "select");
+ },
+
+ /**
+ * Part of the Tracker implementation. This function is called by the
+ * tabs module when a browser is being tracked. Often, that means a new tab
+ * has been opened, but it can also mean an addon has been installed while
+ * tabs are already opened. In that case, this function is called for those
+ * already-opened tabs.
+ *
+ * @param browser
+ * The browser being tracked
+ */
+ onTrack: function onTrack(browser) {
+ browser.addEventListener("load", onLoad, true);
+ browser.addEventListener("unload", onUnload, true);
+ },
+
+ onLoad: function onLoad(event) {
+ // Nothing to do without a useful window
+ let window = event.target.defaultView;
+ if (!window)
+ return;
+
+ // Wrap the add selection call with some number of setTimeout 0 because some
+ // reason it's possible to add a selection listener "too early". 2 sometimes
+ // works for gmail, and more consistently with 3, so make it 5 to be safe.
+ let count = 0;
+ let self = this;
+ function wrap(count, func) {
+ if (count-- > 0)
+ setTimeout(wrap, 0);
+ else
+ self.addSelectionListener(window);
+ }
+ wrap();
+ },
+
+ addSelectionListener: function addSelectionListener(window) {
+ if (window.jetpack_core_selection_listener)
+ return;
+ let selection = window.getSelection();
+ if (selection instanceof Ci.nsISelectionPrivate)
+ selection.addSelectionListener(this);
+
+ // nsISelectionListener implementation seems not fire a notification if
+ // a selection is in a text field, therefore we need to add a listener to
+ // window.onselect, that is fired only for text fields.
+ // https://developer.mozilla.org/en/DOM/window.onselect
+ window.addEventListener("select", onSelect, true);
+
+ window.jetpack_core_selection_listener = true;
+ },
+
+ onUnload: function onUnload(event) {
+ // Nothing to do without a useful window
+ let window = event.target.defaultView;
+ if (!window)
+ return;
+ this.removeSelectionListener(window);
+ off(exports);
+ },
+
+ removeSelectionListener: function removeSelectionListener(window) {
+ if (!window.jetpack_core_selection_listener)
+ return;
+ let selection = window.getSelection();
+ if (selection instanceof Ci.nsISelectionPrivate)
+ selection.removeSelectionListener(this);
+
+ window.removeEventListener("select", onSelect);
+
+ window.jetpack_core_selection_listener = false;
+ },
+
+ /**
+ * Part of the TabTracker implementation. This function is called by the
+ * tabs module when a browser is being untracked. Usually, that means a tab
+ * has been closed.
+ *
+ * @param browser
+ * The browser being untracked
+ */
+ onUntrack: function onUntrack(browser) {
+ browser.removeEventListener("load", onLoad, true);
+ browser.removeEventListener("unload", onUnload, true);
+ }
+});
+
+/**
+ * Install |SelectionListenerManager| as tab tracker in order to watch
+ * tab opening/closing
+ */
+require("api-utils/tab-browser").Tracker(SelectionListenerManager);
+
+// Note: We use `Object.create` form just in order to define `__iterator__`
+// as non-enumerable, to ensure that it won't be returned by an `Object.keys`.
+var SelectionIterator = Object.create(Object.prototype, {
+ /**
+ * Exports an iterator so that discontiguous selections can be iterated.
+ *
+ * If discontiguous selections are in a text field, only the first one
+ * is returned because the text field selection APIs doesn't support
+ * multiple selections.
+ */
+ __iterator__: { enumerable: false, value: function() {
+ let selection = getSelection(DOM);
+ let count = selection.rangeCount || (getElementWithSelection() ? 1 : 0);
+
+ for (let i = 0; i < count; i++)
+ yield Selection.new(i);
+ }}
+});
+
+var selection = EventTarget.extend(Selection, SelectionIterator).new(0);
+
+// This is workaround making sure that exports is wrapped before it's
+// frozen, which needs to happen in order to workaround Bug 673468.
+off(selection, 'workaround-bug-673468');
+module.exports = selection;
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/lib/simple-prefs.js b/tools/addon-sdk-1.7/packages/addon-kit/lib/simple-prefs.js
new file mode 100644
index 0000000..5f73cc5
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/lib/simple-prefs.js
@@ -0,0 +1,68 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const { Cc, Ci } = require("chrome");
+const { emit, off } = require("api-utils/event/core");
+const { EventTarget } = require("api-utils/event/target");
+const { when: unload } = require("api-utils/unload");
+const { jetpackID } = require("@packaging");
+const prefService = require("api-utils/preferences-service");
+const observers = require("api-utils/observer-service");
+
+const ADDON_BRANCH = "extensions." + jetpackID + ".";
+const BUTTON_PRESSED = jetpackID + "-cmdPressed";
+
+// XXX Currently, only Firefox implements the inline preferences.
+if (!require("xul-app").is("Firefox"))
+ throw Error("This API is only supported in Firefox");
+
+const branch = Cc["@mozilla.org/preferences-service;1"].
+ getService(Ci.nsIPrefService).
+ getBranch(ADDON_BRANCH).
+ QueryInterface(Ci.nsIPrefBranch2);
+
+// Listen to changes in the preferences
+function preferenceChange(subject, topic, name) {
+ if (topic === 'nsPref:changed')
+ emit(target, name, name);
+}
+branch.addObserver('', preferenceChange, false);
+
+// Listen to clicks on buttons
+function buttonClick(subject, data) {
+ emit(target, data);
+}
+observers.add(BUTTON_PRESSED, buttonClick);
+
+// Make sure we cleanup listeners on unload.
+unload(function() {
+ off(exports);
+ branch.removeObserver('', preferenceChange, false);
+ observers.remove(BUTTON_PRESSED, buttonClick);
+});
+
+const prefs = Proxy.create({
+ get: function(receiver, pref) {
+ return prefService.get(ADDON_BRANCH + pref);
+ },
+ set: function(receiver, pref, val) {
+ prefService.set(ADDON_BRANCH + pref, val);
+ },
+ delete: function(pref) {
+ prefService.reset(ADDON_BRANCH + pref);
+ return true;
+ },
+ has: function(pref) {
+ return prefService.has(ADDON_BRANCH + pref);
+ }
+});
+
+// Event target we will expose as module exports in order to be able to
+// emit events on it.
+const target = EventTarget.extend({ prefs: prefs }).new();
+module.exports = target;
+
+// This is workaround making sure that exports is wrapped before it's
+// frozen, which needs to happen in order to workaround Bug 673468.
+off(target, 'workaround-bug-673468');
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/lib/simple-storage.js b/tools/addon-sdk-1.7/packages/addon-kit/lib/simple-storage.js
new file mode 100644
index 0000000..85395f8
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/lib/simple-storage.js
@@ -0,0 +1,237 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim:set ts=2 sw=2 sts=2 et filetype=javascript
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Cc, Ci } = require("chrome");
+const file = require("api-utils/file");
+const prefs = require("api-utils/preferences-service");
+const jpSelf = require("self");
+const timer = require("api-utils/timer");
+const unload = require("api-utils/unload");
+const { emit, on, off } = require("api-utils/event/core");
+
+const WRITE_PERIOD_PREF = "extensions.addon-sdk.simple-storage.writePeriod";
+const WRITE_PERIOD_DEFAULT = 300000; // 5 minutes
+
+const QUOTA_PREF = "extensions.addon-sdk.simple-storage.quota";
+const QUOTA_DEFAULT = 5242880; // 5 MiB
+
+const JETPACK_DIR_BASENAME = "jetpack";
+
+Object.defineProperties(exports, {
+ storage: {
+ enumerable: true,
+ get: function() { return manager.root; },
+ set: function(value) { manager.root = value; }
+ },
+ quotaUsage: {
+ get: function() { return manager.quotaUsage; }
+ }
+});
+
+// A generic JSON store backed by a file on disk. This should be isolated
+// enough to move to its own module if need be...
+function JsonStore(options) {
+ this.filename = options.filename;
+ this.quota = options.quota;
+ this.writePeriod = options.writePeriod;
+ this.onOverQuota = options.onOverQuota;
+ this.onWrite = options.onWrite;
+
+ unload.ensure(this);
+
+ this.writeTimer = timer.setInterval(this.write.bind(this),
+ this.writePeriod);
+}
+
+JsonStore.prototype = {
+ // The store's root.
+ get root() {
+ return this.isRootInited ? this._root : {};
+ },
+
+ // Performs some type checking.
+ set root(val) {
+ let types = ["array", "boolean", "null", "number", "object", "string"];
+ if (types.indexOf(typeof(val)) < 0) {
+ throw new Error("storage must be one of the following types: " +
+ types.join(", "));
+ }
+ this._root = val;
+ return val;
+ },
+
+ // True if the root has ever been set (either via the root setter or by the
+ // backing file's having been read).
+ get isRootInited() {
+ return this._root !== undefined;
+ },
+
+ // Percentage of quota used, as a number [0, Inf). > 1 implies over quota.
+ // Undefined if there is no quota.
+ get quotaUsage() {
+ return this.quota > 0 ?
+ JSON.stringify(this.root).length / this.quota :
+ undefined;
+ },
+
+ // Removes the backing file and all empty subdirectories.
+ purge: function JsonStore_purge() {
+ try {
+ // This'll throw if the file doesn't exist.
+ file.remove(this.filename);
+ let parentPath = this.filename;
+ do {
+ parentPath = file.dirname(parentPath);
+ // This'll throw if the dir isn't empty.
+ file.rmdir(parentPath);
+ } while (file.basename(parentPath) !== JETPACK_DIR_BASENAME);
+ }
+ catch (err) {}
+ },
+
+ // Initializes the root by reading the backing file.
+ read: function JsonStore_read() {
+ try {
+ let str = file.read(this.filename);
+
+ // Ideally we'd log the parse error with console.error(), but logged
+ // errors cause tests to fail. Supporting "known" errors in the test
+ // harness appears to be non-trivial. Maybe later.
+ this.root = JSON.parse(str);
+ }
+ catch (err) {
+ this.root = {};
+ }
+ },
+
+ // If the store is under quota, writes the root to the backing file.
+ // Otherwise quota observers are notified and nothing is written.
+ write: function JsonStore_write() {
+ if (this.quotaUsage > 1)
+ this.onOverQuota(this);
+ else
+ this._write();
+ },
+
+ // Cleans up on unload. If unloading because of uninstall, the store is
+ // purged; otherwise it's written.
+ unload: function JsonStore_unload(reason) {
+ timer.clearInterval(this.writeTimer);
+ this.writeTimer = null;
+
+ if (reason === "uninstall")
+ this.purge();
+ else
+ this._write();
+ },
+
+ // True if the root is an empty object.
+ get _isEmpty() {
+ if (this.root && typeof(this.root) === "object") {
+ let empty = true;
+ for (let key in this.root) {
+ empty = false;
+ break;
+ }
+ return empty;
+ }
+ return false;
+ },
+
+ // Writes the root to the backing file, notifying write observers when
+ // complete. If the store is over quota or if it's empty and the store has
+ // never been written, nothing is written and write observers aren't notified.
+ _write: function JsonStore__write() {
+ // Don't write if the root is uninitialized or if the store is empty and the
+ // backing file doesn't yet exist.
+ if (!this.isRootInited || (this._isEmpty && !file.exists(this.filename)))
+ return;
+
+ // If the store is over quota, don't write. The current under-quota state
+ // should persist.
+ if (this.quotaUsage > 1)
+ return;
+
+ // Finally, write.
+ let stream = file.open(this.filename, "w");
+ try {
+ stream.writeAsync(JSON.stringify(this.root), function writeAsync(err) {
+ if (err)
+ console.error("Error writing simple storage file: " + this.filename);
+ else if (this.onWrite)
+ this.onWrite(this);
+ }.bind(this));
+ }
+ catch (err) {
+ // writeAsync closes the stream after it's done, so only close on error.
+ stream.close();
+ }
+ }
+};
+
+
+// This manages a JsonStore singleton and tailors its use to simple storage.
+// The root of the JsonStore is lazy-loaded: The backing file is only read the
+// first time the root's gotten.
+let manager = ({
+ jsonStore: null,
+
+ // The filename of the store, based on the profile dir and extension ID.
+ get filename() {
+ let storeFile = Cc["@mozilla.org/file/directory_service;1"].
+ getService(Ci.nsIProperties).
+ get("ProfD", Ci.nsIFile);
+ storeFile.append(JETPACK_DIR_BASENAME);
+ storeFile.append(jpSelf.id);
+ storeFile.append("simple-storage");
+ file.mkpath(storeFile.path);
+ storeFile.append("store.json");
+ return storeFile.path;
+ },
+
+ get quotaUsage() {
+ return this.jsonStore.quotaUsage;
+ },
+
+ get root() {
+ if (!this.jsonStore.isRootInited)
+ this.jsonStore.read();
+ return this.jsonStore.root;
+ },
+
+ set root(val) {
+ return this.jsonStore.root = val;
+ },
+
+ unload: function manager_unload() {
+ off(this);
+ },
+
+ new: function manager_constructor() {
+ let manager = Object.create(this);
+ unload.ensure(manager);
+
+ manager.jsonStore = new JsonStore({
+ filename: manager.filename,
+ writePeriod: prefs.get(WRITE_PERIOD_PREF, WRITE_PERIOD_DEFAULT),
+ quota: prefs.get(QUOTA_PREF, QUOTA_DEFAULT),
+ onOverQuota: emit.bind(null, exports, "OverQuota")
+ });
+
+ return manager;
+ }
+}).new();
+
+// This is workaround making sure that exports is wrapped before it's
+// frozen, which needs to happen in order to workaround Bug 673468.
+off(exports, 'workaround-bug-673468');
+
+exports.on = on.bind(null, exports);
+exports.removeListener = function(type, listener) {
+ off(exports, type, listener);
+};
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/lib/tabs.js b/tools/addon-sdk-1.7/packages/addon-kit/lib/tabs.js
new file mode 100644
index 0000000..ab915f5
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/lib/tabs.js
@@ -0,0 +1,28 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+if (!require("api-utils/xul-app").is("Firefox")) {
+ throw new Error([
+ "The tabs module currently supports only Firefox. In the future ",
+ "we would like it to support other applications, however. Please see ",
+ "https://bugzilla.mozilla.org/show_bug.cgi?id=560716 for more information."
+ ].join(""));
+}
+
+const { browserWindows } = require("./windows");
+const { tabs } = require("api-utils/windows/tabs");
+
+Object.defineProperties(tabs, {
+ open: { value: function open(options) {
+ if (options.inNewWindow)
+ // `tabs` option is under review and may be removed.
+ return browserWindows.open({ tabs: [ options ] });
+ // Open in active window if new window was not required.
+ return browserWindows.activeWindow.tabs.open(options);
+ }}
+});
+// It's a hack but we will be able to remove it once will implement CommonJS
+// feature that would allow us to override exports.
+exports.__proto__ = tabs;
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/lib/timers.js b/tools/addon-sdk-1.7/packages/addon-kit/lib/timers.js
new file mode 100644
index 0000000..45fcf8d
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/lib/timers.js
@@ -0,0 +1,8 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+// This module just proxies to the low level equivalent "timer" in "api-utils".
+module.exports = require("api-utils/timer");
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/lib/widget.js b/tools/addon-sdk-1.7/packages/addon-kit/lib/widget.js
new file mode 100644
index 0000000..e0bbfb6
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/lib/widget.js
@@ -0,0 +1,923 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+// Widget content types
+const CONTENT_TYPE_URI = 1;
+const CONTENT_TYPE_HTML = 2;
+const CONTENT_TYPE_IMAGE = 3;
+
+const ERR_CONTENT = "No content or contentURL property found. Widgets must "
+ + "have one or the other.",
+ ERR_LABEL = "The widget must have a non-empty label property.",
+ ERR_ID = "You have to specify a unique value for the id property of " +
+ "your widget in order for the application to remember its " +
+ "position.",
+ ERR_DESTROYED = "The widget has been destroyed and can no longer be used.";
+
+// Supported events, mapping from DOM event names to our event names
+const EVENTS = {
+ "click": "click",
+ "mouseover": "mouseover",
+ "mouseout": "mouseout",
+};
+
+if (!require("api-utils/xul-app").is("Firefox")) {
+ throw new Error([
+ "The widget module currently supports only Firefox. In the future ",
+ "it will support other applications. Please see ",
+ "https://bugzilla.mozilla.org/show_bug.cgi?id=560716 for more information."
+ ].join(""));
+}
+
+const { validateOptions } = require("api-utils/api-utils");
+const panels = require("./panel");
+const { EventEmitter, EventEmitterTrait } = require("api-utils/events");
+const { Trait } = require("api-utils/traits");
+const LightTrait = require('api-utils/light-traits').Trait;
+const { Loader, Symbiont } = require("api-utils/content");
+const { Cortex } = require('api-utils/cortex');
+const windowsAPI = require("./windows");
+const { setTimeout } = require("api-utils/timer");
+const unload = require("api-utils/unload");
+const { uuid } = require("api-utils/uuid");
+
+// Data types definition
+const valid = {
+ number: { is: ["null", "undefined", "number"] },
+ string: { is: ["null", "undefined", "string"] },
+ id: {
+ is: ["string"],
+ ok: function (v) v.length > 0,
+ msg: ERR_ID,
+ readonly: true
+ },
+ label: {
+ is: ["string"],
+ ok: function (v) v.length > 0,
+ msg: ERR_LABEL
+ },
+ panel: {
+ is: ["null", "undefined", "object"],
+ ok: function(v) !v || v instanceof panels.Panel
+ },
+ width: {
+ is: ["null", "undefined", "number"],
+ map: function (v) {
+ if (null === v || undefined === v) v = 16;
+ return v;
+ },
+ defaultValue: 16
+ },
+ allow: {
+ is: ["null", "undefined", "object"],
+ map: function (v) {
+ if (!v) v = { script: true };
+ return v;
+ },
+ get defaultValue() ({ script: true })
+ },
+};
+
+// Widgets attributes definition
+let widgetAttributes = {
+ label: valid.label,
+ id: valid.id,
+ tooltip: valid.string,
+ width: valid.width,
+ content: valid.string,
+ panel: valid.panel,
+ allow: valid.allow
+};
+
+// Import data definitions from loader, but don't compose with it as Model
+// functions allow us to recreate easily all Loader code.
+let loaderAttributes = require("api-utils/content/loader").validationAttributes;
+for (let i in loaderAttributes)
+ widgetAttributes[i] = loaderAttributes[i];
+
+widgetAttributes.contentURL.optional = true;
+
+// Widgets public events list, that are automatically binded in options object
+const WIDGET_EVENTS = [
+ "click",
+ "mouseover",
+ "mouseout",
+ "error",
+ "message",
+ "attach"
+];
+
+// `Model` utility functions that help creating these various Widgets objects
+let model = {
+
+ // Validate one attribute using api-utils.js:validateOptions function
+ _validate: function _validate(name, suspect, validation) {
+ let $1 = {};
+ $1[name] = suspect;
+ let $2 = {};
+ $2[name] = validation;
+ return validateOptions($1, $2)[name];
+ },
+
+ /**
+ * This method has two purposes:
+ * 1/ Validate and define, on a given object, a set of attribute
+ * 2/ Emit a "change" event on this object when an attribute is changed
+ *
+ * @params {Object} object
+ * Object on which we can bind attributes on and watch for their changes.
+ * This object must have an EventEmitter interface, or, at least `_emit`
+ * method
+ * @params {Object} attrs
+ * Dictionary of attributes definition following api-utils:validateOptions
+ * scheme
+ * @params {Object} values
+ * Dictionary of attributes default values
+ */
+ setAttributes: function setAttributes(object, attrs, values) {
+ let properties = {};
+ for (let name in attrs) {
+ let value = values[name];
+ let req = attrs[name];
+
+ // Retrieve default value from typedef if the value is not defined
+ if ((typeof value == "undefined" || value == null) && req.defaultValue)
+ value = req.defaultValue;
+
+ // Check for valid value if value is defined or mandatory
+ if (!req.optional || typeof value != "undefined")
+ value = model._validate(name, value, req);
+
+ // In any case, define this property on `object`
+ let property = null;
+ if (req.readonly) {
+ property = {
+ value: value,
+ writable: false,
+ enumerable: true,
+ configurable: false
+ };
+ }
+ else {
+ property = model._createWritableProperty(name, value);
+ }
+
+ properties[name] = property;
+ }
+ Object.defineProperties(object, properties);
+ },
+
+ // Generate ES5 property definition for a given attribute
+ _createWritableProperty: function _createWritableProperty(name, value) {
+ return {
+ get: function () {
+ return value;
+ },
+ set: function (newValue) {
+ value = newValue;
+ // The main goal of all this Model stuff is here:
+ // We want to forward all changes to some listeners
+ this._emit("change", name, value);
+ },
+ enumerable: true,
+ configurable: false
+ };
+ },
+
+ /**
+ * Automagically register listeners in options dictionary
+ * by detecting listener attributes with name starting with `on`
+ *
+ * @params {Object} object
+ * Target object that need to follow EventEmitter interface, or, at least,
+ * having `on` method.
+ * @params {Array} events
+ * List of events name to automatically bind.
+ * @params {Object} listeners
+ * Dictionary of event listener functions to register.
+ */
+ setEvents: function setEvents(object, events, listeners) {
+ for (let i = 0, l = events.length; i < l; i++) {
+ let name = events[i];
+ let onName = "on" + name[0].toUpperCase() + name.substr(1);
+ if (!listeners[onName])
+ continue;
+ object.on(name, listeners[onName].bind(object));
+ }
+ }
+
+};
+
+
+/**
+ * Main Widget class: entry point of the widget API
+ *
+ * Allow to control all widget across all existing windows with a single object.
+ * Widget.getView allow to retrieve a WidgetView instance to control a widget
+ * specific to one window.
+ */
+const WidgetTrait = LightTrait.compose(EventEmitterTrait, LightTrait({
+
+ _initWidget: function _initWidget(options) {
+ model.setAttributes(this, widgetAttributes, options);
+
+ browserManager.validate(this);
+
+ // We must have at least content or contentURL defined
+ if (!(this.content || this.contentURL))
+ throw new Error(ERR_CONTENT);
+
+ this._views = [];
+
+ // Set tooltip to label value if we don't have tooltip defined
+ if (!this.tooltip)
+ this.tooltip = this.label;
+
+ model.setEvents(this, WIDGET_EVENTS, options);
+
+ this.on('change', this._onChange.bind(this));
+
+ let self = this;
+ this._port = EventEmitterTrait.create({
+ emit: function () {
+ let args = arguments;
+ self._views.forEach(function(v) v.port.emit.apply(v.port, args));
+ }
+ });
+ // expose wrapped port, that exposes only public properties.
+ this._port._public = Cortex(this._port);
+
+ // Register this widget to browser manager in order to create new widget on
+ // all new windows
+ browserManager.addItem(this);
+ },
+
+ _onChange: function _onChange(name, value) {
+ // Set tooltip to label value if we don't have tooltip defined
+ if (name == 'tooltip' && !value) {
+ // we need to change tooltip again in order to change the value of the
+ // attribute itself
+ this.tooltip = this.label;
+ return;
+ }
+
+ // Forward attributes changes to WidgetViews
+ if (['width', 'tooltip', 'content', 'contentURL'].indexOf(name) != -1) {
+ this._views.forEach(function(v) v[name] = value);
+ }
+ },
+
+ _onEvent: function _onEvent(type, eventData) {
+ this._emit(type, eventData);
+ },
+
+ _createView: function _createView() {
+ // Create a new WidgetView instance
+ let view = WidgetView(this);
+
+ // Keep a reference to it
+ this._views.push(view);
+
+ // Emit an `attach` event with a WidgetView instance without private attrs
+ this._emit("attach", view._public);
+
+ return view;
+ },
+
+ // a WidgetView instance is destroyed
+ _onViewDestroyed: function _onViewDestroyed(view) {
+ let idx = this._views.indexOf(view);
+ this._views.splice(idx, 1);
+ },
+
+ /**
+ * Called on browser window closed, to destroy related WidgetViews
+ * @params {ChromeWindow} window
+ * Window that has been closed
+ */
+ _onWindowClosed: function _onWindowClosed(window) {
+ for each (let view in this._views) {
+ if (view._isInChromeWindow(window)) {
+ view.destroy();
+ break;
+ }
+ }
+ },
+
+ /**
+ * Get the WidgetView instance related to a BrowserWindow instance
+ * @params {BrowserWindow} window
+ * BrowserWindow reference from "windows" module
+ */
+ getView: function getView(window) {
+ for each (let view in this._views) {
+ if (view._isInWindow(window)) {
+ return view._public;
+ }
+ }
+ return null;
+ },
+
+ get port() this._port._public,
+ set port(v) {}, // Work around Cortex failure with getter without setter
+ // See bug 653464
+ _port: null,
+
+ postMessage: function postMessage(message) {
+ this._views.forEach(function(v) v.postMessage(message));
+ },
+
+ destroy: function destroy() {
+ if (this.panel)
+ this.panel.destroy();
+
+ // Dispatch destroy calls to views
+ // we need to go backward as we remove items from this array in
+ // _onViewDestroyed
+ for (let i = this._views.length - 1; i >= 0; i--)
+ this._views[i].destroy();
+
+ // Unregister widget to stop creating it over new windows
+ // and allow creation of new widget with same id
+ browserManager.removeItem(this);
+ }
+
+}));
+
+// Widget constructor
+const Widget = function Widget(options) {
+ let w = WidgetTrait.create(Widget.prototype);
+ w._initWidget(options);
+
+ // Return a Cortex of widget in order to hide private attributes like _onEvent
+ let _public = Cortex(w);
+ unload.ensure(_public, "destroy");
+ return _public;
+}
+exports.Widget = Widget;
+
+
+
+/**
+ * WidgetView is an instance of a widget for a specific window.
+ *
+ * This is an external API that can be retrieved by calling Widget.getView or
+ * by watching `attach` event on Widget.
+ */
+const WidgetViewTrait = LightTrait.compose(EventEmitterTrait, LightTrait({
+
+ // Reference to the matching WidgetChrome
+ // set right after constructor call
+ _chrome: null,
+
+ // Public interface of the WidgetView, passed in `attach` event or in
+ // Widget.getView
+ _public: null,
+
+ _initWidgetView: function WidgetView__initWidgetView(baseWidget) {
+ this._baseWidget = baseWidget;
+
+ model.setAttributes(this, widgetAttributes, baseWidget);
+
+ this.on('change', this._onChange.bind(this));
+
+ let self = this;
+ this._port = EventEmitterTrait.create({
+ emit: function () {
+ if (!self._chrome)
+ throw new Error(ERR_DESTROYED);
+ self._chrome.update(self._baseWidget, "emit", arguments);
+ }
+ });
+ // expose wrapped port, that exposes only public properties.
+ this._port._public = Cortex(this._port);
+
+ this._public = Cortex(this);
+ },
+
+ _onChange: function WidgetView__onChange(name, value) {
+ if (name == 'tooltip' && !value) {
+ this.tooltip = this.label;
+ return;
+ }
+
+ // Forward attributes changes to WidgetChrome instance
+ if (['width', 'tooltip', 'content', 'contentURL'].indexOf(name) != -1) {
+ this._chrome.update(this._baseWidget, name, value);
+ }
+ },
+
+ _onEvent: function WidgetView__onEvent(type, eventData, domNode) {
+ // Dispatch event in view
+ this._emit(type, eventData);
+
+ // And forward it to the main Widget object
+ if ("click" == type || type.indexOf("mouse") == 0)
+ this._baseWidget._onEvent(type, this._public);
+ else
+ this._baseWidget._onEvent(type, eventData);
+
+ // Special case for click events: if the widget doesn't have a click
+ // handler, but it does have a panel, display the panel.
+ if ("click" == type && !this._listeners("click").length && this.panel)
+ this.panel.show(domNode);
+ },
+
+ _isInWindow: function WidgetView__isInWindow(window) {
+ return windowsAPI.BrowserWindow({
+ window: this._chrome.window
+ }) == window;
+ },
+
+ _isInChromeWindow: function WidgetView__isInChromeWindow(window) {
+ return this._chrome.window == window;
+ },
+
+ _onPortEvent: function WidgetView__onPortEvent(args) {
+ let port = this._port;
+ port._emit.apply(port, args);
+ let basePort = this._baseWidget._port;
+ basePort._emit.apply(basePort, args);
+ },
+
+ get port() this._port._public,
+ set port(v) {}, // Work around Cortex failure with getter without setter
+ // See bug 653464
+ _port: null,
+
+ postMessage: function WidgetView_postMessage(message) {
+ if (!this._chrome)
+ throw new Error(ERR_DESTROYED);
+ this._chrome.update(this._baseWidget, "postMessage", message);
+ },
+
+ destroy: function WidgetView_destroy() {
+ this._chrome.destroy();
+ delete this._chrome;
+ this._baseWidget._onViewDestroyed(this);
+ this._emit("detach");
+ }
+
+}));
+
+const WidgetView = function WidgetView(baseWidget) {
+ let w = WidgetViewTrait.create(WidgetView.prototype);
+ w._initWidgetView(baseWidget);
+ return w;
+}
+
+
+
+/**
+ * Keeps track of all browser windows.
+ * Exposes methods for adding/removing widgets
+ * across all open windows (and future ones).
+ * Create a new instance of BrowserWindow per window.
+ */
+let browserManager = {
+ items: [],
+ windows: [],
+
+ // Registers the manager to listen for window openings and closings. Note
+ // that calling this method can cause onTrack to be called immediately if
+ // there are open windows.
+ init: function () {
+ let windowTracker = new (require("api-utils/window-utils").WindowTracker)(this);
+ unload.ensure(windowTracker);
+ },
+
+ // Registers a window with the manager. This is a WindowTracker callback.
+ onTrack: function browserManager_onTrack(window) {
+ if (this._isBrowserWindow(window)) {
+ let win = new BrowserWindow(window);
+ win.addItems(this.items);
+ this.windows.push(win);
+ }
+ },
+
+ // Unregisters a window from the manager. It's told to undo all
+ // modifications. This is a WindowTracker callback. Note that when
+ // WindowTracker is unloaded, it calls onUntrack for every currently opened
+ // window. The browserManager therefore doesn't need to specially handle
+ // unload itself, since unloading the browserManager means untracking all
+ // currently opened windows.
+ onUntrack: function browserManager_onUntrack(window) {
+ if (this._isBrowserWindow(window)) {
+ this.items.forEach(function(i) i._onWindowClosed(window));
+ for (let i = 0; i < this.windows.length; i++) {
+ if (this.windows[i].window == window) {
+ this.windows.splice(i, 1)[0];
+ return;
+ }
+ }
+
+ }
+ },
+
+ // Used to validate widget by browserManager before adding it,
+ // in order to check input very early in widget constructor
+ validate : function (item) {
+ let idx = this.items.indexOf(item);
+ if (idx > -1)
+ throw new Error("The widget " + item + " has already been added.");
+ if (item.id) {
+ let sameId = this.items.filter(function(i) i.id == item.id);
+ if (sameId.length > 0)
+ throw new Error("This widget ID is already used: " + item.id);
+ } else {
+ item.id = this.items.length;
+ }
+ },
+
+ // Registers an item with the manager. It's added to all currently registered
+ // windows, and when new windows are registered it will be added to them, too.
+ addItem: function browserManager_addItem(item) {
+ this.items.push(item);
+ this.windows.forEach(function (w) w.addItems([item]));
+ },
+
+ // Unregisters an item from the manager. It's removed from all windows that
+ // are currently registered.
+ removeItem: function browserManager_removeItem(item) {
+ let idx = this.items.indexOf(item);
+ if (idx > -1)
+ this.items.splice(idx, 1);
+ },
+
+ _isBrowserWindow: function browserManager__isBrowserWindow(win) {
+ let winType = win.document.documentElement.getAttribute("windowtype");
+ return winType === "navigator:browser";
+ }
+};
+
+
+
+/**
+ * Keeps track of a single browser window.
+ *
+ * This is where the core of how a widget's content is added to a window lives.
+ */
+function BrowserWindow(window) {
+ this.window = window;
+ this.doc = window.document;
+}
+
+BrowserWindow.prototype = {
+
+ // Adds an array of items to the window.
+ addItems: function BW_addItems(items) {
+ items.forEach(this._addItemToWindow, this);
+ },
+
+ _addItemToWindow: function BW__addItemToWindow(baseWidget) {
+ // Create a WidgetView instance
+ let widget = baseWidget._createView();
+
+ // Create a WidgetChrome instance
+ let item = new WidgetChrome({
+ widget: widget,
+ doc: this.doc,
+ window: this.window
+ });
+
+ widget._chrome = item;
+
+ this._insertNodeInToolbar(item.node);
+
+ // We need to insert Widget DOM Node before finishing widget view creation
+ // (because fill creates an iframe and tries to access its docShell)
+ item.fill();
+ },
+
+ _insertNodeInToolbar: function BW__insertNodeInToolbar(node) {
+ // Add to the customization palette
+ let toolbox = this.doc.getElementById("navigator-toolbox");
+ let palette = toolbox.palette;
+ palette.appendChild(node);
+
+ // Search for widget toolbar by reading toolbar's currentset attribute
+ let container = null;
+ let toolbars = this.doc.getElementsByTagName("toolbar");
+ let id = node.getAttribute("id");
+ for (let i = 0, l = toolbars.length; i < l; i++) {
+ let toolbar = toolbars[i];
+ if (toolbar.getAttribute("currentset").indexOf(id) == -1)
+ continue;
+ container = toolbar;
+ }
+
+ // if widget isn't in any toolbar, add it to the addon-bar
+ // TODO: we may want some "first-launch" module to do this only on very
+ // first execution
+ if (!container) {
+ container = this.doc.getElementById("addon-bar");
+ // TODO: find a way to make the following code work when we use "cfx run":
+ // http://mxr.mozilla.org/mozilla-central/source/browser/base/content/browser.js#8586
+ // until then, force display of addon bar directly from sdk code
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=627484
+ if (container.collapsed)
+ this.window.toggleAddonBar();
+ }
+
+ // Now retrieve a reference to the next toolbar item
+ // by reading currentset attribute on the toolbar
+ let nextNode = null;
+ let currentSet = container.getAttribute("currentset");
+ let ids = (currentSet == "__empty") ? [] : currentSet.split(",");
+ let idx = ids.indexOf(id);
+ if (idx != -1) {
+ for (let i = idx; i < ids.length; i++) {
+ nextNode = this.doc.getElementById(ids[i]);
+ if (nextNode)
+ break;
+ }
+ }
+
+ // Finally insert our widget in the right toolbar and in the right position
+ container.insertItem(id, nextNode, null, false);
+
+ // Update DOM in order to save position: which toolbar, and which position
+ // in this toolbar. But only do this the first time we add it to the toolbar
+ // Otherwise, this code will collide with other instance of Widget module
+ // during Firefox startup. See bug 685929.
+ if (ids.indexOf(id) == -1) {
+ container.setAttribute("currentset", container.currentSet);
+ // Save DOM attribute in order to save position on new window opened
+ this.window.document.persist(container.id, "currentset");
+ }
+ }
+}
+
+
+/**
+ * Final Widget class that handles chrome DOM Node:
+ * - create initial DOM nodes
+ * - receive instruction from WidgetView through update method and update DOM
+ * - watch for DOM events and forward them to WidgetView
+ */
+function WidgetChrome(options) {
+ this.window = options.window;
+ this._doc = options.doc;
+ this._widget = options.widget;
+ this._symbiont = null; // set later
+ this.node = null; // set later
+
+ this._createNode();
+}
+
+// Update a property of a widget.
+WidgetChrome.prototype.update = function WC_update(updatedItem, property, value) {
+ switch(property) {
+ case "contentURL":
+ case "content":
+ this.setContent();
+ break;
+ case "width":
+ this.node.style.minWidth = value + "px";
+ this.node.querySelector("iframe").style.width = value + "px";
+ break;
+ case "tooltip":
+ this.node.setAttribute("tooltiptext", value);
+ break;
+ case "postMessage":
+ this._symbiont.postMessage(value);
+ break;
+ case "emit":
+ let port = this._symbiont.port;
+ port.emit.apply(port, value);
+ break;
+ }
+}
+
+// Add a widget to this window.
+WidgetChrome.prototype._createNode = function WC__createNode() {
+ // XUL element container for widget
+ let node = this._doc.createElement("toolbaritem");
+ let guid = String(uuid());
+
+ // Temporary work around require("self") failing on unit-test execution ...
+ let jetpackID = "testID";
+ try {
+ jetpackID = require("self").id;
+ } catch(e) {}
+
+ // Compute an unique and stable widget id with jetpack id and widget.id
+ let id = "widget:" + jetpackID + "-" + this._widget.id;
+ node.setAttribute("id", id);
+ node.setAttribute("label", this._widget.label);
+ node.setAttribute("tooltiptext", this._widget.tooltip);
+ node.setAttribute("align", "center");
+ // Bug 626326: Prevent customize toolbar context menu to appear
+ node.setAttribute("context", "");
+
+ // TODO move into a stylesheet, configurable by consumers.
+ // Either widget.style, exposing the style object, or a URL
+ // (eg, can load local stylesheet file).
+ node.setAttribute("style", [
+ "overflow: hidden; margin: 1px 2px 1px 2px; padding: 0px;",
+ "min-height: 16px;",
+ ].join(""));
+
+ node.style.minWidth = this._widget.width + "px";
+
+ this.node = node;
+}
+
+// Initial population of a widget's content.
+WidgetChrome.prototype.fill = function WC_fill() {
+ // Create element
+ var iframe = this._doc.createElement("iframe");
+ iframe.setAttribute("type", "content");
+ iframe.setAttribute("transparent", "transparent");
+ iframe.style.overflow = "hidden";
+ iframe.style.height = "16px";
+ iframe.style.maxHeight = "16px";
+ iframe.style.width = this._widget.width + "px";
+ iframe.setAttribute("flex", "1");
+ iframe.style.border = "none";
+ iframe.style.padding = "0px";
+
+ // Do this early, because things like contentWindow are null
+ // until the node is attached to a document.
+ this.node.appendChild(iframe);
+
+ // add event handlers
+ this.addEventHandlers();
+
+ // set content
+ this.setContent();
+}
+
+// Get widget content type.
+WidgetChrome.prototype.getContentType = function WC_getContentType() {
+ if (this._widget.content)
+ return CONTENT_TYPE_HTML;
+ return (this._widget.contentURL && /\.(jpg|gif|png|ico)$/.test(this._widget.contentURL))
+ ? CONTENT_TYPE_IMAGE : CONTENT_TYPE_URI;
+}
+
+// Set widget content.
+WidgetChrome.prototype.setContent = function WC_setContent() {
+ let type = this.getContentType();
+ let contentURL = null;
+
+ switch (type) {
+ case CONTENT_TYPE_HTML:
+ contentURL = "data:text/html," + encodeURIComponent(this._widget.content);
+ break;
+ case CONTENT_TYPE_URI:
+ contentURL = this._widget.contentURL;
+ break;
+ case CONTENT_TYPE_IMAGE:
+ let imageURL = this._widget.contentURL;
+ contentURL = "data:text/html,<html><body><img src='" +
+ encodeURI(imageURL) + "'></body></html>";
+ break;
+ default:
+ throw new Error("The widget's type cannot be determined.");
+ }
+
+ let iframe = this.node.firstElementChild;
+
+ let self = this;
+ // Cleanup previously created symbiont (in case we are update content)
+ if (this._symbiont)
+ this._symbiont.destroy();
+
+ this._symbiont = Trait.compose(Symbiont.resolve({
+ _onContentScriptEvent: "_onContentScriptEvent-not-used"
+ }), {
+ _onContentScriptEvent: function () {
+ // Redirect events to WidgetView
+ self._widget._onPortEvent(arguments);
+ }
+ })({
+ frame: iframe,
+ contentURL: contentURL,
+ contentScriptFile: this._widget.contentScriptFile,
+ contentScript: this._widget.contentScript,
+ contentScriptWhen: this._widget.contentScriptWhen,
+ allow: this._widget.allow,
+ onMessage: function(message) {
+ setTimeout(function() {
+ self._widget._onEvent("message", message);
+ }, 0);
+ }
+ });
+}
+
+// Detect if document consists of a single image.
+WidgetChrome._isImageDoc = function WC__isImageDoc(doc) {
+ return doc.body.childNodes.length == 1 &&
+ doc.body.firstElementChild &&
+ doc.body.firstElementChild.tagName == "IMG";
+}
+
+// Set up all supported events for a widget.
+WidgetChrome.prototype.addEventHandlers = function WC_addEventHandlers() {
+ let contentType = this.getContentType();
+
+ let self = this;
+ let listener = function(e) {
+ // Ignore event firings that target the iframe.
+ if (e.target == self.node.firstElementChild)
+ return;
+
+ // The widget only supports left-click for now,
+ // so ignore right-clicks.
+ if (e.type == "click" && e.button == 2)
+ return;
+
+ // Proxy event to the widget
+ setTimeout(function() {
+ self._widget._onEvent(EVENTS[e.type], null, self.node);
+ }, 0);
+ };
+
+ this.eventListeners = {};
+ let iframe = this.node.firstElementChild;
+ for (let [type, method] in Iterator(EVENTS)) {
+ iframe.addEventListener(type, listener, true, true);
+
+ // Store listeners for later removal
+ this.eventListeners[type] = listener;
+ }
+
+ // On document load, make modifications required for nice default
+ // presentation.
+ function loadListener(e) {
+ let containerStyle = self.window.getComputedStyle(self.node.parentNode);
+ // Ignore event firings that target the iframe
+ if (e.target == iframe)
+ return;
+ // Ignore about:blank loads
+ if (e.type == "load" && e.target.location == "about:blank")
+ return;
+
+ // We may have had an unload event before that cleaned up the symbiont
+ if (!self._symbiont)
+ self.setContent();
+
+ let doc = e.target;
+ if (contentType == CONTENT_TYPE_IMAGE || WidgetChrome._isImageDoc(doc)) {
+ // Force image content to size.
+ // Add-on authors must size their images correctly.
+ doc.body.firstElementChild.style.width = self._widget.width + "px";
+ doc.body.firstElementChild.style.height = "16px";
+ }
+
+ // Extend the add-on bar's default text styles to the widget.
+ doc.body.style.color = containerStyle.color;
+ doc.body.style.fontFamily = containerStyle.fontFamily;
+ doc.body.style.fontSize = containerStyle.fontSize;
+ doc.body.style.fontWeight = containerStyle.fontWeight;
+ doc.body.style.textShadow = containerStyle.textShadow;
+ // Allow all content to fill the box by default.
+ doc.body.style.margin = "0";
+ }
+ iframe.addEventListener("load", loadListener, true);
+ this.eventListeners["load"] = loadListener;
+
+ // Register a listener to unload symbiont if the toolbaritem is moved
+ // on user toolbars customization
+ function unloadListener(e) {
+ if (e.target.location == "about:blank")
+ return;
+ self._symbiont.destroy();
+ self._symbiont = null;
+ // This may fail but not always, it depends on how the node is
+ // moved or removed
+ try {
+ self.setContent();
+ } catch(e) {}
+
+ }
+
+ iframe.addEventListener("unload", unloadListener, true);
+ this.eventListeners["unload"] = unloadListener;
+}
+
+// Remove and unregister the widget from everything
+WidgetChrome.prototype.destroy = function WC_destroy(removedItems) {
+ // remove event listeners
+ for (let [type, listener] in Iterator(this.eventListeners))
+ this.node.firstElementChild.removeEventListener(type, listener, true);
+ // remove dom node
+ this.node.parentNode.removeChild(this.node);
+ // cleanup symbiont
+ this._symbiont.destroy();
+ // cleanup itself
+ this.eventListeners = null;
+ this._widget = null;
+ this._symbiont = null;
+}
+
+// Init the browserManager only after setting prototypes and such above, because
+// it will cause browserManager.onTrack to be called immediately if there are
+// open windows.
+browserManager.init();
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/lib/windows.js b/tools/addon-sdk-1.7/packages/addon-kit/lib/windows.js
new file mode 100644
index 0000000..8f13e6c
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/lib/windows.js
@@ -0,0 +1,210 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+if (!require("api-utils/xul-app").is("Firefox")) {
+ throw new Error([
+ "The windows module currently supports only Firefox. In the future",
+ " we would like it to support other applications, however. Please see ",
+ "https://bugzilla.mozilla.org/show_bug.cgi?id=571449 for more information."
+ ].join(""));
+}
+
+const { Cc, Ci } = require('chrome'),
+ { Trait } = require('api-utils/traits'),
+ { List } = require('api-utils/list'),
+ { EventEmitter } = require('api-utils/events'),
+ { WindowTabs, WindowTabTracker } = require('api-utils/windows/tabs'),
+ { WindowDom } = require('api-utils/windows/dom'),
+ { WindowLoader } = require('api-utils/windows/loader'),
+ { WindowTrackerTrait } = require('api-utils/window-utils'),
+ { Options } = require('api-utils/tabs/tab'),
+ apiUtils = require('api-utils/api-utils'),
+ unload = require('api-utils/unload'),
+
+ WM = Cc['@mozilla.org/appshell/window-mediator;1'].
+ getService(Ci.nsIWindowMediator),
+
+ BROWSER = 'navigator:browser';
+
+/**
+ * Window trait composes safe wrappers for browser window that are E10S
+ * compatible.
+ */
+const BrowserWindowTrait = Trait.compose(
+ EventEmitter,
+ WindowDom.resolve({ close: '_close' }),
+ WindowTabs,
+ WindowTabTracker,
+ WindowLoader,
+ /* WindowSidebars, */
+ Trait.compose({
+ _emit: Trait.required,
+ _close: Trait.required,
+ _load: Trait.required,
+ /**
+ * Constructor returns wrapper of the specified chrome window.
+ * @param {nsIWindow} window
+ */
+ constructor: function BrowserWindow(options) {
+ // Register this window ASAP, in order to avoid loop that would try
+ // to create this window instance over and over (see bug 648244)
+ windows.push(this);
+
+ // make sure we don't have unhandled errors
+ this.on('error', console.exception.bind(console));
+
+ if ('onOpen' in options)
+ this.on('open', options.onOpen);
+ if ('onClose' in options)
+ this.on('close', options.onClose);
+ if ('window' in options)
+ this._window = options.window;
+ if ('tabs' in options) {
+ this._tabOptions = Array.isArray(options.tabs) ?
+ options.tabs.map(Options) :
+ [ Options(options.tabs) ];
+ }
+ else if ('url' in options) {
+ this._tabOptions = [ Options(options.url) ];
+ }
+ this._load();
+ return this;
+ },
+ destroy: function () this._onUnload(),
+ _tabOptions: [],
+ _onLoad: function() {
+ try {
+ this._initWindowTabTracker();
+ } catch(e) {
+ this._emit('error', e)
+ }
+ this._emitOnObject(browserWindows, 'open', this._public);
+ },
+ _onUnload: function() {
+ if (!this._window)
+ return;
+ this._destroyWindowTabTracker();
+ this._emitOnObject(browserWindows, 'close', this._public);
+ this._window = null;
+ // Removing reference from the windows array.
+ windows.splice(windows.indexOf(this), 1);
+ this._removeAllListeners();
+ },
+ close: function close(callback) {
+ // maybe we should deprecate this with message ?
+ if (callback) this.on('close', callback);
+ return this._close();
+ }
+ })
+);
+/**
+ * Wrapper for `BrowserWindowTrait`. Creates new instance if wrapper for
+ * window doesn't exists yet. If wrapper already exists then returns it
+ * instead.
+ * @params {Object} options
+ * Options that are passed to the the `BrowserWindowTrait`
+ * @returns {BrowserWindow}
+ * @see BrowserWindowTrait
+ */
+function BrowserWindow(options) {
+ let chromeWindow = options.window;
+ for each (let window in windows) {
+ if (chromeWindow == window._window)
+ return window._public
+ }
+ let window = BrowserWindowTrait(options);
+ return window._public;
+}
+// to have proper `instanceof` behavior will go away when #596248 is fixed.
+BrowserWindow.prototype = BrowserWindowTrait.prototype;
+exports.BrowserWindow = BrowserWindow
+const windows = [];
+
+/**
+ * `BrowserWindows` trait is composed out of `List` trait and it represents
+ * "live" list of currently open browser windows. Instance mutates itself
+ * whenever new browser window gets opened / closed.
+ */
+// Very stupid to resolve all `toStrings` but this will be fixed by #596248
+const browserWindows = Trait.resolve({ toString: null }).compose(
+ List.resolve({ constructor: '_initList' }),
+ EventEmitter.resolve({ toString: null }),
+ WindowTrackerTrait.resolve({ constructor: '_initTracker', toString: null }),
+ Trait.compose({
+ _emit: Trait.required,
+ _add: Trait.required,
+ _remove: Trait.required,
+
+ // public API
+
+ /**
+ * Constructor creates instance of `Windows` that represents live list of open
+ * windows.
+ */
+ constructor: function BrowserWindows() {
+ this._trackedWindows = [];
+ this._initList();
+ this._initTracker();
+ unload.ensure(this, "_destructor");
+ },
+ _destructor: function _destructor() {
+ this._removeAllListeners('open');
+ this._removeAllListeners('close');
+ this._clear();
+ },
+ /**
+ * This property represents currently active window.
+ * Property is non-enumerable, in order to preserve array like enumeration.
+ * @type {Window|null}
+ */
+ get activeWindow() {
+ let window = WM.getMostRecentWindow(BROWSER);
+ return this._isBrowser(window) ? BrowserWindow({ window: window }) : null;
+ },
+ open: function open(options) {
+ if (typeof options === "string")
+ // `tabs` option is under review and may be removed.
+ options = { tabs: [Options(options)] };
+ return BrowserWindow(options);
+ },
+ /**
+ * Returns true if specified window is a browser window.
+ * @param {nsIWindow} window
+ * @returns {Boolean}
+ */
+ _isBrowser: function _isBrowser(window)
+ BROWSER === window.document.documentElement.getAttribute("windowtype")
+ ,
+ /**
+ * Internal listener which is called whenever new window gets open.
+ * Creates wrapper and adds to this list.
+ * @param {nsIWindow} chromeWindow
+ */
+ _onTrack: function _onTrack(chromeWindow) {
+ if (!this._isBrowser(chromeWindow)) return;
+ let window = BrowserWindow({ window: chromeWindow });
+ this._add(window);
+ this._emit('open', window);
+ },
+ /**
+ * Internal listener which is called whenever window gets closed.
+ * Cleans up references and removes wrapper from this list.
+ * @param {nsIWindow} window
+ */
+ _onUntrack: function _onUntrack(chromeWindow) {
+ if (!this._isBrowser(chromeWindow)) return;
+ let window = BrowserWindow({ window: chromeWindow });
+ this._remove(window);
+ this._emit('close', window);
+
+ // Bug 724404: do not leak this module and linked windows:
+ // We have to do it on untrack and not only when `_onUnload` is called
+ // when windows are closed, otherwise, we will leak on addon disabling.
+ window.destroy();
+ }
+ }).resolve({ toString: null })
+)();
+exports.browserWindows = browserWindows;
+
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/locale/en-GB.properties b/tools/addon-sdk-1.7/packages/addon-kit/locale/en-GB.properties
new file mode 100644
index 0000000..08db753
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/locale/en-GB.properties
@@ -0,0 +1,11 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+Translated= Yes
+
+downloadsCount=%d downloads
+downloadsCount[one]=one download
+
+pluralTest=fallback to other
+pluralTest[zero]=optional zero form
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/locale/eo.properties b/tools/addon-sdk-1.7/packages/addon-kit/locale/eo.properties
new file mode 100644
index 0000000..a979fca
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/locale/eo.properties
@@ -0,0 +1,5 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+Translated= jes
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/locale/fr-FR.properties b/tools/addon-sdk-1.7/packages/addon-kit/locale/fr-FR.properties
new file mode 100644
index 0000000..2c5ffbb
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/locale/fr-FR.properties
@@ -0,0 +1,14 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+Translated= Oui
+
+placeholderString= Placeholder %s
+
+# Plural forms
+%d downloads=%d téléchargements
+%d downloads[one]=%d téléchargement
+
+downloadsCount=%d téléchargements
+downloadsCount[one]=%d téléchargement
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/package.json b/tools/addon-sdk-1.7/packages/addon-kit/package.json
new file mode 100644
index 0000000..8cd643f
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/package.json
@@ -0,0 +1,12 @@
+{
+ "name": "addon-kit",
+ "description": "Add-on development made easy.",
+ "keywords": ["javascript", "engine", "platform", "xulrunner", "jetpack-high-level"],
+ "author": "Atul Varma (http://toolness.com/) <atul@mozilla.com>",
+ "contributors": [
+ "Myk Melez (http://melez.com/) <myk@mozilla.org>",
+ "Daniel Aquino <mr.danielaquino@gmail.com>"
+ ],
+ "license": "MPL 2.0",
+ "dependencies": ["api-utils"]
+}
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/helpers.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/helpers.js
new file mode 100644
index 0000000..399046f
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/helpers.js
@@ -0,0 +1,23 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Loader } = require("@loader");
+
+exports.Loader = function(module, globals) {
+ var options = JSON.parse(JSON.stringify(require("@packaging")));
+ options.globals = globals;
+ let loader = Loader.new(options);
+ return Object.create(loader, {
+ require: { value: Loader.require.bind(loader, module.path) },
+ sandbox: { value: function sandbox(id) {
+ let path = options.manifest[module.path].requirements[id].path;
+ return loader.sandboxes[path].sandbox;
+ }},
+ unload: { value: function unload(reason, callback) {
+ loader.unload(reason, callback);
+ }}
+ })
+};
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/pagemod-test-helpers.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/pagemod-test-helpers.js
new file mode 100644
index 0000000..7c741eb
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/pagemod-test-helpers.js
@@ -0,0 +1,67 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {Cc,Ci} = require("chrome");
+const timer = require("timer");
+const xulApp = require("xul-app");
+const { Loader } = require('./helpers');
+
+/**
+ * A helper function that creates a PageMod, then opens the specified URL
+ * and checks the effect of the page mod on 'onload' event via testCallback.
+ */
+exports.testPageMod = function testPageMod(test, testURL, pageModOptions,
+ testCallback, timeout) {
+ if (!xulApp.versionInRange(xulApp.platformVersion, "1.9.3a3", "*") &&
+ !xulApp.versionInRange(xulApp.platformVersion, "1.9.2.7", "1.9.2.*")) {
+ test.pass("Note: not testing PageMod, as it doesn't work on this platform version");
+ return null;
+ }
+
+ var wm = Cc['@mozilla.org/appshell/window-mediator;1']
+ .getService(Ci.nsIWindowMediator);
+ var browserWindow = wm.getMostRecentWindow("navigator:browser");
+ if (!browserWindow) {
+ test.pass("page-mod tests: could not find the browser window, so " +
+ "will not run. Use -a firefox to run the pagemod tests.")
+ return null;
+ }
+
+ if (timeout !== undefined)
+ test.waitUntilDone(timeout);
+ else
+ test.waitUntilDone();
+
+ let loader = Loader(module);
+ let pageMod = loader.require("page-mod");
+
+ var pageMods = [new pageMod.PageMod(opts) for each(opts in pageModOptions)];
+
+ var tabBrowser = browserWindow.gBrowser;
+ var newTab = tabBrowser.addTab(testURL);
+ tabBrowser.selectedTab = newTab;
+ var b = tabBrowser.getBrowserForTab(newTab);
+
+ function onPageLoad() {
+ b.removeEventListener("load", onPageLoad, true);
+ // Delay callback execute as page-mod content scripts may be executed on
+ // load event. So page-mod actions may not be already done.
+ // If we delay even more contentScriptWhen:'end', we may want to modify
+ // this code again.
+ timer.setTimeout(testCallback, 0,
+ b.contentWindow.wrappedJSObject,
+ function done() {
+ pageMods.forEach(function(mod) mod.destroy());
+ // XXX leaks reported if we don't close the tab?
+ tabBrowser.removeTab(newTab);
+ loader.unload();
+ test.done();
+ });
+ }
+ b.addEventListener("load", onPageLoad, true);
+
+ return pageMods;
+}
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-addon-page.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-addon-page.js
new file mode 100644
index 0000000..c0ee35d
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-addon-page.js
@@ -0,0 +1,51 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+const { isTabOpen, activateTab, openTab, closeTab } = require('api-utils/tabs/utils');
+const windows = require('api-utils/window-utils');
+const { Loader } = require('./helpers');
+const { setTimeout } = require('api-utils/timer');
+
+let uri = require('self').data.url('index.html');
+
+function isChromeVisible(window)
+ window.document.documentElement.getAttribute('disablechrome') !== 'true'
+
+exports['test that add-on page has no chrome'] = function(assert, done) {
+ let loader = Loader(module);
+ loader.require('addon-kit/addon-page');
+
+ let window = windows.activeBrowserWindow;
+ let tab = openTab(window, uri);
+
+ assert.ok(isChromeVisible(window), 'chrome is visible for non addon page');
+
+ // need to do this in another turn to make sure event listener
+ // that sets property has time to do that.
+ setTimeout(function() {
+ activateTab(tab);
+
+ assert.ok(!isChromeVisible(window), 'chrome is not visible for addon page');
+
+ closeTab(tab);
+ assert.ok(isChromeVisible(window), 'chrome is visible again');
+ loader.unload();
+ done();
+ });
+};
+
+exports['test that add-on pages is closed on unload'] = function(assert) {
+ let loader = Loader(module);
+ loader.require('addon-kit/addon-page');
+
+ let tab = openTab(windows.activeBrowserWindow, uri);
+ loader.unload();
+
+ assert.ok(isTabOpen(tab), 'add-on page tabs are closed on unload');
+};
+
+
+require('test').run(exports);
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-clipboard.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-clipboard.js
new file mode 100644
index 0000000..1819d68
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-clipboard.js
@@ -0,0 +1,64 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+// Test the typical use case, setting & getting with no flavors specified
+exports.testWithNoFlavor = function(test) {
+ var contents = "hello there";
+ var flavor = "text";
+ var fullFlavor = "text/unicode";
+ var clip = require("clipboard");
+ // Confirm we set the clipboard
+ test.assert(clip.set(contents));
+ // Confirm flavor is set
+ test.assertEqual(clip.currentFlavors[0], flavor);
+ // Confirm we set the clipboard
+ test.assertEqual(clip.get(), contents);
+ // Confirm we can get the clipboard using the flavor
+ test.assertEqual(clip.get(flavor), contents);
+ // Confirm we can still get the clipboard using the full flavor
+ test.assertEqual(clip.get(fullFlavor), contents);
+};
+
+// Test the slightly less common case where we specify the flavor
+exports.testWithFlavor = function(test) {
+ var contents = "<b>hello there</b>";
+ var contentsText = "hello there";
+ var flavor = "html";
+ var fullFlavor = "text/html";
+ var unicodeFlavor = "text";
+ var unicodeFullFlavor = "text/unicode";
+ var clip = require("clipboard");
+ test.assert(clip.set(contents, flavor));
+ test.assertEqual(clip.currentFlavors[0], unicodeFlavor);
+ test.assertEqual(clip.currentFlavors[1], flavor);
+ test.assertEqual(clip.get(), contentsText);
+ test.assertEqual(clip.get(flavor), contents);
+ test.assertEqual(clip.get(fullFlavor), contents);
+ test.assertEqual(clip.get(unicodeFlavor), contentsText);
+ test.assertEqual(clip.get(unicodeFullFlavor), contentsText);
+};
+
+// Test that the typical case still works when we specify the flavor to set
+exports.testWithRedundantFlavor = function(test) {
+ var contents = "<b>hello there</b>";
+ var flavor = "text";
+ var fullFlavor = "text/unicode";
+ var clip = require("clipboard");
+ test.assert(clip.set(contents, flavor));
+ test.assertEqual(clip.currentFlavors[0], flavor);
+ test.assertEqual(clip.get(), contents);
+ test.assertEqual(clip.get(flavor), contents);
+ test.assertEqual(clip.get(fullFlavor), contents);
+};
+
+exports.testNotInFlavor = function(test) {
+ var contents = "hello there";
+ var flavor = "html";
+ var clip = require("clipboard");
+ test.assert(clip.set(contents));
+ // If there's nothing on the clipboard with this flavor, should return null
+ test.assertEqual(clip.get(flavor), null);
+};
+// TODO: Test error cases.
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-context-menu.html b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-context-menu.html
new file mode 100644
index 0000000..4196d5f
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-context-menu.html
@@ -0,0 +1,45 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<html>
+ <head>
+ <title>Context menu test</title>
+ </head>
+ <body>
+ <p>
+ <img id="image" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHWSURBVHjaYvz//z8DJQAggJiQOe/fv2fv7Oz8rays/N+VkfG/iYnJfyD/1+rVq7ffu3dPFpsBAAHEAHIBCJ85c8bN2Nj4vwsDw/8zQLwKiO8CcRoQu0DxqlWrdsHUwzBAAIGJmTNnPgYa9j8UqhFElwPxf2MIDeIrKSn9FwSJoRkAEEAM0DD4DzMAyPi/G+QKY4hh5WAXGf8PDQ0FGwJ22d27CjADAAIIrLmjo+MXA9R2kAHvGBA2wwx6B8W7od6CeQcggKCmCEL8bgwxYCbUIGTDVkHDBia+CuotgACCueD3TDQN75D4xmAvCoK9ARMHBzAw0AECiBHkAlC0Mdy7x9ABNA3obAZXIAa6iKEcGlMVQHwWyjYuL2d4v2cPg8vZswx7gHyAAAK7AOif7SAbOqCmn4Ha3AHFsIDtgPq/vLz8P4MSkJ2W9h8ggBjevXvHDo4FQUQg/kdypqCg4H8lUIACnQ/SOBMYI8bAsAJFPcj1AAEEjwVQqLpAbXmH5BJjqI0gi9DTAAgDBBCcAVLkgmQ7yKCZxpCQxqUZhAECCJ4XgMl493ug21ZD+aDAXH0WLM4A9MZPXJkJIIAwTAR5pQMalaCABQUULttBGCCAGCnNzgABBgAMJ5THwGvJLAAAAABJRU5ErkJggg==">
+ </p>
+
+ <p>
+ <a id="link" href="">
+ A simple link.
+ </a>
+ </p>
+
+ <p>
+ <a href="">
+ <span id="span-link">
+ A span inside a link.
+ </span>
+ </a>
+ </p>
+
+ <p id="text">
+ Some text.
+ </p>
+
+ <p>
+ <textarea id="textfield">
+ A text field,
+ with some text.
+ </textarea>
+ </p>
+
+ <p>
+ <iframe id="iframe" src="data:text/html,An iframe."
+ width="200" height="100">
+ </iframe>
+ </p>
+ </body>
+</html>
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-context-menu.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-context-menu.js
new file mode 100644
index 0000000..c398933
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-context-menu.js
@@ -0,0 +1,2067 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+let {Cc,Ci} = require("chrome");
+const { Loader } = require('./helpers');
+
+// These should match the same constants in the module.
+const ITEM_CLASS = "jetpack-context-menu-item";
+const SEPARATOR_ID = "jetpack-context-menu-separator";
+const OVERFLOW_THRESH_DEFAULT = 10;
+const OVERFLOW_THRESH_PREF =
+ "extensions.addon-sdk.context-menu.overflowThreshold";
+const OVERFLOW_MENU_ID = "jetpack-content-menu-overflow-menu";
+const OVERFLOW_POPUP_ID = "jetpack-content-menu-overflow-popup";
+
+const TEST_DOC_URL = module.uri.replace(/\.js$/, ".html");
+
+// Destroying items that were previously created should cause them to be absent
+// from the menu.
+exports.testConstructDestroy = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ // Create an item.
+ let item = new loader.cm.Item({ label: "item" });
+ test.assertEqual(item.parentMenu, null, "item's parent menu should be null");
+
+ test.showMenu(null, function (popup) {
+
+ // It should be present when the menu is shown.
+ test.checkMenu([item], [], []);
+ popup.hidePopup();
+
+ // Destroy the item. Multiple destroys should be harmless.
+ item.destroy();
+ item.destroy();
+ test.showMenu(null, function (popup) {
+
+ // It should be removed from the menu.
+ test.checkMenu([], [], [item]);
+ test.done();
+ });
+ });
+};
+
+
+// Destroying an item twice should not cause an error.
+exports.testDestroyTwice = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let item = new loader.cm.Item({ label: "item" });
+ item.destroy();
+ item.destroy();
+
+ test.pass("Destroying an item twice should not cause an error.");
+ test.done();
+};
+
+
+// CSS selector contexts should cause their items to be present in the menu
+// when the menu is invoked on nodes that match the selectors.
+exports.testSelectorContextMatch = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let item = new loader.cm.Item({
+ label: "item",
+ data: "item",
+ context: loader.cm.SelectorContext("img")
+ });
+
+ test.withTestDoc(function (window, doc) {
+ test.showMenu(doc.getElementById("image"), function (popup) {
+ test.checkMenu([item], [], []);
+ test.done();
+ });
+ });
+};
+
+
+// CSS selector contexts should cause their items to be present in the menu
+// when the menu is invoked on nodes that have ancestors that match the
+// selectors.
+exports.testSelectorAncestorContextMatch = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let item = new loader.cm.Item({
+ label: "item",
+ data: "item",
+ context: loader.cm.SelectorContext("a[href]")
+ });
+
+ test.withTestDoc(function (window, doc) {
+ test.showMenu(doc.getElementById("span-link"), function (popup) {
+ test.checkMenu([item], [], []);
+ test.done();
+ });
+ });
+};
+
+
+// CSS selector contexts should cause their items to be absent from the menu
+// when the menu is not invoked on nodes that match or have ancestors that
+// match the selectors.
+exports.testSelectorContextNoMatch = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let item = new loader.cm.Item({
+ label: "item",
+ data: "item",
+ context: loader.cm.SelectorContext("img")
+ });
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([], [item], []);
+ test.done();
+ });
+};
+
+
+// Page contexts should cause their items to be present in the menu when the
+// menu is not invoked on an active element.
+exports.testPageContextMatch = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let items = [
+ new loader.cm.Item({
+ label: "item 0"
+ }),
+ new loader.cm.Item({
+ label: "item 1",
+ context: undefined
+ }),
+ new loader.cm.Item({
+ label: "item 2",
+ context: loader.cm.PageContext()
+ }),
+ new loader.cm.Item({
+ label: "item 3",
+ context: [loader.cm.PageContext()]
+ })
+ ];
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu(items, [], []);
+ test.done();
+ });
+};
+
+
+// Page contexts should cause their items to be absent from the menu when the
+// menu is invoked on an active element.
+exports.testPageContextNoMatch = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let items = [
+ new loader.cm.Item({
+ label: "item 0"
+ }),
+ new loader.cm.Item({
+ label: "item 1",
+ context: undefined
+ }),
+ new loader.cm.Item({
+ label: "item 2",
+ context: loader.cm.PageContext()
+ }),
+ new loader.cm.Item({
+ label: "item 3",
+ context: [loader.cm.PageContext()]
+ })
+ ];
+
+ test.withTestDoc(function (window, doc) {
+ test.showMenu(doc.getElementById("image"), function (popup) {
+ test.checkMenu([], items, []);
+ test.done();
+ });
+ });
+};
+
+
+// Selection contexts should cause items to appear when a selection exists.
+exports.testSelectionContextMatch = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let item = loader.cm.Item({
+ label: "item",
+ context: loader.cm.SelectionContext()
+ });
+
+ test.withTestDoc(function (window, doc) {
+ window.getSelection().selectAllChildren(doc.body);
+ test.showMenu(null, function (popup) {
+ test.checkMenu([item], [], []);
+ test.done();
+ });
+ });
+};
+
+
+// Selection contexts should cause items to appear when a selection exists in
+// a text field.
+exports.testSelectionContextMatchInTextField = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let item = loader.cm.Item({
+ label: "item",
+ context: loader.cm.SelectionContext()
+ });
+
+ test.withTestDoc(function (window, doc) {
+ let textfield = doc.getElementById("textfield");
+ textfield.setSelectionRange(0, textfield.value.length);
+ test.showMenu(textfield, function (popup) {
+ test.checkMenu([item], [], []);
+ test.done();
+ });
+ });
+};
+
+
+// Selection contexts should not cause items to appear when a selection does
+// not exist in a text field.
+exports.testSelectionContextNoMatchInTextField = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let item = loader.cm.Item({
+ label: "item",
+ context: loader.cm.SelectionContext()
+ });
+
+ test.withTestDoc(function (window, doc) {
+ let textfield = doc.getElementById("textfield");
+ textfield.setSelectionRange(0, 0);
+ test.showMenu(textfield, function (popup) {
+ test.checkMenu([], [item], []);
+ test.done();
+ });
+ });
+};
+
+
+// Selection contexts should not cause items to appear when a selection does
+// not exist.
+exports.testSelectionContextNoMatch = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let item = loader.cm.Item({
+ label: "item",
+ context: loader.cm.SelectionContext()
+ });
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([], [item], []);
+ test.done();
+ });
+};
+
+
+// URL contexts should cause items to appear on pages that match.
+exports.testURLContextMatch = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let items = [
+ loader.cm.Item({
+ label: "item 0",
+ context: loader.cm.URLContext(TEST_DOC_URL)
+ }),
+ loader.cm.Item({
+ label: "item 1",
+ context: loader.cm.URLContext([TEST_DOC_URL, "*.bogus.com"])
+ })
+ ];
+
+ test.withTestDoc(function (window, doc) {
+ test.showMenu(null, function (popup) {
+ test.checkMenu(items, [], []);
+ test.done();
+ });
+ });
+};
+
+
+// URL contexts should not cause items to appear on pages that do not match.
+exports.testURLContextNoMatch = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let items = [
+ loader.cm.Item({
+ label: "item 0",
+ context: loader.cm.URLContext("*.bogus.com")
+ }),
+ loader.cm.Item({
+ label: "item 1",
+ context: loader.cm.URLContext(["*.bogus.com", "*.gnarly.com"])
+ })
+ ];
+
+ test.withTestDoc(function (window, doc) {
+ test.showMenu(null, function (popup) {
+ test.checkMenu([], items, []);
+ test.done();
+ });
+ });
+};
+
+
+// Removing a non-matching URL context after its item is created and the page is
+// loaded should cause the item's content script to be evaluated.
+exports.testURLContextRemove = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let shouldBeEvaled = false;
+ let context = loader.cm.URLContext("*.bogus.com");
+ let item = loader.cm.Item({
+ label: "item",
+ context: context,
+ contentScript: 'self.postMessage("ok");',
+ onMessage: function (msg) {
+ test.assert(shouldBeEvaled,
+ "content script should be evaluated when expected");
+ shouldBeEvaled = false;
+ test.done();
+ }
+ });
+
+ test.withTestDoc(function (window, doc) {
+ shouldBeEvaled = true;
+ item.context.remove(context);
+ });
+};
+
+
+// Adding a non-matching URL context after its item is created and the page is
+// loaded should cause the item's worker to be destroyed.
+exports.testURLContextAdd = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let item = loader.cm.Item({ label: "item" });
+
+ test.withTestDoc(function (window, doc) {
+ let privatePropsKey = loader.globalScope.PRIVATE_PROPS_KEY;
+ let workerReg = item.valueOf(privatePropsKey)._workerReg;
+
+ let found = false;
+ for each (let winWorker in workerReg.winWorkers) {
+ if (winWorker.win === window) {
+ found = true;
+ break;
+ }
+ }
+ this.test.assert(found, "window should be present in worker registry");
+
+ item.context.add(loader.cm.URLContext("*.bogus.com"));
+
+ for each (let winWorker in workerReg.winWorkers)
+ this.test.assertNotEqual(winWorker.win, window,
+ "window should not be present in worker registry");
+
+ test.done();
+ });
+};
+
+
+// Content contexts that return true should cause their items to be present
+// in the menu.
+exports.testContentContextMatch = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let item = new loader.cm.Item({
+ label: "item",
+ contentScript: 'self.on("context", function () true);'
+ });
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([item], [], []);
+ test.done();
+ });
+};
+
+
+// Content contexts that return false should cause their items to be absent
+// from the menu.
+exports.testContentContextNoMatch = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let item = new loader.cm.Item({
+ label: "item",
+ contentScript: 'self.on("context", function () false);'
+ });
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([], [item], []);
+ test.done();
+ });
+};
+
+
+// Content contexts that return a string should cause their items to be present
+// in the menu and the items' labels to be updated.
+exports.testContentContextMatchString = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let item = new loader.cm.Item({
+ label: "first label",
+ contentScript: 'self.on("context", function () "second label");'
+ });
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([item], [], []);
+ test.assertEqual(item.label, "second label",
+ "item's label should be updated");
+ test.done();
+ });
+};
+
+
+// Ensure that contentScripFile is working correctly
+exports.testContentScriptFile = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ // Reject remote files
+ test.assertRaises(function() {
+ new loader.cm.Item({
+ label: "item",
+ contentScriptFile: "http://mozilla.com/context-menu.js"
+ });
+ },
+ "The 'contentScriptFile' option must be a local file URL " +
+ "or an array of local file URLs.",
+ "Item throws when contentScriptFile is a remote URL");
+
+ // But accept files from data folder
+ let item = new loader.cm.Item({
+ label: "item",
+ contentScriptFile: require("self").data.url("test-context-menu.js")
+ });
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([item], [], []);
+ test.done();
+ });
+};
+
+
+// The args passed to context listeners should be correct.
+exports.testContentContextArgs = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+ let callbacks = 0;
+
+ let item = new loader.cm.Item({
+ label: "item",
+ contentScript: 'self.on("context", function (node) {' +
+ ' let Ci = Components.interfaces;' +
+ ' self.postMessage(node instanceof Ci.nsIDOMHTMLElement);' +
+ ' return false;' +
+ '});',
+ onMessage: function (isElt) {
+ test.assert(isElt, "node should be an HTML element");
+ if (++callbacks == 2) test.done();
+ }
+ });
+
+ test.showMenu(null, function () {
+ if (++callbacks == 2) test.done();
+ });
+};
+
+// Multiple contexts imply intersection, not union, and content context
+// listeners should not be called if all declarative contexts are not current.
+exports.testMultipleContexts = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let item = new loader.cm.Item({
+ label: "item",
+ context: [loader.cm.SelectorContext("a[href]"), loader.cm.PageContext()],
+ contentScript: 'self.on("context", function () self.postMessage());',
+ onMessage: function () {
+ test.fail("Context listener should not be called");
+ }
+ });
+
+ test.withTestDoc(function (window, doc) {
+ test.showMenu(doc.getElementById("span-link"), function (popup) {
+ test.checkMenu([], [item], []);
+ test.done();
+ });
+ });
+};
+
+// Once a context is removed, it should no longer cause its item to appear.
+exports.testRemoveContext = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let ctxt = loader.cm.SelectorContext("img");
+ let item = new loader.cm.Item({
+ label: "item",
+ context: ctxt
+ });
+
+ test.withTestDoc(function (window, doc) {
+ test.showMenu(doc.getElementById("image"), function (popup) {
+
+ // The item should be present at first.
+ test.checkMenu([item], [], []);
+ popup.hidePopup();
+
+ // Remove the img context and check again.
+ item.context.remove(ctxt);
+ test.showMenu(doc.getElementById("image"), function (popup) {
+ test.checkMenu([], [item], []);
+ test.done();
+ });
+ });
+ });
+};
+
+
+// Lots of items should overflow into the overflow submenu.
+exports.testOverflow = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let items = [];
+ for (let i = 0; i < OVERFLOW_THRESH_DEFAULT + 1; i++) {
+ let item = new loader.cm.Item({ label: "item " + i });
+ items.push(item);
+ }
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu(items, [], []);
+ test.done();
+ });
+};
+
+
+// Module unload should cause all items to be removed.
+exports.testUnload = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let item = new loader.cm.Item({ label: "item" });
+
+ test.showMenu(null, function (popup) {
+
+ // The menu should contain the item.
+ test.checkMenu([item], [], []);
+ popup.hidePopup();
+
+ // Unload the module.
+ loader.unload();
+ test.showMenu(null, function (popup) {
+
+ // The item should be removed from the menu.
+ test.checkMenu([], [], [item]);
+ test.done();
+ });
+ });
+};
+
+
+// Using multiple module instances to add items without causing overflow should
+// work OK. Assumes OVERFLOW_THRESH_DEFAULT <= 2.
+exports.testMultipleModulesAdd = function (test) {
+ test = new TestHelper(test);
+ let loader0 = test.newLoader();
+ let loader1 = test.newLoader();
+
+ // Use each module to add an item, then unload each module in turn.
+ let item0 = new loader0.cm.Item({ label: "item 0" });
+ let item1 = new loader1.cm.Item({ label: "item 1" });
+
+ test.showMenu(null, function (popup) {
+
+ // The menu should contain both items.
+ test.checkMenu([item0, item1], [], []);
+ popup.hidePopup();
+
+ // Unload the first module.
+ loader0.unload();
+ test.showMenu(null, function (popup) {
+
+ // The first item should be removed from the menu.
+ test.checkMenu([item1], [], [item0]);
+ popup.hidePopup();
+
+ // Unload the second module.
+ loader1.unload();
+ test.showMenu(null, function (popup) {
+
+ // Both items should be removed from the menu.
+ test.checkMenu([], [], [item0, item1]);
+ test.done();
+ });
+ });
+ });
+};
+
+
+// Using multiple module instances to add items causing overflow should work OK.
+exports.testMultipleModulesAddOverflow = function (test) {
+ test = new TestHelper(test);
+ let loader0 = test.newLoader();
+ let loader1 = test.newLoader();
+
+ // Use module 0 to add OVERFLOW_THRESH_DEFAULT items.
+ let items0 = [];
+ for (let i = 0; i < OVERFLOW_THRESH_DEFAULT; i++) {
+ let item = new loader0.cm.Item({ label: "item 0 " + i });
+ items0.push(item);
+ }
+
+ // Use module 1 to add one item.
+ let item1 = new loader1.cm.Item({ label: "item 1" });
+
+ let allItems = items0.concat(item1);
+
+ test.showMenu(null, function (popup) {
+
+ // The menu should contain all items in overflow.
+ test.checkMenu(allItems, [], []);
+ popup.hidePopup();
+
+ // Unload the first module.
+ loader0.unload();
+ test.showMenu(null, function (popup) {
+
+ // The first items should be removed from the menu, which should not
+ // overflow.
+ test.checkMenu([item1], [], items0);
+ popup.hidePopup();
+
+ // Unload the second module.
+ loader1.unload();
+ test.showMenu(null, function (popup) {
+
+ // All items should be removed from the menu.
+ test.checkMenu([], [], allItems);
+ test.done();
+ });
+ });
+ });
+};
+
+
+// Using multiple module instances to modify the menu without causing overflow
+// should work OK. This test creates two loaders and:
+// loader0 create item -> loader1 create item -> loader0.unload ->
+// loader1.unload
+exports.testMultipleModulesDiffContexts1 = function (test) {
+ test = new TestHelper(test);
+ let loader0 = test.newLoader();
+ let loader1 = test.newLoader();
+
+ let item0 = new loader0.cm.Item({
+ label: "item 0",
+ context: loader0.cm.SelectorContext("img")
+ });
+
+ let item1 = new loader1.cm.Item({ label: "item 1" });
+
+ test.showMenu(null, function (popup) {
+
+ // The menu should contain item1.
+ test.checkMenu([item1], [item0], []);
+ popup.hidePopup();
+
+ // Unload module 0.
+ loader0.unload();
+ test.showMenu(null, function (popup) {
+
+ // item0 should be removed from the menu.
+ test.checkMenu([item1], [], [item0]);
+ popup.hidePopup();
+
+ // Unload module 1.
+ loader1.unload();
+ test.showMenu(null, function (popup) {
+
+ // Both items should be removed from the menu.
+ test.checkMenu([], [], [item0, item1]);
+ test.done();
+ });
+ });
+ });
+};
+
+
+// Using multiple module instances to modify the menu without causing overflow
+// should work OK. This test creates two loaders and:
+// loader1 create item -> loader0 create item -> loader0.unload ->
+// loader1.unload
+exports.testMultipleModulesDiffContexts2 = function (test) {
+ test = new TestHelper(test);
+ let loader0 = test.newLoader();
+ let loader1 = test.newLoader();
+
+ let item1 = new loader1.cm.Item({ label: "item 1" });
+
+ let item0 = new loader0.cm.Item({
+ label: "item 0",
+ context: loader0.cm.SelectorContext("img")
+ });
+
+ test.showMenu(null, function (popup) {
+
+ // The menu should contain item1.
+ test.checkMenu([item1], [item0], []);
+ popup.hidePopup();
+
+ // Unload module 0.
+ loader0.unload();
+ test.showMenu(null, function (popup) {
+
+ // item0 should be removed from the menu.
+ test.checkMenu([item1], [], [item0]);
+ popup.hidePopup();
+
+ // Unload module 1.
+ loader1.unload();
+ test.showMenu(null, function (popup) {
+
+ // Both items should be removed from the menu.
+ test.checkMenu([], [], [item0, item1]);
+ test.done();
+ });
+ });
+ });
+};
+
+
+// Using multiple module instances to modify the menu without causing overflow
+// should work OK. This test creates two loaders and:
+// loader0 create item -> loader1 create item -> loader1.unload ->
+// loader0.unload
+exports.testMultipleModulesDiffContexts3 = function (test) {
+ test = new TestHelper(test);
+ let loader0 = test.newLoader();
+ let loader1 = test.newLoader();
+
+ let item0 = new loader0.cm.Item({
+ label: "item 0",
+ context: loader0.cm.SelectorContext("img")
+ });
+
+ let item1 = new loader1.cm.Item({ label: "item 1" });
+
+ test.showMenu(null, function (popup) {
+
+ // The menu should contain item1.
+ test.checkMenu([item1], [item0], []);
+ popup.hidePopup();
+
+ // Unload module 1.
+ loader1.unload();
+ test.showMenu(null, function (popup) {
+
+ // item1 should be removed from the menu.
+ test.checkMenu([], [item0], [item1]);
+ popup.hidePopup();
+
+ // Unload module 0.
+ loader0.unload();
+ test.showMenu(null, function (popup) {
+
+ // Both items should be removed from the menu.
+ test.checkMenu([], [], [item0, item1]);
+ test.done();
+ });
+ });
+ });
+};
+
+
+// Using multiple module instances to modify the menu without causing overflow
+// should work OK. This test creates two loaders and:
+// loader1 create item -> loader0 create item -> loader1.unload ->
+// loader0.unload
+exports.testMultipleModulesDiffContexts4 = function (test) {
+ test = new TestHelper(test);
+ let loader0 = test.newLoader();
+ let loader1 = test.newLoader();
+
+ let item1 = new loader1.cm.Item({ label: "item 1" });
+
+ let item0 = new loader0.cm.Item({
+ label: "item 0",
+ context: loader0.cm.SelectorContext("img")
+ });
+
+ test.showMenu(null, function (popup) {
+
+ // The menu should contain item1.
+ test.checkMenu([item1], [item0], []);
+ popup.hidePopup();
+
+ // Unload module 1.
+ loader1.unload();
+ test.showMenu(null, function (popup) {
+
+ // item1 should be removed from the menu.
+ test.checkMenu([], [item0], [item1]);
+ popup.hidePopup();
+
+ // Unload module 0.
+ loader0.unload();
+ test.showMenu(null, function (popup) {
+
+ // Both items should be removed from the menu.
+ test.checkMenu([], [], [item0, item1]);
+ test.done();
+ });
+ });
+ });
+};
+
+
+// Test interactions between a loaded module, unloading another module, and the
+// menu separator and overflow submenu.
+exports.testMultipleModulesAddRemove = function (test) {
+ test = new TestHelper(test);
+ let loader0 = test.newLoader();
+ let loader1 = test.newLoader();
+
+ let item = new loader0.cm.Item({ label: "item" });
+
+ test.showMenu(null, function (popup) {
+
+ // The menu should contain the item.
+ test.checkMenu([item], [], []);
+ popup.hidePopup();
+
+ // Remove the item.
+ item.destroy();
+ test.showMenu(null, function (popup) {
+
+ // The item should be removed from the menu.
+ test.checkMenu([], [], [item]);
+ popup.hidePopup();
+
+ // Unload module 1.
+ loader1.unload();
+ test.showMenu(null, function (popup) {
+
+ // There shouldn't be any errors involving the menu separator or
+ // overflow submenu.
+ test.checkMenu([], [], [item]);
+ test.done();
+ });
+ });
+ });
+};
+
+
+// An item's click listener should work.
+exports.testItemClick = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let item = new loader.cm.Item({
+ label: "item",
+ data: "item data",
+ contentScript: 'self.on("click", function (node, data) {' +
+ ' let Ci = Components.interfaces;' +
+ ' self.postMessage({' +
+ ' isElt: node instanceof Ci.nsIDOMHTMLElement,' +
+ ' data: data' +
+ ' });' +
+ '});',
+ onMessage: function (data) {
+ test.assertEqual(this, item, "`this` inside onMessage should be item");
+ test.assert(data.isElt, "node should be an HTML element");
+ test.assertEqual(data.data, item.data, "data should be item data");
+ test.done();
+ }
+ });
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([item], [], []);
+ let elt = test.getItemElt(popup, item);
+ elt.click();
+ });
+};
+
+
+// A menu's click listener should work and receive bubbling clicks from
+// sub-items appropriately. This also tests menus and ensures that when a CSS
+// selector context matches the clicked node's ancestor, the matching ancestor
+// is passed to listeners as the clicked node.
+exports.testMenuClick = function (test) {
+ // Create a top-level menu, submenu, and item, like this:
+ // topMenu -> submenu -> item
+ // Click the item and make sure the click bubbles.
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let item = new loader.cm.Item({
+ label: "submenu item",
+ data: "submenu item data"
+ });
+
+ let submenu = new loader.cm.Menu({
+ label: "submenu",
+ items: [item]
+ });
+
+ let topMenu = new loader.cm.Menu({
+ label: "top menu",
+ contentScript: 'self.on("click", function (node, data) {' +
+ ' let Ci = Components.interfaces;' +
+ ' self.postMessage({' +
+ ' isAnchor: node instanceof Ci.nsIDOMHTMLAnchorElement,' +
+ ' data: data' +
+ ' });' +
+ '});',
+ onMessage: function (data) {
+ test.assertEqual(this, topMenu, "`this` inside top menu should be menu");
+ test.assert(data.isAnchor, "Clicked node should be anchor");
+ test.assertEqual(data.data, item.data,
+ "Clicked item data should be correct");
+ test.done();
+ },
+ items: [submenu],
+ context: loader.cm.SelectorContext("a")
+ });
+
+ test.withTestDoc(function (window, doc) {
+ test.showMenu(doc.getElementById("span-link"), function (popup) {
+ test.checkMenu([topMenu], [], []);
+ let topMenuElt = test.getItemElt(popup, topMenu);
+ let topMenuPopup = topMenuElt.firstChild;
+ let submenuElt = test.getItemElt(topMenuPopup, submenu);
+ let submenuPopup = submenuElt.firstChild;
+ let itemElt = test.getItemElt(submenuPopup, item);
+ itemElt.click();
+ });
+ });
+};
+
+// Click listeners should work when multiple modules are loaded.
+exports.testItemClickMultipleModules = function (test) {
+ test = new TestHelper(test);
+ let loader0 = test.newLoader();
+ let loader1 = test.newLoader();
+
+ let item0 = loader0.cm.Item({
+ label: "loader 0 item",
+ contentScript: 'self.on("click", self.postMessage);',
+ onMessage: function () {
+ test.fail("loader 0 item should not emit click event");
+ }
+ });
+ let item1 = loader1.cm.Item({
+ label: "loader 1 item",
+ contentScript: 'self.on("click", self.postMessage);',
+ onMessage: function () {
+ test.pass("loader 1 item clicked as expected");
+ test.done();
+ }
+ });
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([item0, item1], [], []);
+ let item1Elt = test.getItemElt(popup, item1);
+ item1Elt.click();
+ });
+};
+
+
+// Adding a separator to a submenu should work OK.
+exports.testSeparator = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let menu = new loader.cm.Menu({
+ label: "submenu",
+ items: [new loader.cm.Separator()]
+ });
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([menu], [], []);
+ test.done();
+ });
+};
+
+
+// Existing context menu modifications should apply to new windows.
+exports.testNewWindow = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let item = new loader.cm.Item({ label: "item" });
+
+ test.withNewWindow(function () {
+ test.showMenu(null, function (popup) {
+ test.checkMenu([item], [], []);
+ test.done();
+ });
+ });
+};
+
+
+// When a new window is opened, items added by an unloaded module should not
+// be present in the menu.
+exports.testNewWindowMultipleModules = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+ let item = new loader.cm.Item({ label: "item" });
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([item], [], []);
+ popup.hidePopup();
+ loader.unload();
+ test.withNewWindow(function () {
+ test.showMenu(null, function (popup) {
+ test.checkMenu([], [], []);
+ test.done();
+ });
+ });
+ });
+};
+
+
+// Items in the context menu should be sorted according to locale.
+exports.testSorting = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ // Make an unsorted items list. It'll look like this:
+ // item 1, item 0, item 3, item 2, item 5, item 4, ...
+ let items = [];
+ for (let i = 0; i < OVERFLOW_THRESH_DEFAULT; i += 2) {
+ items.push(new loader.cm.Item({ label: "item " + (i + 1) }));
+ items.push(new loader.cm.Item({ label: "item " + i }));
+ }
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu(items, [], []);
+ test.done();
+ });
+};
+
+
+// Items in the overflow menu should be sorted according to locale.
+exports.testSortingOverflow = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ // Make an unsorted items list. It'll look like this:
+ // item 1, item 0, item 3, item 2, item 5, item 4, ...
+ let items = [];
+ for (let i = 0; i < OVERFLOW_THRESH_DEFAULT * 2; i += 2) {
+ items.push(new loader.cm.Item({ label: "item " + (i + 1) }));
+ items.push(new loader.cm.Item({ label: "item " + i }));
+ }
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu(items, [], []);
+ test.done();
+ });
+};
+
+
+// Multiple modules shouldn't interfere with sorting.
+exports.testSortingMultipleModules = function (test) {
+ test = new TestHelper(test);
+ let loader0 = test.newLoader();
+ let loader1 = test.newLoader();
+
+ let items0 = [];
+ let items1 = [];
+ for (let i = 0; i < OVERFLOW_THRESH_DEFAULT; i++) {
+ if (i % 2) {
+ let item = new loader0.cm.Item({ label: "item " + i });
+ items0.push(item);
+ }
+ else {
+ let item = new loader1.cm.Item({ label: "item " + i });
+ items1.push(item);
+ }
+ }
+ let allItems = items0.concat(items1);
+
+ test.showMenu(null, function (popup) {
+
+ // All items should be present and sorted.
+ test.checkMenu(allItems, [], []);
+ popup.hidePopup();
+ loader0.unload();
+ loader1.unload();
+ test.showMenu(null, function (popup) {
+
+ // All items should be removed.
+ test.checkMenu([], [], allItems);
+ test.done();
+ });
+ });
+};
+
+
+// The binary search of insertionPoint should work OK.
+exports.testInsertionPoint = function (test) {
+ function mockElts(labels) {
+ return labels.map(function (label) {
+ return { label: label, getAttribute: function (l) label };
+ });
+ }
+
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+ let insertionPoint = loader.globalScope.insertionPoint;
+
+ let ip = insertionPoint("a", []);
+ test.assertStrictEqual(ip, null, "Insertion point should be null");
+
+ ip = insertionPoint("a", mockElts(["b"]));
+ test.assertEqual(ip.label, "b", "Insertion point should be 'b'");
+
+ ip = insertionPoint("c", mockElts(["b"]));
+ test.assertStrictEqual(ip, null, "Insertion point should be null");
+
+ ip = insertionPoint("b", mockElts(["a", "c"]));
+ test.assertEqual(ip.label, "c", "Insertion point should be 'c'");
+
+ ip = insertionPoint("c", mockElts(["a", "b", "d"]));
+ test.assertEqual(ip.label, "d", "Insertion point should be 'd'");
+
+ ip = insertionPoint("a", mockElts(["b", "c", "d"]));
+ test.assertEqual(ip.label, "b", "Insertion point should be 'b'");
+
+ ip = insertionPoint("d", mockElts(["a", "b", "c"]));
+ test.assertStrictEqual(ip, null, "Insertion point should be null");
+
+ test.done();
+};
+
+
+// Content click handlers and context handlers should be able to communicate,
+// i.e., they're eval'ed in the same worker and sandbox.
+exports.testContentCommunication = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let item = new loader.cm.Item({
+ label: "item",
+ contentScript: 'var potato;' +
+ 'self.on("context", function () {' +
+ ' potato = "potato";' +
+ ' return true;' +
+ '});' +
+ 'self.on("click", function () {' +
+ ' self.postMessage(potato);' +
+ '});',
+ });
+
+ item.on("message", function (data) {
+ test.assertEqual(data, "potato", "That's a lot of potatoes!");
+ test.done();
+ });
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([item], [], []);
+ let elt = test.getItemElt(popup, item);
+ elt.click();
+ });
+};
+
+
+// When the context menu is invoked on a tab that was already open when the
+// module was loaded, it should contain the expected items and content workers
+// should function as expected.
+exports.testLoadWithOpenTab = function (test) {
+ test = new TestHelper(test);
+ test.withTestDoc(function (window, doc) {
+ let loader = test.newLoader();
+ let item = new loader.cm.Item({
+ label: "item",
+ contentScript:
+ 'self.on("click", function () self.postMessage("click"));',
+ onMessage: function (msg) {
+ if (msg === "click")
+ test.done();
+ }
+ });
+ test.showMenu(null, function (popup) {
+ test.checkMenu([item], [], []);
+ test.getItemElt(popup, item).click();
+ });
+ });
+};
+
+
+// Setting an item's label before the menu is ever shown should correctly change
+// its label and, if necessary, its order within the menu.
+exports.testSetLabelBeforeShow = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let items = [
+ new loader.cm.Item({ label: "a" }),
+ new loader.cm.Item({ label: "b" })
+ ]
+ items[0].label = "z";
+ test.assertEqual(items[0].label, "z");
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([items[1], items[0]], [], []);
+ test.done();
+ });
+};
+
+
+// Setting an item's label after the menu is shown should correctly change its
+// label and, if necessary, its order within the menu.
+exports.testSetLabelAfterShow = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let items = [
+ new loader.cm.Item({ label: "a" }),
+ new loader.cm.Item({ label: "b" })
+ ];
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu(items, [], []);
+ popup.hidePopup();
+
+ items[0].label = "z";
+ test.assertEqual(items[0].label, "z");
+ test.showMenu(null, function (popup) {
+ test.checkMenu([items[1], items[0]], [], []);
+ test.done();
+ });
+ });
+};
+
+
+// Setting an item's label before the menu is ever shown should correctly change
+// its label and, if necessary, its order within the menu if the item is in the
+// overflow submenu.
+exports.testSetLabelBeforeShowOverflow = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let prefs = loader.loader.require("preferences-service");
+ prefs.set(OVERFLOW_THRESH_PREF, 0);
+
+ let items = [
+ new loader.cm.Item({ label: "a" }),
+ new loader.cm.Item({ label: "b" })
+ ]
+ items[0].label = "z";
+ test.assertEqual(items[0].label, "z");
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([items[1], items[0]], [], []);
+ prefs.set(OVERFLOW_THRESH_PREF, OVERFLOW_THRESH_DEFAULT);
+ test.done();
+ });
+};
+
+
+// Setting an item's label after the menu is shown should correctly change its
+// label and, if necessary, its order within the menu if the item is in the
+// overflow submenu.
+exports.testSetLabelAfterShowOverflow = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let prefs = loader.loader.require("preferences-service");
+ prefs.set(OVERFLOW_THRESH_PREF, 0);
+
+ let items = [
+ new loader.cm.Item({ label: "a" }),
+ new loader.cm.Item({ label: "b" })
+ ];
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu(items, [], []);
+ popup.hidePopup();
+
+ items[0].label = "z";
+ test.assertEqual(items[0].label, "z");
+ test.showMenu(null, function (popup) {
+ test.checkMenu([items[1], items[0]], [], []);
+ prefs.set(OVERFLOW_THRESH_PREF, OVERFLOW_THRESH_DEFAULT);
+ test.done();
+ });
+ });
+};
+
+
+// Setting the label of an item in a Menu should work.
+exports.testSetLabelMenuItem = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let menu = loader.cm.Menu({
+ label: "menu",
+ items: [loader.cm.Item({ label: "a" })]
+ });
+ menu.items[0].label = "z";
+
+ test.assertEqual(menu.items[0].label, "z");
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([menu], [], []);
+ test.done();
+ });
+};
+
+
+// Menu.addItem() should work.
+exports.testMenuAddItem = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let menu = loader.cm.Menu({
+ label: "menu",
+ items: [
+ loader.cm.Item({ label: "item 0" })
+ ]
+ });
+ menu.addItem(loader.cm.Item({ label: "item 1" }));
+ menu.addItem(loader.cm.Item({ label: "item 2" }));
+
+ test.assertEqual(menu.items.length, 3,
+ "menu should have correct number of items");
+ for (let i = 0; i < 3; i++) {
+ test.assertEqual(menu.items[i].label, "item " + i,
+ "item label should be correct");
+ test.assertEqual(menu.items[i].parentMenu, menu,
+ "item's parent menu should be correct");
+ }
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([menu], [], []);
+ test.done();
+ });
+};
+
+
+// Adding the same item twice to a menu should work as expected.
+exports.testMenuAddItemTwice = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let menu = loader.cm.Menu({
+ label: "menu",
+ items: []
+ });
+ let subitem = loader.cm.Item({ label: "item 1" })
+ menu.addItem(subitem);
+ menu.addItem(loader.cm.Item({ label: "item 0" }));
+ menu.addItem(subitem);
+
+ test.assertEqual(menu.items.length, 2,
+ "menu should have correct number of items");
+ for (let i = 0; i < 2; i++) {
+ test.assertEqual(menu.items[i].label, "item " + i,
+ "item label should be correct");
+ }
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([menu], [], []);
+ test.done();
+ });
+};
+
+
+// Menu.removeItem() should work.
+exports.testMenuRemoveItem = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let subitem = loader.cm.Item({ label: "item 1" });
+ let menu = loader.cm.Menu({
+ label: "menu",
+ items: [
+ loader.cm.Item({ label: "item 0" }),
+ subitem,
+ loader.cm.Item({ label: "item 2" })
+ ]
+ });
+
+ // Removing twice should be harmless.
+ menu.removeItem(subitem);
+ menu.removeItem(subitem);
+
+ test.assertEqual(subitem.parentMenu, null,
+ "item's parent menu should be correct");
+
+ test.assertEqual(menu.items.length, 2,
+ "menu should have correct number of items");
+ test.assertEqual(menu.items[0].label, "item 0",
+ "item label should be correct");
+ test.assertEqual(menu.items[1].label, "item 2",
+ "item label should be correct");
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([menu], [], []);
+ test.done();
+ });
+};
+
+
+// Adding an item currently contained in one menu to another menu should work.
+exports.testMenuItemSwap = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let subitem = loader.cm.Item({ label: "item" });
+ let menu0 = loader.cm.Menu({
+ label: "menu 0",
+ items: [subitem]
+ });
+ let menu1 = loader.cm.Menu({
+ label: "menu 1",
+ items: []
+ });
+ menu1.addItem(subitem);
+
+ test.assertEqual(menu0.items.length, 0,
+ "menu should have correct number of items");
+
+ test.assertEqual(menu1.items.length, 1,
+ "menu should have correct number of items");
+ test.assertEqual(menu1.items[0].label, "item",
+ "item label should be correct");
+
+ test.assertEqual(subitem.parentMenu, menu1,
+ "item's parent menu should be correct");
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([menu0, menu1], [], []);
+ test.done();
+ });
+};
+
+
+// Destroying an item should remove it from its parent menu.
+exports.testMenuItemDestroy = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let subitem = loader.cm.Item({ label: "item" });
+ let menu = loader.cm.Menu({
+ label: "menu",
+ items: [subitem]
+ });
+ subitem.destroy();
+
+ test.assertEqual(menu.items.length, 0,
+ "menu should have correct number of items");
+ test.assertEqual(subitem.parentMenu, null,
+ "item's parent menu should be correct");
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([menu], [], []);
+ test.done();
+ });
+};
+
+
+// Setting Menu.items should work.
+exports.testMenuItemsSetter = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let menu = loader.cm.Menu({
+ label: "menu",
+ items: [
+ loader.cm.Item({ label: "old item 0" }),
+ loader.cm.Item({ label: "old item 1" })
+ ]
+ });
+ menu.items = [
+ loader.cm.Item({ label: "new item 0" }),
+ loader.cm.Item({ label: "new item 1" }),
+ loader.cm.Item({ label: "new item 2" })
+ ];
+
+ test.assertEqual(menu.items.length, 3,
+ "menu should have correct number of items");
+ for (let i = 0; i < 3; i++) {
+ test.assertEqual(menu.items[i].label, "new item " + i,
+ "item label should be correct");
+ test.assertEqual(menu.items[i].parentMenu, menu,
+ "item's parent menu should be correct");
+ }
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([menu], [], []);
+ test.done();
+ });
+};
+
+
+// Setting Item.data should work.
+exports.testItemDataSetter = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let item = loader.cm.Item({ label: "old item 0", data: "old" });
+ item.data = "new";
+
+ test.assertEqual(item.data, "new", "item should have correct data");
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([item], [], []);
+ test.done();
+ });
+};
+
+
+// Open the test doc, load the module, make sure items appear when context-
+// clicking the iframe.
+exports.testAlreadyOpenIframe = function (test) {
+ test = new TestHelper(test);
+ test.withTestDoc(function (window, doc) {
+ let loader = test.newLoader();
+ let item = new loader.cm.Item({
+ label: "item"
+ });
+ test.showMenu(doc.getElementById("iframe"), function (popup) {
+ test.checkMenu([item], [], []);
+ test.done();
+ });
+ });
+};
+
+
+// Test image support.
+exports.testItemImage = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let imageURL = require("self").data.url("moz_favicon.ico");
+ let item = new loader.cm.Item({ label: "item", image: imageURL });
+ let menu = new loader.cm.Menu({ label: "menu", image: imageURL, items: [] });
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([item, menu], [], []);
+
+ let imageURL2 = require("self").data.url("dummy.ico");
+ item.image = imageURL2;
+ menu.image = imageURL2;
+ test.checkMenu([item, menu], [], []);
+
+ item.image = null;
+ menu.image = null;
+ test.checkMenu([item, menu], [], []);
+
+ test.done();
+ });
+};
+
+
+// Menu.destroy should destroy the item tree rooted at that menu.
+exports.testMenuDestroy = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ let menu = loader.cm.Menu({
+ label: "menu",
+ items: [
+ loader.cm.Item({ label: "item 0" }),
+ loader.cm.Menu({
+ label: "item 1",
+ items: [
+ loader.cm.Item({ label: "subitem 0" }),
+ loader.cm.Item({ label: "subitem 1" }),
+ loader.cm.Item({ label: "subitem 2" })
+ ]
+ }),
+ loader.cm.Item({ label: "item 2" })
+ ]
+ });
+ menu.destroy();
+
+ let numRegistryEntries = 0;
+ loader.globalScope.browserManager.browserWins.forEach(function (bwin) {
+ for (let itemID in bwin.items)
+ numRegistryEntries++;
+ });
+ test.assertEqual(numRegistryEntries, 0, "All items should be unregistered.");
+
+ test.showMenu(null, function (popup) {
+ test.checkMenu([], [], [menu]);
+ test.done();
+ });
+};
+
+
+// NO TESTS BELOW THIS LINE! ///////////////////////////////////////////////////
+
+// Run only a dummy test if context-menu doesn't support the host app.
+if (!require("xul-app").is("Firefox")) {
+ for (let [prop, val] in Iterator(exports))
+ if (/^test/.test(prop) && typeof(val) === "function")
+ delete exports[prop];
+ exports.testAppNotSupported = function (test) {
+ test.pass("context-menu does not support this application.");
+ };
+}
+
+
+// This makes it easier to run tests by handling things like opening the menu,
+// opening new windows, making assertions, etc. Methods on |test| can be called
+// on instances of this class. Don't forget to call done() to end the test!
+// WARNING: This looks up items in popups by comparing labels, so don't give two
+// items the same label.
+function TestHelper(test) {
+ // default waitUntilDone timeout is 10s, which is too short on the win7
+ // buildslave
+ test.waitUntilDone(30*1000);
+ this.test = test;
+ this.loaders = [];
+ this.browserWindow = Cc["@mozilla.org/appshell/window-mediator;1"].
+ getService(Ci.nsIWindowMediator).
+ getMostRecentWindow("navigator:browser");
+}
+
+TestHelper.prototype = {
+ get contextMenuPopup() {
+ return this.browserWindow.document.getElementById("contentAreaContextMenu");
+ },
+
+ get contextMenuSeparator() {
+ return this.browserWindow.document.getElementById(SEPARATOR_ID);
+ },
+
+ get overflowPopup() {
+ return this.browserWindow.document.getElementById(OVERFLOW_POPUP_ID);
+ },
+
+ get overflowSubmenu() {
+ return this.browserWindow.document.getElementById(OVERFLOW_MENU_ID);
+ },
+
+ get tabBrowser() {
+ return this.browserWindow.gBrowser;
+ },
+
+ // Methods on the wrapped test can be called on this object.
+ __noSuchMethod__: function (methodName, args) {
+ this.test[methodName].apply(this.test, args);
+ },
+
+ // Asserts that absentItems -- an array of items that should not match the
+ // current context -- aren't present in the menu.
+ checkAbsentItems: function (presentItems, absentItems) {
+ for (let i = 0; i < absentItems.length; i++) {
+ let item = absentItems[i];
+ let elt = this.getItemElt(this.contextMenuPopup, item);
+
+ // The implementation actually hides items rather than removing or not
+ // adding them in the first place, but that's an implementation detail.
+ this.test.assert(!elt || elt.hidden,
+ "Item should not be present in top-level menu");
+
+ if (this.shouldOverflow(presentItems)) {
+ elt = getItemElt(this.overflowPopup, item);
+ this.test.assert(!elt || elt.hidden,
+ "Item should not be present in overflow submenu");
+ }
+ }
+ },
+
+ // Asserts that elt, a DOM element representing item, looks OK.
+ checkItemElt: function (elt, item) {
+ let itemType = this.getItemType(item);
+
+ switch (itemType) {
+ case "Item":
+ this.test.assertEqual(elt.localName, "menuitem",
+ "Item DOM element should be a xul:menuitem");
+ if (typeof(item.data) === "string") {
+ this.test.assertEqual(elt.getAttribute("value"), item.data,
+ "Item should have correct data");
+ }
+ break
+ case "Menu":
+ this.test.assertEqual(elt.localName, "menu",
+ "Menu DOM element should be a xul:menu");
+ let subPopup = elt.firstChild;
+ this.test.assert(subPopup, "xul:menu should have a child");
+ this.test.assertEqual(subPopup.localName, "menupopup",
+ "xul:menu's first child should be a menupopup");
+ break;
+ case "Separator":
+ this.test.assertEqual(elt.localName, "menuseparator",
+ "Separator DOM element should be a xul:menuseparator");
+ break;
+ }
+
+ if (itemType === "Item" || itemType === "Menu") {
+ this.test.assertEqual(elt.getAttribute("label"), item.label,
+ "Item should have correct title");
+ if (typeof(item.image) === "string")
+ this.test.assertEqual(elt.getAttribute("image"), item.image,
+ "Item should have correct image");
+ else
+ this.test.assert(!elt.hasAttribute("image"),
+ "Item should not have image");
+ }
+ },
+
+ // Asserts that the context menu looks OK given the arguments. presentItems
+ // are items that should match the current context. absentItems are items
+ // that shouldn't. removedItems are items that have been removed from the
+ // menu.
+ checkMenu: function (presentItems, absentItems, removedItems) {
+ this.checkSeparator(presentItems);
+ this.checkOverflow(presentItems);
+ this.checkPresentItems(presentItems);
+ this.checkAbsentItems(presentItems, absentItems);
+ this.checkRemovedItems(removedItems);
+ this.checkSort(presentItems);
+ },
+
+ // Asserts that the overflow submenu is present or absent as appropriate for
+ // presentItems.
+ checkOverflow: function (presentItems) {
+ let submenu = this.overflowSubmenu;
+ if (this.shouldOverflow(presentItems)) {
+ this.test.assert(submenu && !submenu.hidden,
+ "Overflow submenu should be present");
+ this.test.assert(submenu.localName, "menu",
+ "Overflow submenu should be a <menu>");
+ let overflowPopup = this.overflowPopup;
+ this.test.assert(overflowPopup,
+ "Overflow submenu popup should be present");
+ this.test.assert(overflowPopup.localName, "menupopup",
+ "Overflow submenu popup should be a <menupopup>");
+ }
+ else {
+ this.test.assert(!submenu || submenu.hidden,
+ "Overflow submenu should be absent");
+ }
+ },
+
+ // Asserts that the items that are present in the menu because they match the
+ // current context look OK.
+ checkPresentItems: function (presentItems) {
+ function recurse(popup, items, isTopLevel) {
+ items.forEach(function (item) {
+ let elt = this.getItemElt(popup, item);
+
+ if (isTopLevel) {
+ if (this.shouldOverflow(items)) {
+ this.test.assert(!elt || elt.hidden,
+ "Item should not be present in top-level menu");
+
+ let overflowPopup = this.overflowPopup;
+ this.test.assert(overflowPopup,
+ "Overflow submenu should be present");
+
+ elt = this.getItemElt(overflowPopup, item);
+ this.test.assert(elt && !elt.hidden,
+ "Item should be present in overflow submenu");
+ }
+ else {
+ this.test.assert(elt && !elt.hidden,
+ "Item should be present in top-level menu");
+ }
+ }
+ else {
+ this.test.assert(elt && !elt.hidden,
+ "Item should be present in menu");
+ }
+
+ this.checkItemElt(elt, item);
+ if (this.getItemType(item) === "Menu")
+ recurse.call(this, elt.firstChild, item.items, false);
+ }, this);
+ }
+
+ recurse.call(this, this.contextMenuPopup, presentItems, true);
+ },
+
+ // Asserts that items that have been removed from the menu are really removed.
+ checkRemovedItems: function (removedItems) {
+ for (let i = 0; i < removedItems.length; i++) {
+ let item = removedItems[i];
+
+ let elt = this.getItemElt(this.contextMenuPopup, item);
+ this.test.assert(!elt, "Item should be removed from top-level menu");
+
+ let overflowPopup = this.overflowPopup;
+ if (overflowPopup) {
+ elt = this.getItemElt(overflowPopup, item);
+ this.test.assert(!elt, "Item should be removed from overflow submenu");
+ }
+ }
+ },
+
+ // Asserts that the menu separator separating standard items from our items
+ // looks OK.
+ checkSeparator: function (presentItems) {
+ let sep = this.contextMenuSeparator;
+ if (presentItems.length) {
+ this.test.assert(sep && !sep.hidden, "Menu separator should be present");
+ this.test.assertEqual(sep.localName, "menuseparator",
+ "Menu separator should be a <menuseparator>");
+ }
+ else {
+ this.test.assert(!sep || sep.hidden, "Menu separator should be absent");
+ }
+ },
+
+ // Asserts that our items are sorted.
+ checkSort: function (presentItems) {
+ // Get the first item in sorted order, get its elt, walk the nextSibling
+ // chain, making sure each is greater than the previous.
+ if (presentItems.length) {
+ let sorted = presentItems.slice(0).
+ sort(function (a, b) a.label.localeCompare(b.label));
+ let elt = this.shouldOverflow(presentItems) ?
+ this.getItemElt(this.overflowPopup, sorted[0]) :
+ this.getItemElt(this.contextMenuPopup, sorted[0]);
+ let numElts = 1;
+ while (elt.nextSibling &&
+ elt.nextSibling.className.split(/\s+/).indexOf(ITEM_CLASS) >= 0) {
+ let eltLabel = elt.getAttribute("label");
+ let nextLabel = elt.nextSibling.getAttribute("label");
+ this.test.assert(eltLabel.localeCompare(nextLabel) < 0,
+ "Item label should be < next item's label");
+ elt = elt.nextSibling;
+ numElts++;
+ }
+ this.test.assertEqual(numElts, presentItems.length,
+ "The first item in sorted order should have the " +
+ "first element in sorted order");
+ }
+ },
+
+ // Attaches an event listener to node. The listener is automatically removed
+ // when it's fired (so it's assumed it will fire), and callback is called
+ // after a short delay. Since the module we're testing relies on the same
+ // event listeners to do its work, this is to give them a little breathing
+ // room before callback runs. Inside callback |this| is this object.
+ delayedEventListener: function (node, event, callback, useCapture) {
+ const self = this;
+ node.addEventListener(event, function handler(evt) {
+ node.removeEventListener(event, handler, useCapture);
+ require("timer").setTimeout(function () {
+ try {
+ callback.call(self, evt);
+ }
+ catch (err) {
+ self.test.exception(err);
+ self.test.done();
+ }
+ }, 20);
+ }, useCapture);
+ },
+
+ // Call to finish the test.
+ done: function () {
+ function commonDone() {
+ if (this.tab) {
+ this.tabBrowser.removeTab(this.tab);
+ this.tabBrowser.selectedTab = this.oldSelectedTab;
+ }
+ while (this.loaders.length) {
+ let browserManager = this.loaders[0].globalScope.browserManager;
+ let topLevelItems = browserManager.topLevelItems.slice();
+ let privatePropsKey = this.loaders[0].globalScope.PRIVATE_PROPS_KEY;
+ let workerRegs = topLevelItems.map(function (item) {
+ return item.valueOf(privatePropsKey)._workerReg;
+ });
+
+ this.loaders[0].unload();
+
+ // Make sure the browser manager is cleaned up.
+ this.test.assertEqual(browserManager.browserWins.length, 0,
+ "browserManager should have no windows left");
+ this.test.assertEqual(browserManager.topLevelItems.length, 0,
+ "browserManager should have no items left");
+ this.test.assert(!("contentWins" in browserManager),
+ "browserManager should have no content windows left");
+
+ // Make sure the items' worker registries are cleaned up.
+ topLevelItems.forEach(function (item) {
+ this.test.assert(!("_workerReg" in item.valueOf(privatePropsKey)),
+ "item's worker registry should be removed");
+ }, this);
+ workerRegs.forEach(function (workerReg) {
+ this.test.assertEqual(Object.keys(workerReg.winWorkers).length, 0,
+ "worker registry should be empty");
+ this.test.assertEqual(
+ Object.keys(workerReg.winsWithoutWorkers).length, 0,
+ "worker registry list of windows without workers should be empty");
+ }, this);
+ }
+ this.test.done();
+ }
+
+ function closeBrowserWindow() {
+ if (this.oldBrowserWindow) {
+ this.delayedEventListener(this.browserWindow, "unload", commonDone,
+ false);
+ this.browserWindow.close();
+ this.browserWindow = this.oldBrowserWindow;
+ delete this.oldBrowserWindow;
+ }
+ else {
+ commonDone.call(this);
+ }
+ };
+
+ if (this.contextMenuPopup.state == "closed") {
+ closeBrowserWindow.call(this);
+ }
+ else {
+ this.delayedEventListener(this.contextMenuPopup, "popuphidden",
+ function () closeBrowserWindow.call(this),
+ false);
+ this.contextMenuPopup.hidePopup();
+ }
+ },
+
+ // Returns the DOM element in popup corresponding to item.
+ // WARNING: The element is found by comparing labels, so don't give two items
+ // the same label.
+ getItemElt: function (popup, item) {
+ let nodes = popup.childNodes;
+ for (let i = nodes.length - 1; i >= 0; i--) {
+ if (this.getItemType(item) === "Separator") {
+ if (nodes[i].localName === "menuseparator")
+ return nodes[i];
+ }
+ else if (nodes[i].getAttribute("label") === item.label)
+ return nodes[i];
+ }
+ return null;
+ },
+
+ // Returns "Item", "Menu", or "Separator".
+ getItemType: function (item) {
+ // Could use instanceof here, but that would require accessing the loader
+ // that created the item, and I don't want to A) somehow search through the
+ // this.loaders list to find it, and B) assume there are any live loaders at
+ // all.
+ return /^\[object (Item|Menu|Separator)/.exec(item.toString())[1];
+ },
+
+ // Returns a wrapper around a new loader: { loader, cm, unload, globalScope }.
+ // loader is a Cuddlefish sandboxed loader, cm is the context menu module,
+ // globalScope is the context menu module's global scope, and unload is a
+ // function that unloads the loader and associated resources.
+ newLoader: function () {
+ const self = this;
+ let loader = Loader(module);
+ let wrapper = {
+ loader: loader,
+ cm: loader.require("context-menu"),
+ globalScope: loader.sandbox("context-menu"),
+ unload: function () {
+ loader.unload();
+ let idx = self.loaders.indexOf(wrapper);
+ if (idx < 0)
+ throw new Error("Test error: tried to unload nonexistent loader");
+ self.loaders.splice(idx, 1);
+ }
+ };
+ this.loaders.push(wrapper);
+ return wrapper;
+ },
+
+ // Returns true if the number of presentItems crosses the overflow threshold.
+ shouldOverflow: function (presentItems) {
+ return presentItems.length >
+ (this.loaders.length ?
+ this.loaders[0].loader.require("preferences-service").
+ get(OVERFLOW_THRESH_PREF, OVERFLOW_THRESH_DEFAULT) :
+ OVERFLOW_THRESH_DEFAULT);
+ },
+
+ // Opens the context menu on the current page. If targetNode is null, the
+ // menu is opened in the top-left corner. onShowncallback is passed the
+ // popup.
+ showMenu: function(targetNode, onshownCallback) {
+ function sendEvent() {
+ this.delayedEventListener(this.browserWindow, "popupshowing",
+ function (e) {
+ let popup = e.target;
+ onshownCallback.call(this, popup);
+ }, false);
+
+ let rect = targetNode ?
+ targetNode.getBoundingClientRect() :
+ { left: 0, top: 0, width: 0, height: 0 };
+ let contentWin = this.browserWindow.content;
+ contentWin.
+ QueryInterface(Ci.nsIInterfaceRequestor).
+ getInterface(Ci.nsIDOMWindowUtils).
+ sendMouseEvent("contextmenu",
+ rect.left + (rect.width / 2),
+ rect.top + (rect.height / 2),
+ 2, 1, 0);
+ }
+
+ // If a new tab or window has not yet been opened, open a new tab now. For
+ // some reason using the tab already opened when the test starts causes
+ // leaks. See bug 566351 for details.
+ if (!targetNode && !this.oldSelectedTab && !this.oldBrowserWindow) {
+ this.oldSelectedTab = this.tabBrowser.selectedTab;
+ this.tab = this.tabBrowser.addTab("about:blank");
+ let browser = this.tabBrowser.getBrowserForTab(this.tab);
+
+ this.delayedEventListener(browser, "load", function () {
+ this.tabBrowser.selectedTab = this.tab;
+ sendEvent.call(this);
+ }, true);
+ }
+ else
+ sendEvent.call(this);
+ },
+
+ // Opens a new browser window. The window will be closed automatically when
+ // done() is called.
+ withNewWindow: function (onloadCallback) {
+ let win = this.browserWindow.OpenBrowserWindow();
+ this.delayedEventListener(win, "load", onloadCallback, true);
+ this.oldBrowserWindow = this.browserWindow;
+ this.browserWindow = win;
+ },
+
+ // Opens a new tab with our test page in the current window. The tab will
+ // be closed automatically when done() is called.
+ withTestDoc: function (onloadCallback) {
+ this.oldSelectedTab = this.tabBrowser.selectedTab;
+ this.tab = this.tabBrowser.addTab(TEST_DOC_URL);
+ let browser = this.tabBrowser.getBrowserForTab(this.tab);
+
+ this.delayedEventListener(browser, "load", function () {
+ this.tabBrowser.selectedTab = this.tab;
+ onloadCallback.call(this, browser.contentWindow, browser.contentDocument);
+ }, true);
+ }
+};
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-hotkeys.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-hotkeys.js
new file mode 100644
index 0000000..0e0ecd6
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-hotkeys.js
@@ -0,0 +1,160 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Hotkey } = require("hotkeys");
+const { keyDown } = require("dom/events/keys");
+const { Loader } = require('./helpers');
+
+exports["test hotkey: function key"] = function(assert, done) {
+ var element = require("window-utils").activeBrowserWindow.document.documentElement;
+ var showHotKey = Hotkey({
+ combo: "f1",
+ onPress: function() {
+ assert.pass("first callback is called");
+ keyDown(element, "f2");
+ showHotKey.destroy();
+ }
+ });
+
+ var hideHotKey = Hotkey({
+ combo: "f2",
+ onPress: function() {
+ assert.pass("second callback is called");
+ hideHotKey.destroy();
+ done();
+ }
+ });
+
+ keyDown(element, "f1");
+};
+
+exports["test hotkey: accel alt shift"] = function(assert, done) {
+ var element = require("window-utils").activeBrowserWindow.document.documentElement;
+ var showHotKey = Hotkey({
+ combo: "accel-shift-6",
+ onPress: function() {
+ assert.pass("first callback is called");
+ keyDown(element, "accel-alt-shift-6");
+ showHotKey.destroy();
+ }
+ });
+
+ var hideHotKey = Hotkey({
+ combo: "accel-alt-shift-6",
+ onPress: function() {
+ assert.pass("second callback is called");
+ hideHotKey.destroy();
+ done();
+ }
+ });
+
+ keyDown(element, "accel-shift-6");
+};
+
+exports["test hotkey meta & control"] = function(assert, done) {
+ var element = require("window-utils").activeBrowserWindow.document.documentElement;
+ var showHotKey = Hotkey({
+ combo: "meta-3",
+ onPress: function() {
+ assert.pass("first callback is called");
+ keyDown(element, "alt-control-shift-b");
+ showHotKey.destroy();
+ }
+ });
+
+ var hideHotKey = Hotkey({
+ combo: "Ctrl-Alt-Shift-B",
+ onPress: function() {
+ assert.pass("second callback is called");
+ hideHotKey.destroy();
+ done();
+ }
+ });
+
+ keyDown(element, "meta-3");
+};
+
+exports["test hotkey: control-1 / meta--"] = function(assert, done) {
+ var element = require("window-utils").activeBrowserWindow.document.documentElement;
+ var showHotKey = Hotkey({
+ combo: "control-1",
+ onPress: function() {
+ assert.pass("first callback is called");
+ keyDown(element, "meta--");
+ showHotKey.destroy();
+ }
+ });
+
+ var hideHotKey = Hotkey({
+ combo: "meta--",
+ onPress: function() {
+ assert.pass("second callback is called");
+ hideHotKey.destroy();
+ done();
+ }
+ });
+
+ keyDown(element, "control-1");
+};
+
+exports["test invalid combos"] = function(assert) {
+ assert.throws(function() {
+ Hotkey({
+ combo: "d",
+ onPress: function() {}
+ });
+ }, "throws if no modifier is present");
+ assert.throws(function() {
+ Hotkey({
+ combo: "alt",
+ onPress: function() {}
+ });
+ }, "throws if no key is present");
+ assert.throws(function() {
+ Hotkey({
+ combo: "alt p b",
+ onPress: function() {}
+ });
+ }, "throws if more then one key is present");
+};
+
+exports["test no exception on unmodified keypress"] = function(assert) {
+ var element = require("window-utils").activeBrowserWindow.document.documentElement;
+ var someHotkey = Hotkey({
+ combo: "control-alt-1",
+ onPress: function() {
+ }
+ });
+ keyDown(element, "a");
+ assert.pass("No exception throw, unmodified keypress passed");
+};
+
+exports["test hotkey: automatic destroy"] = function(assert, done) {
+ // Hacky way to be able to create unloadable modules via makeSandboxedLoader.
+ let loader = Loader(module);
+
+ var called = false;
+ var element = loader.require("window-utils").activeBrowserWindow.document.documentElement;
+ var hotkey = loader.require("hotkeys").Hotkey({
+ combo: "accel-shift-x",
+ onPress: function() {
+ called = true;
+ }
+ });
+
+ // Unload the module so that previous hotkey is automatically destroyed
+ loader.unload();
+
+ // Ensure that the hotkey is really destroyed
+ keyDown(element, "accel-shift-x");
+
+ require("timer").setTimeout(function () {
+ assert.ok(!called, "Hotkey is destroyed and not called.");
+ done();
+ }, 0);
+};
+
+require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-l10n.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-l10n.js
new file mode 100644
index 0000000..259b160
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-l10n.js
@@ -0,0 +1,97 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const prefs = require("preferences-service");
+const { Loader } = require('./helpers');
+
+const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS";
+const PREF_SELECTED_LOCALE = "general.useragent.locale";
+
+function setLocale(locale) {
+ prefs.set(PREF_MATCH_OS_LOCALE, false);
+ prefs.set(PREF_SELECTED_LOCALE, locale);
+}
+
+function resetLocale() {
+ prefs.reset(PREF_MATCH_OS_LOCALE);
+ prefs.reset(PREF_SELECTED_LOCALE);
+}
+
+exports.testExactMatching = function(test) {
+ let loader = Loader(module);
+ setLocale("fr-FR");
+
+ let _ = loader.require("l10n").get;
+ test.assertEqual(_("Not translated"), "Not translated",
+ "Key not translated");
+ test.assertEqual(_("Translated"), "Oui",
+ "Simple key translated");
+
+ // Placeholders
+ test.assertEqual(_("placeholderString", "works"), "Placeholder works",
+ "Value with placeholder");
+ test.assertEqual(_("Placeholder %s", "works"), "Placeholder works",
+ "Key without value but with placeholder");
+ test.assertEqual(_("Placeholders %2s %1s %s.", "working", "are", "correctly"),
+ "Placeholders are working correctly.",
+ "Multiple placeholders");
+
+ // Plurals
+ test.assertEqual(_("downloadsCount", 0),
+ "0 téléchargement",
+ "PluralForm form 'one' for 0 in french");
+ test.assertEqual(_("downloadsCount", 1),
+ "1 téléchargement",
+ "PluralForm form 'one' for 1 in french");
+ test.assertEqual(_("downloadsCount", 2),
+ "2 téléchargements",
+ "PluralForm form 'other' for n > 1 in french");
+
+ loader.unload();
+ resetLocale();
+}
+
+exports.testEnUsLocaleName = function(test) {
+ let loader = Loader(module);
+ setLocale("en-US");
+
+ let _ = loader.require("l10n").get;
+ test.assertEqual(_("Not translated"), "Not translated");
+ test.assertEqual(_("Translated"), "Yes");
+
+ // Check plural forms regular matching
+ test.assertEqual(_("downloadsCount", 0),
+ "0 downloads",
+ "PluralForm form 'other' for 0 in english");
+ test.assertEqual(_("downloadsCount", 1),
+ "one download",
+ "PluralForm form 'one' for 1 in english");
+ test.assertEqual(_("downloadsCount", 2),
+ "2 downloads",
+ "PluralForm form 'other' for n != 1 in english");
+
+ // Check optional plural forms
+ test.assertEqual(_("pluralTest", 0),
+ "optional zero form",
+ "PluralForm form 'zero' can be optionaly specified. (Isn't mandatory in english)");
+ test.assertEqual(_("pluralTest", 1),
+ "fallback to other",
+ "If the specific plural form is missing, we fallback to 'other'");
+
+ loader.unload();
+ resetLocale();
+}
+
+exports.testShortLocaleName = function(test) {
+ let loader = Loader(module);
+ setLocale("eo");
+
+ let _ = loader.require("l10n").get;
+ test.assertEqual(_("Not translated"), "Not translated");
+ test.assertEqual(_("Translated"), "jes");
+
+ loader.unload();
+ resetLocale();
+}
+
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-module.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-module.js
new file mode 100644
index 0000000..957d075
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-module.js
@@ -0,0 +1,37 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+/** Disabled because of Bug 672199
+exports["test module exports are frozen"] = function(assert) {
+ assert.ok(Object.isFrozen(require("addon-kit/hotkeys")),
+ "module exports are frozen");
+};
+
+exports["test redefine exported property"] = function(assert) {
+ let hotkeys = require("addon-kit/hotkeys");
+ let { Hotkey } = hotkeys;
+ try { Object.defineProperty(hotkeys, 'Hotkey', { value: {} }); } catch(e) {}
+ assert.equal(hotkeys.Hotkey, Hotkey, "exports can't be redefined");
+};
+*/
+
+exports["test can't delete exported property"] = function(assert) {
+ let hotkeys = require("addon-kit/hotkeys");
+ let { Hotkey } = hotkeys;
+
+ try { delete hotkeys.Hotkey; } catch(e) {}
+ assert.equal(hotkeys.Hotkey, Hotkey, "exports can't be deleted");
+};
+
+exports["test can't override exported property"] = function(assert) {
+ let hotkeys = require("addon-kit/hotkeys");
+ let { Hotkey } = hotkeys;
+
+ try { hotkeys.Hotkey = Object } catch(e) {}
+ assert.equal(hotkeys.Hotkey, Hotkey, "exports can't be overriden");
+};
+
+require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-notifications.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-notifications.js
new file mode 100644
index 0000000..b0e1f37
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-notifications.js
@@ -0,0 +1,46 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim:set ts=2 sw=2 sts=2 et filetype=javascript
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const { Loader } = require('./helpers');
+
+exports.testOnClick = function (test) {
+ let [loader, mockAlertServ] = makeLoader(module);
+ let notifs = loader.require("notifications");
+ let data = "test data";
+ let opts = {
+ onClick: function (clickedData) {
+ test.assertEqual(this, notifs, "|this| should be notifications module");
+ test.assertEqual(clickedData, data,
+ "data passed to onClick should be correct");
+ },
+ data: data,
+ title: "test title",
+ text: "test text",
+ iconURL: "test icon URL"
+ };
+ notifs.notify(opts);
+ mockAlertServ.click();
+ loader.unload();
+};
+
+// Returns [loader, mockAlertService].
+function makeLoader(test) {
+ let loader = Loader(module);
+ let mockAlertServ = {
+ showAlertNotification: function (imageUrl, title, text, textClickable,
+ cookie, alertListener, name) {
+ this._cookie = cookie;
+ this._alertListener = alertListener;
+ },
+ click: function () {
+ this._alertListener.observe(null, "alertclickcallback", this._cookie);
+ }
+ };
+ loader.require("notifications");
+ let scope = loader.sandbox("notifications");
+ scope.notify = mockAlertServ.showAlertNotification.bind(mockAlertServ);
+ return [loader, mockAlertServ];
+};
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-page-mod.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-page-mod.js
new file mode 100644
index 0000000..14a3ef9
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-page-mod.js
@@ -0,0 +1,526 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+var pageMod = require("page-mod");
+var testPageMod = require("pagemod-test-helpers").testPageMod;
+const { Loader } = require('./helpers');
+const tabs = require("tabs");
+
+/* XXX This can be used to delay closing the test Firefox instance for interactive
+ * testing or visual inspection. This test is registered first so that it runs
+ * the last. */
+exports.delay = function(test) {
+ if (false) {
+ test.waitUntilDone(60000);
+ require("timer").setTimeout(function() {test.done();}, 4000);
+ } else
+ test.pass();
+}
+
+/* Tests for the PageMod APIs */
+
+exports.testPageMod1 = function(test) {
+ let mods = testPageMod(test, "about:", [{
+ include: /about:/,
+ contentScriptWhen: 'end',
+ contentScript: 'new ' + function WorkerScope() {
+ window.document.body.setAttribute("JEP-107", "worked");
+ },
+ onAttach: function() {
+ test.assertEqual(this, mods[0], "The 'this' object is the page mod.");
+ }
+ }],
+ function(win, done) {
+ test.assertEqual(
+ win.document.body.getAttribute("JEP-107"),
+ "worked",
+ "PageMod.onReady test"
+ );
+ done();
+ }
+ );
+};
+
+exports.testPageMod2 = function(test) {
+ testPageMod(test, "about:", [{
+ include: "about:*",
+ contentScript: [
+ 'new ' + function contentScript() {
+ window.AUQLUE = function() { return 42; }
+ try {
+ window.AUQLUE()
+ }
+ catch(e) {
+ throw new Error("PageMod scripts executed in order");
+ }
+ document.documentElement.setAttribute("first", "true");
+ },
+ 'new ' + function contentScript() {
+ document.documentElement.setAttribute("second", "true");
+ }
+ ]
+ }], function(win, done) {
+ test.assertEqual(win.document.documentElement.getAttribute("first"),
+ "true",
+ "PageMod test #2: first script has run");
+ test.assertEqual(win.document.documentElement.getAttribute("second"),
+ "true",
+ "PageMod test #2: second script has run");
+ test.assertEqual("AUQLUE" in win, false,
+ "PageMod test #2: scripts get a wrapped window");
+ done();
+ });
+};
+
+exports.testPageModIncludes = function(test) {
+ var asserts = [];
+ function createPageModTest(include, expectedMatch) {
+ // Create an 'onload' test function...
+ asserts.push(function(test, win) {
+ var matches = include in win.localStorage;
+ test.assert(expectedMatch ? matches : !matches,
+ "'" + include + "' match test, expected: " + expectedMatch);
+ });
+ // ...and corresponding PageMod options
+ return {
+ include: include,
+ contentScript: 'new ' + function() {
+ self.on("message", function(msg) {
+ window.localStorage[msg] = true;
+ });
+ },
+ // The testPageMod callback with test assertions is called on 'end',
+ // and we want this page mod to be attached before it gets called,
+ // so we attach it on 'start'.
+ contentScriptWhen: 'start',
+ onAttach: function(worker) {
+ worker.postMessage(this.include[0]);
+ }
+ };
+ }
+
+ testPageMod(test, "about:buildconfig", [
+ createPageModTest("*", false),
+ createPageModTest("*.google.com", false),
+ createPageModTest("about:*", true),
+ createPageModTest("about:", false),
+ createPageModTest("about:buildconfig", true)
+ ],
+ function (win, done) {
+ test.waitUntil(function () win.localStorage["about:buildconfig"],
+ "about:buildconfig page-mod to be executed")
+ .then(function () {
+ asserts.forEach(function(fn) {
+ fn(test, win);
+ });
+ done();
+ });
+ }
+ );
+};
+
+exports.testPageModErrorHandling = function(test) {
+ test.assertRaises(function() {
+ new pageMod.PageMod();
+ },
+ 'pattern is undefined',
+ "PageMod() throws when 'include' option is not specified.");
+};
+
+/* Tests for internal functions. */
+exports.testCommunication1 = function(test) {
+ let workerDone = false,
+ callbackDone = null;
+
+ testPageMod(test, "about:", [{
+ include: "about:*",
+ contentScriptWhen: 'end',
+ contentScript: 'new ' + function WorkerScope() {
+ self.on('message', function(msg) {
+ document.body.setAttribute('JEP-107', 'worked');
+ self.postMessage(document.body.getAttribute('JEP-107'));
+ })
+ },
+ onAttach: function(worker) {
+ worker.on('error', function(e) {
+ test.fail('Errors where reported');
+ });
+ worker.on('message', function(value) {
+ test.assertEqual(
+ "worked",
+ value,
+ "test comunication"
+ );
+ workerDone = true;
+ if (callbackDone)
+ callbackDone();
+ });
+ worker.postMessage('do it!')
+ }
+ }],
+ function(win, done) {
+ (callbackDone = function() {
+ if (workerDone) {
+ test.assertEqual(
+ 'worked',
+ win.document.body.getAttribute('JEP-107'),
+ 'attribute should be modified'
+ );
+ done();
+ }
+ })();
+ }
+ );
+};
+
+exports.testCommunication2 = function(test) {
+ let callbackDone = null,
+ window;
+
+ testPageMod(test, "about:credits", [{
+ include: "about:*",
+ contentScriptWhen: 'start',
+ contentScript: 'new ' + function WorkerScope() {
+ document.documentElement.setAttribute('AUQLUE', 42);
+ window.addEventListener('load', function listener() {
+ self.postMessage('onload');
+ }, false);
+ self.on("message", function() {
+ self.postMessage(document.documentElement.getAttribute("test"))
+ });
+ },
+ onAttach: function(worker) {
+ worker.on('error', function(e) {
+ test.fail('Errors where reported');
+ });
+ worker.on('message', function(msg) {
+ if ('onload' == msg) {
+ test.assertEqual(
+ '42',
+ window.document.documentElement.getAttribute('AUQLUE'),
+ 'PageMod scripts executed in order'
+ );
+ window.document.documentElement.setAttribute('test', 'changes in window');
+ worker.postMessage('get window.test')
+ } else {
+ test.assertEqual(
+ 'changes in window',
+ msg,
+ 'PageMod test #2: second script has run'
+ )
+ callbackDone();
+ }
+ });
+ }
+ }],
+ function(win, done) {
+ window = win;
+ callbackDone = done;
+ }
+ );
+};
+
+exports.testEventEmitter = function(test) {
+ let workerDone = false,
+ callbackDone = null;
+
+ testPageMod(test, "about:", [{
+ include: "about:*",
+ contentScript: 'new ' + function WorkerScope() {
+ self.port.on('addon-to-content', function(data) {
+ self.port.emit('content-to-addon', data);
+ });
+ },
+ onAttach: function(worker) {
+ worker.on('error', function(e) {
+ test.fail('Errors were reported : '+e);
+ });
+ worker.port.on('content-to-addon', function(value) {
+ test.assertEqual(
+ "worked",
+ value,
+ "EventEmitter API works!"
+ );
+ if (callbackDone)
+ callbackDone();
+ else
+ workerDone = true;
+ });
+ worker.port.emit('addon-to-content', 'worked');
+ }
+ }],
+ function(win, done) {
+ if (workerDone)
+ done();
+ else
+ callbackDone = done;
+ }
+ );
+};
+
+// Execute two concurrent page mods on same document to ensure that their
+// JS contexts are different
+exports.testMixedContext = function(test) {
+ let doneCallback = null;
+ let messages = 0;
+ let modObject = {
+ include: "data:text/html,",
+ contentScript: 'new ' + function WorkerScope() {
+ // Both scripts will execute this,
+ // context is shared if one script see the other one modification.
+ let isContextShared = "sharedAttribute" in document;
+ self.postMessage(isContextShared);
+ document.sharedAttribute = true;
+ },
+ onAttach: function(w) {
+ w.on("message", function (isContextShared) {
+ if (isContextShared) {
+ test.fail("Page mod contexts are mixed.");
+ doneCallback();
+ }
+ else if (++messages == 2) {
+ test.pass("Page mod contexts are different.");
+ doneCallback();
+ }
+ });
+ }
+ };
+ testPageMod(test, "data:text/html,", [modObject, modObject],
+ function(win, done) {
+ doneCallback = done;
+ }
+ );
+};
+
+exports.testHistory = function(test) {
+ // We need a valid url in order to have a working History API.
+ // (i.e do not work on data: or about: pages)
+ // Test bug 679054.
+ let url = require("self").data.url("test-page-mod.html");
+ let callbackDone = null;
+ testPageMod(test, url, [{
+ include: url,
+ contentScriptWhen: 'end',
+ contentScript: 'new ' + function WorkerScope() {
+ history.pushState({}, "", "#");
+ history.replaceState({foo: "bar"}, "", "#");
+ self.postMessage(history.state);
+ },
+ onAttach: function(worker) {
+ worker.on('message', function (data) {
+ test.assertEqual(JSON.stringify(data), JSON.stringify({foo: "bar"}),
+ "History API works!");
+ callbackDone();
+ });
+ }
+ }],
+ function(win, done) {
+ callbackDone = done;
+ }
+ );
+};
+
+exports.testRelatedTab = function(test) {
+ test.waitUntilDone();
+
+ let tab;
+ let { PageMod } = require("page-mod");
+ let pageMod = new PageMod({
+ include: "about:*",
+ onAttach: function(worker) {
+ test.assertEqual(tab, worker.tab, "Worker.tab is valid");
+ pageMod.destroy();
+ tab.close();
+ test.done();
+ }
+ });
+
+ tabs.open({
+ url: "about:",
+ onOpen: function onOpen(t) {
+ tab = t;
+ }
+ });
+
+};
+
+exports['test tab worker on message'] = function(test) {
+ test.waitUntilDone();
+
+ let { browserWindows } = require("windows");
+ let tabs = require("tabs");
+ let { PageMod } = require("page-mod");
+
+ let url1 = "data:text/html,<title>tab1</title><h1>worker1.tab</h1>";
+ let url2 = "data:text/html,<title>tab2</title><h1>worker2.tab</h1>";
+ let worker1 = null;
+
+ let mod = PageMod({
+ include: "data:text/html,*",
+ contentScriptWhen: "ready",
+ contentScript: "self.postMessage('#1');",
+ onAttach: function onAttach(worker) {
+ worker.on("message", function onMessage() {
+ this.tab.attach({
+ contentScriptWhen: "ready",
+ contentScript: "self.postMessage({ url: window.location.href, title: document.title });",
+ onMessage: function onMessage(data) {
+ test.assertEqual(this.tab.url, data.url, "location is correct");
+ test.assertEqual(this.tab.title, data.title, "title is correct");
+ if (this.tab.url === url1) {
+ worker1 = this;
+ tabs.open({ url: url2, inBackground: true });
+ }
+ else if (this.tab.url === url2) {
+ mod.destroy();
+ worker1.tab.close();
+ worker1.destroy();
+ worker.tab.close();
+ worker.destroy();
+ test.done();
+ }
+ }
+ });
+ });
+ }
+ });
+
+ tabs.open(url1);
+};
+
+exports.testAutomaticDestroy = function(test) {
+ test.waitUntilDone();
+ let loader = Loader(module);
+
+ let pageMod = loader.require("page-mod").PageMod({
+ include: "about:*",
+ contentScriptWhen: "start",
+ onAttach: function(w) {
+ test.fail("Page-mod should have been detroyed during module unload");
+ }
+ });
+
+ // Unload the page-mod module so that our page mod is destroyed
+ loader.unload();
+
+ // Then create a second tab to ensure that it is correctly destroyed
+ let tabs = require("tabs");
+ tabs.open({
+ url: "about:",
+ onReady: function onReady(tab) {
+ test.pass("check automatic destroy");
+ tab.close();
+ test.done();
+ }
+ });
+
+}
+
+exports.testPageModCss = function(test) {
+ let [pageMod] = testPageMod(test,
+ 'data:text/html,<div style="background: silver">css test</div>', [{
+ include: "data:*",
+ contentStyle: "div { height: 100px; }",
+ contentStyleFile:
+ require("self").data.url("pagemod-css-include-file.css")
+ }],
+ function(win, done) {
+ let div = win.document.querySelector("div");
+ test.assertEqual(
+ div.clientHeight,
+ 100,
+ "PageMod contentStyle worked"
+ );
+ test.assertEqual(
+ div.offsetHeight,
+ 120,
+ "PageMod contentStyleFile worked"
+ );
+ done();
+ }
+ );
+};
+
+exports.testPageModCssList = function(test) {
+ let [pageMod] = testPageMod(test,
+ 'data:text/html,<div style="width:320px; max-width: 480px!important">css test</div>', [{
+ include: "data:*",
+ contentStyleFile: [
+ // Highlight evaluation order in this list
+ "data:text/css,div { border: 1px solid black; }",
+ "data:text/css,div { border: 10px solid black; }",
+ // Highlight evaluation order between contentStylesheet & contentStylesheetFile
+ "data:text/css,div { height: 1000px; }",
+ // Highlight precedence between the author and user style sheet
+ "data:text/css,div { width: 200px; max-width: 640px!important}",
+ ],
+ contentStyle: [
+ "div { height: 10px; }",
+ "div { height: 100px; }"
+ ]
+ }],
+ function(win, done) {
+ let div = win.document.querySelector("div"),
+ style = win.getComputedStyle(div);
+
+ test.assertEqual(
+ div.clientHeight,
+ 100,
+ "PageMod contentStyle list works and is evaluated after contentStyleFile"
+ );
+
+ test.assertEqual(
+ div.offsetHeight,
+ 120,
+ "PageMod contentStyleFile list works"
+ );
+
+ test.assertEqual(
+ style.width,
+ "320px",
+ "PageMod author/user style sheet precedence works"
+ );
+
+ test.assertEqual(
+ style.maxWidth,
+ "640px",
+ "PageMod author/user style sheet precedence with !important works"
+ );
+
+ done();
+ }
+ );
+};
+
+exports.testPageModCssDestroy = function(test) {
+ let [pageMod] = testPageMod(test,
+ 'data:text/html,<div style="width:200px">css test</div>', [{
+ include: "data:*",
+ contentStyle: "div { width: 100px!important; }"
+ }],
+
+ function(win, done) {
+ let div = win.document.querySelector("div"),
+ style = win.getComputedStyle(div);
+
+ test.assertEqual(
+ style.width,
+ "100px",
+ "PageMod contentStyle worked"
+ );
+
+ pageMod.destroy();
+ test.assertEqual(
+ style.width,
+ "200px",
+ "PageMod contentStyle is removed after destroy"
+ );
+
+ done();
+
+ }
+ );
+};
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-page-worker.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-page-worker.js
new file mode 100644
index 0000000..5fc3bec
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-page-worker.js
@@ -0,0 +1,366 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+let tests = {}, Pages, Page;
+const { Loader } = require('./helpers');
+
+const ERR_DESTROYED =
+ "The page has been destroyed and can no longer be used.";
+
+tests.testSimplePageCreation = function(test) {
+ test.waitUntilDone();
+
+ let page = new Page({
+ contentScript: "self.postMessage(window.location.href)",
+ contentScriptWhen: "end",
+ onMessage: function (message) {
+ test.assertEqual(message, "about:blank",
+ "Page Worker should start with a blank page by default");
+ test.assertEqual(this, page, "The 'this' object is the page itself.");
+ test.done();
+ }
+ });
+}
+
+/*
+ * Tests that we can't be tricked by document overloads as we have access
+ * to wrapped nodes
+ */
+tests.testWrappedDOM = function(test) {
+ test.waitUntilDone();
+
+ let page = Page({
+ allow: { script: true },
+ contentURL: "data:text/html,<script>document.getElementById=3;window.scrollTo=3;</script>",
+ contentScript: "window.addEventListener('load', function () " +
+ "self.postMessage([typeof(document.getElementById), " +
+ "typeof(window.scrollTo)]), true)",
+ onMessage: function (message) {
+ test.assertEqual(message[0],
+ "function",
+ "getElementById from content script is the native one");
+
+ test.assertEqual(message[1],
+ "function",
+ "scrollTo from content script is the native one");
+
+ test.done();
+ }
+ });
+}
+
+/*
+// We do not offer unwrapped access to DOM since bug 601295 landed
+// See 660780 to track progress of unwrap feature
+tests.testUnwrappedDOM = function(test) {
+ test.waitUntilDone();
+
+ let page = Page({
+ allow: { script: true },
+ contentURL: "data:text/html,<script>document.getElementById=3;window.scrollTo=3;</script>",
+ contentScript: "window.addEventListener('load', function () " +
+ "self.postMessage([typeof(unsafeWindow.document.getElementById), " +
+ "typeof(unsafeWindow.scrollTo)]), true)",
+ onMessage: function (message) {
+ test.assertEqual(message[0],
+ "number",
+ "document inside page is free to be changed");
+
+ test.assertEqual(message[1],
+ "number",
+ "window inside page is free to be changed");
+
+ test.done();
+ }
+ });
+}
+*/
+
+tests.testPageProperties = function(test) {
+ let page = new Page();
+
+ for each (let prop in ['contentURL', 'allow', 'contentScriptFile',
+ 'contentScript', 'contentScriptWhen', 'on',
+ 'postMessage', 'removeListener']) {
+ test.assert(prop in page, prop + " property is defined on page.");
+ }
+
+ test.assert(function () page.postMessage("foo") || true,
+ "postMessage doesn't throw exception on page.");
+}
+
+tests.testConstructorAndDestructor = function(test) {
+ test.waitUntilDone();
+
+ let loader = Loader(module);
+ let Pages = loader.require("page-worker");
+ let global = loader.sandbox("page-worker");
+
+ let pagesReady = 0;
+
+ let page1 = Pages.Page({
+ contentScript: "self.postMessage('')",
+ contentScriptWhen: "end",
+ onMessage: pageReady
+ });
+ let page2 = Pages.Page({
+ contentScript: "self.postMessage('')",
+ contentScriptWhen: "end",
+ onMessage: pageReady
+ });
+
+ test.assertNotEqual(page1, page2,
+ "Page 1 and page 2 should be different objects.");
+
+ function pageReady() {
+ if (++pagesReady == 2) {
+ page1.destroy();
+ page2.destroy();
+
+ test.assert(isDestroyed(page1), "page1 correctly unloaded.");
+ test.assert(isDestroyed(page2), "page2 correctly unloaded.");
+
+ loader.unload();
+ test.done();
+ }
+ }
+}
+
+tests.testAutoDestructor = function(test) {
+ test.waitUntilDone();
+
+ let loader = Loader(module);
+ let Pages = loader.require("page-worker");
+
+ let page = Pages.Page({
+ contentScript: "self.postMessage('')",
+ contentScriptWhen: "end",
+ onMessage: function() {
+ loader.unload();
+ test.assert(isDestroyed(page), "Page correctly unloaded.");
+ test.done();
+ }
+ });
+}
+
+tests.testValidateOptions = function(test) {
+ test.assertRaises(
+ function () Page({ contentURL: 'home' }),
+ "The `contentURL` option must be a valid URL.",
+ "Validation correctly denied a non-URL contentURL"
+ );
+
+ test.assertRaises(
+ function () Page({ onMessage: "This is not a function."}),
+ "The event listener must be a function.",
+ "Validation correctly denied a non-function onMessage."
+ );
+
+ test.pass("Options validation is working.");
+}
+
+tests.testContentAndAllowGettersAndSetters = function(test) {
+ test.waitUntilDone();
+ let content = "data:text/html,<script>window.localStorage.allowScript=3;</script>";
+ let page = Page({
+ contentURL: content,
+ contentScript: "self.postMessage(window.localStorage.allowScript)",
+ contentScriptWhen: "end",
+ onMessage: step0
+ });
+
+ function step0(message) {
+ test.assertEqual(message, "3",
+ "Correct value expected for allowScript - 3");
+ test.assertEqual(page.contentURL, content,
+ "Correct content expected");
+ page.removeListener('message', step0);
+ page.on('message', step1);
+ page.allow = { script: false };
+ page.contentURL = content =
+ "data:text/html,<script>window.localStorage.allowScript='f'</script>";
+ }
+
+ function step1(message) {
+ test.assertEqual(message, "3",
+ "Correct value expected for allowScript - 3");
+ test.assertEqual(page.contentURL, content, "Correct content expected");
+ page.removeListener('message', step1);
+ page.on('message', step2);
+ page.allow = { script: true };
+ page.contentURL = content =
+ "data:text/html,<script>window.localStorage.allowScript='g'</script>";
+ }
+
+ function step2(message) {
+ test.assertEqual(message, "g",
+ "Correct value expected for allowScript - g");
+ test.assertEqual(page.contentURL, content, "Correct content expected");
+ page.removeListener('message', step2);
+ page.on('message', step3);
+ page.allow.script = false;
+ page.contentURL = content =
+ "data:text/html,<script>window.localStorage.allowScript=3</script>";
+ }
+
+ function step3(message) {
+ test.assertEqual(message, "g",
+ "Correct value expected for allowScript - g");
+ test.assertEqual(page.contentURL, content, "Correct content expected");
+ page.removeListener('message', step3);
+ page.on('message', step4);
+ page.allow.script = true;
+ page.contentURL = content =
+ "data:text/html,<script>window.localStorage.allowScript=4</script>";
+ }
+
+ function step4(message) {
+ test.assertEqual(message, "4",
+ "Correct value expected for allowScript - 4");
+ test.assertEqual(page.contentURL, content, "Correct content expected");
+ test.done();
+ }
+
+}
+
+tests.testOnMessageCallback = function(test) {
+ test.waitUntilDone();
+
+ Page({
+ contentScript: "self.postMessage('')",
+ contentScriptWhen: "end",
+ onMessage: function() {
+ test.pass("onMessage callback called");
+ test.done();
+ }
+ });
+}
+
+tests.testMultipleOnMessageCallbacks = function(test) {
+ test.waitUntilDone();
+
+ let count = 0;
+ let page = Page({
+ contentScript: "self.postMessage('')",
+ contentScriptWhen: "end",
+ onMessage: function() count += 1
+ });
+ page.on('message', function() count += 2);
+ page.on('message', function() count *= 3);
+ page.on('message', function()
+ test.assertEqual(count, 9, "All callbacks were called, in order."));
+ page.on('message', function() test.done());
+
+}
+
+tests.testLoadContentPage = function(test) {
+
+ test.waitUntilDone();
+
+ let page = Page({
+ onMessage: function(message) {
+ // The message is an array whose first item is the test method to call
+ // and the rest of whose items are arguments to pass it.
+ test[message.shift()].apply(test, message);
+ },
+ contentURL: require("self").data.url("test-page-worker.html"),
+ contentScriptFile: require("self").data.url("test-page-worker.js"),
+ contentScriptWhen: "ready"
+ });
+
+}
+
+tests.testAllowScriptDefault = function(test) {
+
+ test.waitUntilDone();
+
+ let page = Page({
+ onMessage: function(message) {
+ test.assert(message, "Script is allowed to run by default.");
+ test.done();
+ },
+ contentURL: "data:text/html,<script>document.documentElement.setAttribute('foo', 3);</script>",
+ contentScript: "self.postMessage(document.documentElement.getAttribute('foo'))",
+ contentScriptWhen: "ready"
+ });
+}
+
+tests.testAllowScript = function(test) {
+
+ test.waitUntilDone();
+
+ let page = Page({
+ onMessage: function(message) {
+ test.assert(message, "Script runs when allowed to do so.");
+ test.done();
+ },
+ allow: { script: true },
+ contentURL: "data:text/html,<script>document.documentElement.setAttribute('foo', 3);</script>",
+ contentScript: "self.postMessage(document.documentElement.hasAttribute('foo') && " +
+ " document.documentElement.getAttribute('foo') == 3)",
+ contentScriptWhen: "ready"
+ });
+}
+
+tests.testPingPong = function(test) {
+ test.waitUntilDone();
+ let page = Page({
+ contentURL: 'data:text/html,ping-pong',
+ contentScript: 'self.on("message", function(message) self.postMessage("pong"));'
+ + 'self.postMessage("ready");',
+ onMessage: function(message) {
+ if ('ready' == message) {
+ page.postMessage('ping');
+ }
+ else {
+ test.assert(message, 'pong', 'Callback from contentScript');
+ test.done();
+ }
+ }
+ });
+};
+
+tests.testMultipleDestroys = function(test) {
+ let page = Page();
+ page.destroy();
+ page.destroy();
+ test.pass("Multiple destroys should not cause an error");
+};
+
+
+function isDestroyed(page) {
+ try {
+ page.postMessage("foo");
+ }
+ catch (err if err.message == ERR_DESTROYED) {
+ return true;
+ }
+ return false;
+}
+
+
+let pageWorkerSupported = true;
+
+try {
+ Pages = require("page-worker");
+ Page = Pages.Page;
+}
+catch (ex if ex.message == [
+ "The page-worker module currently supports only Firefox and Thunderbird. ",
+ "In the future, we would like it to support other applications, however. ",
+ "Please see https://bugzilla.mozilla.org/show_bug.cgi?id=546740 for more ",
+ "information."
+ ].join("")) {
+ pageWorkerSupported = false;
+}
+
+if (pageWorkerSupported) {
+ for (let test in tests) {
+ exports[test] = tests[test];
+ }
+} else {
+ exports.testPageWorkerNotSupported = function(test) {
+ test.pass("The page-worker module is not supported on this app.");
+ }
+}
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-panel.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-panel.js
new file mode 100644
index 0000000..e05400e
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-panel.js
@@ -0,0 +1,466 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+let { Cc, Ci } = require("chrome");
+let panels = require('panel');
+let tests = {}, panels, Panel;
+const { Loader } = require('./helpers');
+
+tests.testPanel = function(test) {
+ test.waitUntilDone();
+ let panel = Panel({
+ contentURL: "about:buildconfig",
+ contentScript: "self.postMessage(1); self.on('message', function() self.postMessage(2));",
+ onMessage: function (message) {
+ test.assertEqual(this, panel, "The 'this' object is the panel.");
+ switch(message) {
+ case 1:
+ test.pass("The panel was loaded.");
+ panel.postMessage('');
+ break;
+ case 2:
+ test.pass("The panel posted a message and received a response.");
+ panel.destroy();
+ test.done();
+ break;
+ }
+ }
+ });
+};
+
+tests.testPanelEmit = function(test) {
+ test.waitUntilDone();
+ let panel = Panel({
+ contentURL: "about:buildconfig",
+ contentScript: "self.port.emit('loaded');" +
+ "self.port.on('addon-to-content', " +
+ " function() self.port.emit('received'));",
+ });
+ panel.port.on("loaded", function () {
+ test.pass("The panel was loaded and sent a first event.");
+ panel.port.emit("addon-to-content");
+ });
+ panel.port.on("received", function () {
+ test.pass("The panel posted a message and received a response.");
+ panel.destroy();
+ test.done();
+ });
+};
+
+tests.testPanelEmitEarly = function(test) {
+ test.waitUntilDone();
+ let panel = Panel({
+ contentURL: "about:buildconfig",
+ contentScript: "self.port.on('addon-to-content', " +
+ " function() self.port.emit('received'));",
+ });
+ panel.port.on("received", function () {
+ test.pass("The panel posted a message early and received a response.");
+ panel.destroy();
+ test.done();
+ });
+ panel.port.emit("addon-to-content");
+};
+
+tests.testShowHidePanel = function(test) {
+ test.waitUntilDone();
+ let panel = Panel({
+ contentScript: "self.postMessage('')",
+ contentScriptWhen: "end",
+ onMessage: function (message) {
+ panel.show();
+ },
+ onShow: function () {
+ test.pass("The panel was shown.");
+ test.assertEqual(this, panel, "The 'this' object is the panel.");
+ test.assertEqual(this.isShowing, true, "panel.isShowing == true.");
+ panel.hide();
+ },
+ onHide: function () {
+ test.pass("The panel was hidden.");
+ test.assertEqual(this, panel, "The 'this' object is the panel.");
+ test.assertEqual(this.isShowing, false, "panel.isShowing == false.");
+ panel.destroy();
+ test.done();
+ }
+ });
+};
+
+tests.testDocumentReload = function(test) {
+ test.waitUntilDone();
+ let content =
+ "<script>" +
+ "setTimeout(function () {" +
+ " window.location = 'about:blank';" +
+ "}, 250);" +
+ "</script>";
+ let messageCount = 0;
+ let panel = Panel({
+ contentURL: "data:text/html," + encodeURIComponent(content),
+ contentScript: "self.postMessage(window.location.href)",
+ onMessage: function (message) {
+ messageCount++;
+ if (messageCount == 1) {
+ test.assertMatches(message, /data:text\/html,/, "First document had a content script");
+ }
+ else if (messageCount == 2) {
+ test.assertEqual(message, "about:blank", "Second document too");
+ panel.destroy();
+ test.done();
+ }
+ }
+ });
+};
+
+tests.testParentResizeHack = function(test) {
+ let browserWindow = Cc["@mozilla.org/appshell/window-mediator;1"].
+ getService(Ci.nsIWindowMediator).
+ getMostRecentWindow("navigator:browser");
+ let docShell = browserWindow.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIWebNavigation)
+ .QueryInterface(Ci.nsIDocShell);
+ if (!("allowWindowControl" in docShell)) {
+ // bug 635673 is not fixed in this firefox build
+ test.pass("allowWindowControl attribute that allow to fix browser window " +
+ "resize is not available on this build.");
+ return;
+ }
+
+ test.waitUntilDone(30000);
+
+ let previousWidth = browserWindow.outerWidth, previousHeight = browserWindow.outerHeight;
+
+ let content = "<script>" +
+ "function contentResize() {" +
+ " resizeTo(200,200);" +
+ " resizeBy(200,200);" +
+ "}" +
+ "</script>" +
+ "Try to resize browser window";
+ let panel = Panel({
+ contentURL: "data:text/html," + encodeURIComponent(content),
+ contentScript: "self.on('message', function(message){" +
+ " if (message=='resize') " +
+ " unsafeWindow.contentResize();" +
+ "});",
+ contentScriptWhen: "ready",
+ onMessage: function (message) {
+
+ },
+ onShow: function () {
+ panel.postMessage('resize');
+ require("timer").setTimeout(function () {
+ test.assertEqual(previousWidth,browserWindow.outerWidth,"Size doesn't change by calling resizeTo/By/...");
+ test.assertEqual(previousHeight,browserWindow.outerHeight,"Size doesn't change by calling resizeTo/By/...");
+ panel.destroy();
+ test.done();
+ },0);
+ }
+ });
+ panel.show();
+}
+
+tests.testResizePanel = function(test) {
+ test.waitUntilDone();
+
+ // These tests fail on Linux if the browser window in which the panel
+ // is displayed is not active. And depending on what other tests have run
+ // before this one, it might not be (the untitled window in which the test
+ // runner executes is often active). So we make sure the browser window
+ // is focused by focusing it before running the tests. Then, to be the best
+ // possible test citizen, we refocus whatever window was focused before we
+ // started running these tests.
+
+ let activeWindow = Cc["@mozilla.org/embedcomp/window-watcher;1"].
+ getService(Ci.nsIWindowWatcher).
+ activeWindow;
+ let browserWindow = Cc["@mozilla.org/appshell/window-mediator;1"].
+ getService(Ci.nsIWindowMediator).
+ getMostRecentWindow("navigator:browser");
+
+
+ function onFocus() {
+ browserWindow.removeEventListener("focus", onFocus, true);
+
+ let panel = Panel({
+ contentScript: "self.postMessage('')",
+ contentScriptWhen: "end",
+ height: 10,
+ width: 10,
+ onMessage: function (message) {
+ panel.show();
+ },
+ onShow: function () {
+ panel.resize(100,100);
+ panel.hide();
+ },
+ onHide: function () {
+ test.assert((panel.width == 100) && (panel.height == 100),
+ "The panel was resized.");
+ if (activeWindow)
+ activeWindow.focus();
+ test.done();
+ }
+ });
+ }
+
+ if (browserWindow === activeWindow) {
+ onFocus();
+ }
+ else {
+ browserWindow.addEventListener("focus", onFocus, true);
+ browserWindow.focus();
+ }
+};
+
+tests.testHideBeforeShow = function(test) {
+ test.waitUntilDone();
+ let showCalled = false;
+ let panel = Panel({
+ onShow: function () {
+ showCalled = true;
+ },
+ onHide: function () {
+ test.assert(!showCalled, 'must not emit show if was hidden before');
+ test.done();
+ }
+ });
+ panel.show();
+ panel.hide();
+};
+
+tests.testSeveralShowHides = function(test) {
+ test.waitUntilDone();
+ let hideCalled = 0;
+ let panel = panels.Panel({
+ contentURL: "about:buildconfig",
+ onShow: function () {
+ panel.hide();
+ },
+ onHide: function () {
+ hideCalled++;
+ if (hideCalled < 3)
+ panel.show();
+ else {
+ test.pass("onHide called three times as expected");
+ test.done();
+ }
+ }
+ });
+ panel.on('error', function(e) {
+ test.fail('error was emitted:' + e.message + '\n' + e.stack);
+ });
+ panel.show();
+};
+
+tests.testAnchorAndArrow = function(test) {
+ test.waitUntilDone(20000);
+ let count = 0;
+ function newPanel(tab, anchor) {
+ let panel = panels.Panel({
+ contentURL: "data:text/html,<html><body style='padding: 0; margin: 0; " +
+ "background: gray; text-align: center;'>Anchor: " +
+ anchor.id + "</body></html>",
+ width: 200,
+ height: 100,
+ onShow: function () {
+ count++;
+ panel.destroy();
+ if (count==5) {
+ test.pass("All anchored panel test displayed");
+ tab.close(function () {
+ test.done();
+ });
+ }
+ }
+ });
+ panel.show(anchor);
+ }
+
+ let tabs= require("tabs");
+ let url = 'data:text/html,' +
+ '<html><head><title>foo</title></head><body>' +
+ '<style>div {background: gray; position: absolute; width: 300px; ' +
+ 'border: 2px solid black;}</style>' +
+ '<div id="tl" style="top: 0px; left: 0px;">Top Left</div>' +
+ '<div id="tr" style="top: 0px; right: 0px;">Top Right</div>' +
+ '<div id="bl" style="bottom: 0px; left: 0px;">Bottom Left</div>' +
+ '<div id="br" style="bottom: 0px; right: 0px;">Bottom right</div>' +
+ '</body></html>';
+
+ tabs.open({
+ url: url,
+ onReady: function(tab) {
+ let browserWindow = Cc["@mozilla.org/appshell/window-mediator;1"].
+ getService(Ci.nsIWindowMediator).
+ getMostRecentWindow("navigator:browser");
+ let window = browserWindow.content;
+ newPanel(tab, window.document.getElementById('tl'));
+ newPanel(tab, window.document.getElementById('tr'));
+ newPanel(tab, window.document.getElementById('bl'));
+ newPanel(tab, window.document.getElementById('br'));
+ let anchor = browserWindow.document.getElementById("identity-box");
+ newPanel(tab, anchor);
+ }
+ });
+
+
+
+};
+
+tests.testPanelTextColor = function(test) {
+ test.waitUntilDone();
+ let html = "<html><head><style>body {color: yellow}</style></head>" +
+ "<body><p>Foo</p></body></html>";
+ let panel = Panel({
+ contentURL: "data:text/html," + encodeURI(html),
+ contentScript: "self.port.emit('color', " +
+ "window.getComputedStyle(document.body.firstChild, null). " +
+ " getPropertyValue('color'));"
+ });
+ panel.port.on("color", function (color) {
+ test.assertEqual(color, "rgb(255, 255, 0)",
+ "The panel text color style is preserved when a style exists.");
+ panel.destroy();
+ test.done();
+ });
+};
+
+// Bug 696552: Ensure panel.contentURL modification support
+tests.testChangeContentURL = function(test) {
+ test.waitUntilDone();
+
+ let panel = Panel({
+ contentURL: "about:blank",
+ contentScript: "self.port.emit('ready', document.location.href);"
+ });
+ let count = 0;
+ panel.port.on("ready", function (location) {
+ count++;
+ if (count == 1) {
+ test.assertEqual(location, "about:blank");
+ test.assertEqual(panel.contentURL, "about:blank");
+ panel.contentURL = "about:buildconfig";
+ }
+ else {
+ test.assertEqual(location, "about:buildconfig");
+ test.assertEqual(panel.contentURL, "about:buildconfig");
+ panel.destroy();
+ test.done();
+ }
+ });
+};
+
+function makeEventOrderTest(options) {
+ let expectedEvents = [];
+
+ return function(test) {
+ let panel = panels.Panel({ contentURL: "about:buildconfig" });
+
+ function expect(event, cb) {
+ expectedEvents.push(event);
+ panel.on(event, function() {
+ test.assertEqual(event, expectedEvents.shift());
+ if (cb)
+ require("timer").setTimeout(cb, 1);
+ });
+ return {then: expect};
+ }
+
+ test.waitUntilDone();
+ options.test(test, expect, panel);
+ }
+}
+
+tests.testAutomaticDestroy = function(test) {
+ let loader = Loader(module);
+ let panel = loader.require("panel").Panel({
+ contentURL: "about:buildconfig",
+ contentScript:
+ "self.port.on('event', function() self.port.emit('event-back'));"
+ });
+
+ loader.unload();
+
+ panel.port.on("event-back", function () {
+ test.fail("Panel should have been destroyed on module unload");
+ });
+ panel.port.emit("event");
+ test.pass("check automatic destroy");
+};
+
+tests.testWaitForInitThenShowThenDestroy = makeEventOrderTest({
+ test: function(test, expect, panel) {
+ expect('inited', function() { panel.show(); }).
+ then('show', function() { panel.destroy(); }).
+ then('hide', function() { test.done(); });
+ }
+});
+
+tests.testShowThenWaitForInitThenDestroy = makeEventOrderTest({
+ test: function(test, expect, panel) {
+ panel.show();
+ expect('inited').
+ then('show', function() { panel.destroy(); }).
+ then('hide', function() { test.done(); });
+ }
+});
+
+tests.testShowThenHideThenDestroy = makeEventOrderTest({
+ test: function(test, expect, panel) {
+ panel.show();
+ expect('show', function() { panel.hide(); }).
+ then('hide', function() { panel.destroy(); test.done(); });
+ }
+});
+
+tests.testContentURLOption = function(test) {
+ const URL_STRING = "about:buildconfig";
+ const HTML_CONTENT = "<html><title>Test</title><p>This is a test.</p></html>";
+
+ let (panel = Panel({ contentURL: URL_STRING })) {
+ test.pass("contentURL accepts a string URL.");
+ test.assertEqual(panel.contentURL, URL_STRING,
+ "contentURL is the string to which it was set.");
+ }
+
+ let dataURL = "data:text/html," + encodeURIComponent(HTML_CONTENT);
+ let (panel = Panel({ contentURL: dataURL })) {
+ test.pass("contentURL accepts a data: URL.");
+ }
+
+ let (panel = Panel({})) {
+ test.assert(panel.contentURL == null,
+ "contentURL is undefined.");
+ }
+
+ test.assertRaises(function () Panel({ contentURL: "foo" }),
+ "The `contentURL` option must be a valid URL.",
+ "Panel throws an exception if contentURL is not a URL.");
+};
+
+let panelSupported = true;
+
+try {
+ panels = require("panel");
+ Panel = panels.Panel;
+}
+catch(ex if ex.message == [
+ "The panel module currently supports only Firefox. In the future ",
+ "we would like it to support other applications, however. Please see ",
+ "https://bugzilla.mozilla.org/show_bug.cgi?id=jetpack-panel-apps ",
+ "for more information."
+ ].join("")) {
+ panelSupported = false;
+}
+
+if (panelSupported) {
+ for (let test in tests)
+ exports[test] = tests[test];
+}
+else {
+ exports.testPanelNotSupported = function(test) {
+ test.pass("The panel module is not supported on this app.");
+ }
+}
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-passwords.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-passwords.js
new file mode 100644
index 0000000..bfb137a
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-passwords.js
@@ -0,0 +1,281 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { store, search, remove } = require("passwords");
+
+exports["test store requires `password` field"] = function(assert, done) {
+ store({
+ username: "foo",
+ realm: "bar",
+ onComplete: function onComplete() {
+ assert.fail("onComplete should not be called");
+ },
+ onError: function onError() {
+ assert.pass("'`password` is required");
+ done();
+ }
+ });
+};
+
+exports["test store requires `username` field"] = function(assert, done) {
+ store({
+ password: "foo",
+ realm: "bar",
+ onComplete: function onComplete() {
+ assert.fail("onComplete should not be called");
+ },
+ onError: function onError() {
+ assert.pass("'`username` is required");
+ done();
+ }
+ });
+};
+
+exports["test onComplete is optional"] = function(assert, done) {
+ store({
+ realm: "bla",
+ username: "bla",
+ password: "bla",
+ onError: function onError() {
+ assert.fail("onError was called");
+ }
+ });
+ assert.pass("exception is not thrown if `onComplete is missing")
+ done();
+};
+
+exports["test exceptions in onComplete are reported"] = function(assert, done) {
+ store({
+ realm: "throws",
+ username: "error",
+ password: "boom!",
+ onComplete: function onComplete(error) {
+ throw new Error("Boom!")
+ },
+ onError: function onError(error) {
+ assert.equal(error.message, "Boom!", "Error thrown is reported");
+ done();
+ }
+ });
+};
+
+exports["test store requires `realm` field"] = function(assert, done) {
+ store({
+ username: "foo",
+ password: "bar",
+ onComplete: function onComplete() {
+ assert.fail("onComplete should not be called");
+ },
+ onError: function onError() {
+ assert.pass("'`realm` is required");
+ done();
+ }
+ });
+};
+
+exports["test can't store same login twice"] = function(assert, done) {
+ store({
+ username: "user",
+ password: "pass",
+ realm: "realm",
+ onComplete: function onComplete() {
+ assert.pass("credential saved");
+
+ store({
+ username: "user",
+ password: "pass",
+ realm: "realm",
+ onComplete: function onComplete() {
+ assert.fail("onComplete should not be called");
+ },
+ onError: function onError() {
+ assert.pass("re-saving credential failed");
+
+ remove({
+ username: "user",
+ password: "pass",
+ realm: "realm",
+ onComplete: function onComplete() {
+ assert.pass("credential was removed");
+ done();
+ },
+ onError: function onError() {
+ assert.fail("remove should not fail");
+ }
+ });
+ }
+ });
+ },
+ onError: function onError() {
+ assert.fail("onError should not be called");
+ }
+ });
+};
+
+exports["test remove fails if no login found"] = function(assert, done) {
+ remove({
+ username: "foo",
+ password: "bar",
+ realm: "baz",
+ onComplete: function onComplete() {
+ assert.fail("should not be able to remove unstored credentials");
+ },
+ onError: function onError() {
+ assert.pass("can't remove unstored credentials");
+ done();
+ }
+ });
+};
+
+exports["test addon associated credentials"] = function(assert, done) {
+ store({
+ username: "foo",
+ password: "bar",
+ realm: "baz",
+ onComplete: function onComplete() {
+ search({
+ username: "foo",
+ password: "bar",
+ realm: "baz",
+ onComplete: function onComplete([credential]) {
+ assert.equal(credential.url.indexOf("addon:"), 0,
+ "`addon:` uri is used for add-on credentials");
+ assert.equal(credential.username, "foo",
+ "username matches");
+ assert.equal(credential.password, "bar",
+ "password matches");
+ assert.equal(credential.realm, "baz", "realm matches");
+ assert.equal(credential.formSubmitURL, null,
+ "`formSubmitURL` is `null` for add-on credentials");
+ assert.equal(credential.usernameField, "", "usernameField is empty");
+ assert.equal(credential.passwordField, "", "passwordField is empty");
+
+ remove({
+ username: credential.username,
+ password: credential.password,
+ realm: credential.realm,
+ onComplete: function onComplete() {
+ assert.pass("credential is removed");
+ done();
+ },
+ onError: function onError() {
+ assert.fail("onError should not be called");
+ }
+ });
+ },
+ onError: function onError() {
+ assert.fail("onError should not be called");
+ }
+ });
+ },
+ onError: function onError() {
+ assert.fail("onError should not be called");
+ }
+ });
+};
+
+exports["test web page associated credentials"] = function(assert, done) {
+ store({
+ url: "http://bar.foo.com/authentication/?login",
+ formSubmitURL: "http://login.foo.com/authenticate.cgi",
+ username: "user",
+ password: "pass",
+ usernameField: "user-f",
+ passwordField: "pass-f",
+ onComplete: function onComplete() {
+ search({
+ username: "user",
+ password: "pass",
+ url: "http://bar.foo.com",
+ formSubmitURL: "http://login.foo.com",
+ onComplete: function onComplete([credential]) {
+ assert.equal(credential.url, "http://bar.foo.com", "url matches");
+ assert.equal(credential.username, "user", "username matches");
+ assert.equal(credential.password, "pass", "password matches");
+ assert.equal(credential.realm, null, "realm is null");
+ assert.equal(credential.formSubmitURL, "http://login.foo.com",
+ "formSubmitURL matches");
+ assert.equal(credential.usernameField, "user-f",
+ "usernameField is matches");
+ assert.equal(credential.passwordField, "pass-f",
+ "passwordField matches");
+
+ remove({
+ url: credential.url,
+ formSubmitURL: credential.formSubmitURL,
+ username: credential.username,
+ password: credential.password,
+ usernameField: credential.usernameField,
+ passwordField: credential.passwordField,
+
+ onComplete: function onComplete() {
+ assert.pass("credential is removed");
+ done();
+ },
+ onError: function onError(e) {
+ assert.fail("onError should not be called");
+ }
+ });
+ },
+ onError: function onError() {
+ assert.fail("onError should not be called");
+ }
+ });
+ },
+ onError: function onError() {
+ assert.fail("onError should not be called");
+ }
+ });
+};
+
+exports["test site authentication credentials"] = function(assert, done) {
+ store({
+ url: "http://authentication.com",
+ username: "U",
+ password: "P",
+ realm: "R",
+ onComplete: function onComplete() {
+ search({
+ url: "http://authentication.com",
+ username: "U",
+ password: "P",
+ realm: "R",
+ onComplete: function onComplete([credential]) {
+ assert.equal(credential.url,"http://authentication.com",
+ "url matches");
+ assert.equal(credential.username, "U", "username matches");
+ assert.equal(credential.password, "P", "password matches");
+ assert.equal(credential.realm, "R", "realm matches");
+ assert.equal(credential.formSubmitURL, null, "formSubmitURL is null");
+ assert.equal(credential.usernameField, "", "usernameField is empty");
+ assert.equal(credential.passwordField, "", "passwordField is empty");
+
+ remove({
+ url: credential.url,
+ username: credential.username,
+ password: credential.password,
+ realm: credential.realm,
+ onComplete: function onComplete() {
+ assert.pass("credential is removed");
+ done();
+ },
+ onError: function onError() {
+ assert.fail("onError should not be called");
+ }
+ });
+ },
+ onError: function onError() {
+ assert.fail("onError should not be called");
+ }
+ });
+ },
+ onError: function onError() {
+ assert.fail("onError should not be called");
+ }
+ });
+};
+
+require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-private-browsing.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-private-browsing.js
new file mode 100644
index 0000000..1d60f6b
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-private-browsing.js
@@ -0,0 +1,204 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+let pb = require("private-browsing");
+let {Cc,Ci} = require("chrome");
+const { Loader } = require('./helpers');
+
+let pbService;
+// Currently, only Firefox implements the private browsing service.
+if (require("xul-app").is("Firefox")) {
+ pbService = Cc["@mozilla.org/privatebrowsing;1"].
+ getService(Ci.nsIPrivateBrowsingService);
+}
+
+if (pbService) {
+
+ // tests that isActive has the same value as the private browsing service
+ // expects
+ exports.testGetIsActive = function (test) {
+ test.assertEqual(pb.isActive, false,
+ "private-browsing.isActive is correct without modifying PB service");
+
+ pbService.privateBrowsingEnabled = true;
+ test.assert(pb.isActive,
+ "private-browsing.isActive is correct after modifying PB service");
+
+ // Switch back to normal mode.
+ pbService.privateBrowsingEnabled = false;
+ };
+
+ // tests that activating does put the browser into private browsing mode
+ exports.testActivateDeactivate = function (test) {
+ test.waitUntilDone();
+ pb.once("start", function onStart() {
+ test.assertEqual(pbService.privateBrowsingEnabled, true,
+ "private browsing mode was activated");
+ pb.deactivate();
+ });
+ pb.once("stop", function onStop() {
+ test.assertEqual(pbService.privateBrowsingEnabled, false,
+ "private browsing mode was deactivate");
+ test.done();
+ });
+ pb.activate();
+ };
+
+ exports.testStart = function(test) {
+ test.waitUntilDone();
+ pb.on("start", function onStart() {
+ test.assertEqual(this, pb, "`this` should be private-browsing module");
+ test.assert(pbService.privateBrowsingEnabled,
+ 'private mode is active when "start" event is emitted');
+ test.assert(pb.isActive,
+ '`isActive` is `true` when "start" event is emitted');
+ pb.removeListener("start", onStart);
+ test.done();
+ });
+ pb.activate();
+ };
+
+ exports.testStop = function(test) {
+ test.waitUntilDone();
+ pb.on("stop", function onStop() {
+ test.assertEqual(this, pb, "`this` should be private-browsing module");
+ test.assertEqual(pbService.privateBrowsingEnabled, false,
+ "private mode is disabled when stop event is emitted");
+ test.assertEqual(pb.isActive, false,
+ "`isActive` is `false` when stop event is emitted");
+ pb.removeListener("stop", onStop);
+ test.done();
+ });
+ pb.activate();
+ pb.deactivate();
+ };
+
+ exports.testAutomaticUnload = function(test) {
+ test.waitUntilDone();
+ // Create another private browsing instance and unload it
+ let loader = Loader(module);
+ let pb2 = loader.require("private-browsing");
+ let called = false;
+ pb2.on("start", function onStart() {
+ called = true;
+ test.fail("should not be called:x");
+ });
+ loader.unload();
+
+ // Then switch to private mode in order to check that the previous instance
+ // is correctly destroyed
+ pb.activate();
+ pb.once("start", function onStart() {
+ require("timer").setTimeout(function () {
+ test.assert(!called,
+ "First private browsing instance is destroyed and inactive");
+
+ // Must reset to normal mode, so that next test starts with it.
+ pb.deactivate();
+ test.done();
+ }, 0);
+ });
+ };
+
+ exports.testBothListeners = function(test) {
+ test.waitUntilDone();
+ let stop = false;
+ let start = false;
+
+ function onStop() {
+ test.assertEqual(stop, false,
+ "stop callback must be called only once");
+ test.assertEqual(pbService.privateBrowsingEnabled, false,
+ "private mode is disabled when stop event is emitted");
+ test.assertEqual(pb.isActive, false,
+ "`isActive` is `false` when stop event is emitted");
+
+ pb.on("start", finish);
+ pb.removeListener("start", onStart);
+ pb.removeListener("start", onStart2);
+ pb.activate();
+ stop = true;
+ }
+
+ function onStart() {
+ test.assertEqual(false, start,
+ "stop callback must be called only once");
+ test.assert(pbService.privateBrowsingEnabled,
+ "private mode is active when start event is emitted");
+ test.assert(pb.isActive,
+ "`isActive` is `true` when start event is emitted");
+
+ pb.on("stop", onStop);
+ pb.deactivate();
+ start = true;
+ }
+
+ function onStart2() {
+ test.assert(start, "start listener must be called already");
+ test.assertEqual(false, stop, "stop callback must not be called yet");
+ }
+
+ function finish() {
+ test.assert(pbService.privateBrowsingEnabled, true,
+ "private mode is active when start event is emitted");
+ test.assert(pb.isActive,
+ "`isActive` is `true` when start event is emitted");
+
+ pb.removeListener("start", finish);
+ pb.removeListener("stop", onStop);
+
+ pb.deactivate();
+ pb.once("stop", function () {
+ test.assertEqual(pbService.privateBrowsingEnabled, false);
+ test.assertEqual(pb.isActive, false);
+
+ test.done();
+ });
+ }
+
+ pb.on("start", onStart);
+ pb.on("start", onStart2);
+ pbService.privateBrowsingEnabled = true;
+ };
+
+ exports["test activate private mode via handler"] = function(test) {
+ const tabs = require("tabs");
+
+ test.waitUntilDone();
+ function onReady(tab) {
+ if (tab.url == "about:robots")
+ tab.close(function() pb.activate());
+ }
+ function cleanup(tab) {
+ if (tab.url == "about:") {
+ tabs.removeListener("ready", cleanup);
+ tab.close(function onClose() {
+ test.done();
+ });
+ }
+ }
+
+ tabs.on("ready", onReady);
+ pb.once("start", function onStart() {
+ test.pass("private mode was activated");
+ pb.deactivate();
+ });
+ pb.once("stop", function onStop() {
+ test.pass("private mode was deactivated");
+ tabs.removeListener("ready", onReady);
+ tabs.on("ready", cleanup);
+ });
+ tabs.once("open", function onOpen() {
+ tabs.open("about:robots");
+ });
+ tabs.open("about:");
+ };
+}
+else {
+ // tests for the case where private browsing doesn't exist
+ exports.testNoImpl = function (test) {
+ test.assertEqual(pb.isActive, false,
+ "pb.isActive returns false when private browsing isn't supported");
+ };
+}
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-request.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-request.js
new file mode 100644
index 0000000..42425d7
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-request.js
@@ -0,0 +1,340 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const { Request } = require("addon-kit/request");
+const { pathFor } = require("api-utils/system");
+const { startServerAsync } = require("api-utils/httpd");
+const file = require("api-utils/file");
+
+const basePath = pathFor("TmpD")
+const port = 8099;
+
+
+exports.testOptionsValidator = function(test) {
+ // First, a simple test to make sure we didn't break normal functionality.
+ test.assertRaises(function () {
+ Request({
+ url: null
+ });
+ }, 'The option "url" must be one of the following types: string');
+
+ // Next we'll have a Request that doesn't throw from c'tor, but from a setter.
+ let req = Request({
+ url: "http://playground.zpao.com/jetpack/request/text.php",
+ onComplete: function () {}
+ });
+ test.assertRaises(function () {
+ req.url = null;
+ }, 'The option "url" must be one of the following types: string');
+ // The url shouldn't have changed, so check that
+ test.assertEqual(req.url, "http://playground.zpao.com/jetpack/request/text.php");
+}
+
+exports.testContentValidator = function(test) {
+ test.waitUntilDone();
+ Request({
+ url: "data:text/html,response",
+ content: { 'key1' : null, 'key2' : 'some value' },
+ onComplete: function(response) {
+ test.assertEqual(response.text, "response?key1=null&key2=some+value");
+ test.done();
+ }
+ }).get();
+};
+
+// All tests below here require a network connection. They will be commented out
+// when checked in. If you'd like to run them, simply uncomment them.
+//
+// When we have the means, these tests will be converted so that they don't
+// require an external server nor a network connection.
+
+// This is a request to a file that exists.
+exports.testStatus200 = function (test) {
+ let srv = startServerAsync(port, basePath);
+ let content = "Look ma, no hands!\n";
+ let basename = "test-request.txt"
+ prepareFile(basename, content);
+
+ test.waitUntilDone();
+ var req = Request({
+ url: "http://localhost:" + port + "/" + basename,
+ onComplete: function (response) {
+ test.assertEqual(this, req, "`this` should be request");
+ test.assertEqual(response.status, 200);
+ test.assertEqual(response.statusText, "OK");
+ test.assertEqual(response.headers["Content-Type"], "text/plain");
+ test.assertEqual(response.text, content);
+ srv.stop(function() test.done());
+ }
+ }).get();
+}
+
+// This tries to get a file that doesn't exist
+exports.testStatus404 = function (test) {
+ var srv = startServerAsync(port, basePath);
+
+ test.waitUntilDone();
+ Request({
+ // the following URL doesn't exist
+ url: "http://localhost:" + port + "/test-request-404.txt",
+ onComplete: function (response) {
+ test.assertEqual(response.status, 404);
+ test.assertEqual(response.statusText, "Not Found");
+ srv.stop(function() test.done());
+ }
+ }).get();
+}
+
+/*
+// a simple file with a known header
+exports.testKnownHeader = function (test) {
+ test.waitUntilDone();
+ Request({
+ url: "http://playground.zpao.com/jetpack/request/headers.php",
+ onComplete: function (response) {
+ test.assertEqual(response.headers["x-zpao-header"], "Jamba Juice");
+ test.done();
+ }
+ }).get();
+}
+
+// complex headers
+exports.testKnownHeader = function (test) {
+ let headers = {
+ "x-zpao-header": "Jamba Juice is: delicious",
+ "x-zpao-header-2": "foo, bar",
+ "Set-Cookie": "foo=bar\nbaz=foo"
+ }
+ test.waitUntilDone();
+ Request({
+ url: "http://playground.zpao.com/jetpack/request/complex_headers.php",
+ onComplete: function (response) {
+ for (k in headers) {
+ test.assertEqual(response.headers[k], headers[k]);
+ }
+ test.done();
+ }
+ }).get();
+}
+*/
+
+exports.testSimpleJSON = function (test) {
+ let srv = startServerAsync(port, basePath);
+ let json = { foo: "bar" };
+ let basename = "test-request.json";
+ prepareFile(basename, JSON.stringify(json));
+
+ test.waitUntilDone();
+ Request({
+ url: "http://localhost:" + port + "/" + basename,
+ onComplete: function (response) {
+ assertDeepEqual(test, response.json, json);
+ srv.stop(function() test.done());
+ }
+ }).get();
+}
+
+exports.testInvalidJSON = function (test) {
+ let srv = startServerAsync(port, basePath);
+ let basename = "test-request-invalid.json";
+ prepareFile(basename, '"this": "isn\'t JSON"');
+
+ test.waitUntilDone();
+ Request({
+ url: "http://localhost:" + port + "/" + basename,
+ onComplete: function (response) {
+ test.assertEqual(response.json, null);
+ srv.stop(function() test.done());
+ }
+ }).get();
+}
+
+/*
+exports.testGetWithParamsNotContent = function (test) {
+ test.waitUntilDone();
+ Request({
+ url: "http://playground.zpao.com/jetpack/request/getpost.php?foo=bar",
+ onComplete: function (response) {
+ let expected = {
+ "POST": [],
+ "GET" : { foo: "bar" }
+ };
+ assertDeepEqual(test, response.json, expected);
+ test.done();
+ }
+ }).get();
+}
+
+exports.testGetWithContent = function (test) {
+ test.waitUntilDone();
+ Request({
+ url: "http://playground.zpao.com/jetpack/request/getpost.php",
+ content: { foo: "bar" },
+ onComplete: function (response) {
+ let expected = {
+ "POST": [],
+ "GET" : { foo: "bar" }
+ };
+ assertDeepEqual(test, response.json, expected);
+ test.done();
+ }
+ }).get();
+}
+
+exports.testGetWithParamsAndContent = function (test) {
+ test.waitUntilDone();
+ Request({
+ url: "http://playground.zpao.com/jetpack/request/getpost.php?foo=bar",
+ content: { baz: "foo" },
+ onComplete: function (response) {
+ let expected = {
+ "POST": [],
+ "GET" : { foo: "bar", baz: "foo" }
+ };
+ assertDeepEqual(test, response.json, expected);
+ test.done();
+ }
+ }).get();
+}
+
+exports.testSimplePost = function (test) {
+ test.waitUntilDone();
+ Request({
+ url: "http://playground.zpao.com/jetpack/request/getpost.php",
+ content: { foo: "bar" },
+ onComplete: function (response) {
+ let expected = {
+ "POST": { foo: "bar" },
+ "GET" : []
+ };
+ assertDeepEqual(test, response.json, expected);
+ test.done();
+ }
+ }).post();
+}
+
+exports.testEncodedContent = function (test) {
+ test.waitUntilDone();
+ Request({
+ url: "http://playground.zpao.com/jetpack/request/getpost.php",
+ content: "foo=bar&baz=foo",
+ onComplete: function (response) {
+ let expected = {
+ "POST": [],
+ "GET" : { foo: "bar", baz: "foo" }
+ };
+ assertDeepEqual(test, response.json, expected);
+ test.done();
+ }
+ }).get();
+}
+
+exports.testEncodedContentWithSpaces = function (test) {
+ test.waitUntilDone();
+ Request({
+ url: "http://playground.zpao.com/jetpack/request/getpost.php",
+ content: "foo=bar+hop!&baz=foo",
+ onComplete: function (response) {
+ let expected = {
+ "POST": [],
+ "GET" : { foo: "bar hop!", baz: "foo" }
+ };
+ assertDeepEqual(test, response.json, expected);
+ test.done();
+ }
+ }).get();
+}
+
+exports.testGetWithArray = function (test) {
+ test.waitUntilDone();
+ Request({
+ url: "http://playground.zpao.com/jetpack/request/getpost.php",
+ content: { foo: [1, 2], baz: "foo" },
+ onComplete: function (response) {
+ let expected = {
+ "POST": [],
+ "GET" : { foo: [1, 2], baz: "foo" }
+ };
+ assertDeepEqual(test, response.json, expected);
+ test.done();
+ }
+ }).get();
+}
+
+exports.testGetWithNestedArray = function (test) {
+ test.waitUntilDone();
+ Request({
+ url: "http://playground.zpao.com/jetpack/request/getpost.php",
+ content: { foo: [1, 2, [3, 4]], bar: "baz" },
+ onComplete: function (response) {
+ let expected = {
+ "POST": [],
+ "GET" : this.content
+ };
+ assertDeepEqual(test, response.json, expected);
+ test.done();
+ }
+ }).get();
+}
+
+exports.testGetWithNestedArray = function (test) {
+ test.waitUntilDone();
+ let request = Request({
+ url: "http://playground.zpao.com/jetpack/request/getpost.php",
+ content: {
+ foo: [1, 2, {
+ omg: "bbq",
+ "all your base!": "are belong to us"
+ }],
+ bar: "baz"
+ },
+ onComplete: function (response) {
+ let expected = {
+ "POST": [],
+ "GET" : request.content
+ };
+ assertDeepEqual(test, response.json, expected);
+ test.done();
+ }
+ }).get();
+}
+*/
+
+// This is not a proper testing for deep equal, but it's good enough for my uses
+// here. It will do type coercion to check equality, but that's good here. Data
+// coming from the server will be stringified and so "0" should be equal to 0.
+function assertDeepEqual(test, obj1, obj2, msg) {
+ function equal(o1, o2) {
+ // cover our non-object cases well enough
+ if (o1 == o2)
+ return true;
+ if (typeof(o1) != typeof(o2))
+ return false;
+ if (typeof(o1) != "object")
+ return o1 == o2;
+
+ let e = true;
+ for (let [key, val] in Iterator(o1)) {
+ e = e && key in o2 && equal(o2[key], val);
+ if (!e)
+ break;
+ }
+ for (let [key, val] in Iterator(o2)) {
+ e = e && key in o1 && equal(o1[key], val);
+ if (!e)
+ break;
+ }
+ return e;
+ }
+ msg = msg || "objects not equal - " + JSON.stringify(obj1) + " != " +
+ JSON.stringify(obj2);
+ test.assert(equal(obj1, obj2), msg);
+}
+
+function prepareFile(basename, content) {
+ let filePath = file.join(basePath, basename);
+ let fileStream = file.open(filePath, 'w');
+ fileStream.write(content);
+ fileStream.close();
+}
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-selection.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-selection.js
new file mode 100644
index 0000000..06feb7e
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-selection.js
@@ -0,0 +1,458 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+let timer = require("timer");
+let {Cc,Ci} = require("chrome");
+
+// Arbitrary delay needed to avoid weird behavior.
+// TODO: We need to find all uses of this and replace them
+// with more deterministic solutions.
+const ARB_DELAY = 100;
+
+// Select all divs elements in an HTML document
+function selectAllDivs(window) {
+ let divs = window.document.getElementsByTagName("div");
+ let s = window.getSelection();
+ if (s.rangeCount > 0)
+ s.removeAllRanges();
+ for (let i = 0; i < divs.length; i++) {
+ let range = window.document.createRange();
+ range.selectNode(divs[i]);
+ s.addRange(range);
+ }
+}
+
+function selectTextarea(window, from, to) {
+ let textarea = window.document.getElementsByTagName("textarea")[0];
+
+ from = from || 0;
+ to = to || textarea.value.length;
+
+ textarea.setSelectionRange(from, to);
+ textarea.focus();
+}
+
+function primeTestCase(html, test, callback) {
+ let tabBrowser = require("tab-browser");
+ let dataURL = "data:text/html," + encodeURI(html);
+ let tracker = tabBrowser.whenContentLoaded(
+ function(window) {
+ if (window.document.location.href != dataURL)
+ return;
+ callback(window, test);
+ timer.setTimeout(function() {
+ tracker.unload();
+ test.done();
+ window.close();
+ },
+ ARB_DELAY);
+ }
+ );
+ tabBrowser.addTab(dataURL);
+}
+
+const DIV1 = '<div id="foo">bar</div>';
+const DIV2 = '<div>noodles</div>';
+const HTML_MULTIPLE = '<html><body>' + DIV1 + DIV2 + '</body></html>';
+const HTML_SINGLE = '<html><body>' + DIV1 + '</body></html>';
+
+// Tests of contiguous
+
+exports.testContiguousMultiple = function testContiguousMultiple(test) {
+ let selection = require("selection");
+ primeTestCase(HTML_MULTIPLE, test, function(window, test) {
+ selectAllDivs(window);
+ test.assertEqual(selection.isContiguous, false,
+ "selection.isContiguous multiple works.");
+ });
+
+ test.waitUntilDone(5000);
+};
+
+exports.testContiguousSingle = function testContiguousSingle(test) {
+ let selection = require("selection");
+ primeTestCase(HTML_SINGLE, test, function(window, test) {
+ selectAllDivs(window);
+ test.assertEqual(selection.isContiguous, true,
+ "selection.isContiguous single works.");
+ });
+
+ test.waitUntilDone(5000);
+};
+
+exports.testContiguousWithoutSelection =
+ function testContiguousWithoutSelection(test) {
+ let selection = require("selection");
+ primeTestCase(HTML_SINGLE, test, function(window, test) {
+ test.assertEqual(selection.isContiguous, false,
+ "selection.isContiguous without selection works.");
+ });
+
+ test.waitUntilDone(5000);
+};
+
+/**
+ * Test that setting the contiguous property has no effect.
+ */
+/*exports.testSetContiguous = function testSetContiguous(test) {
+ let selection = require("selection");
+ primeTestCase(HTML_MULTIPLE, test, function(window, test) {
+ selectAllDivs(window);
+ try {
+ selection.isContiguous = true;
+ test.assertEqual(selection.isContiguous, false,
+ "setting selection.isContiguous doesn't work (as expected).");
+ }
+ catch (e) {
+ test.pass("setting selection.isContiguous doesn't work (as expected).");
+ }
+ });
+
+ test.waitUntilDone(5000);
+};*/
+
+
+// HTML tests
+
+exports.testGetHTMLSingleSelection = function testGetHTMLSingleSelection(test) {
+ let selection = require("selection");
+ primeTestCase(HTML_SINGLE, test, function(window, test) {
+ selectAllDivs(window);
+ test.assertEqual(selection.html, DIV1, "get html selection works");
+ });
+
+ test.waitUntilDone(5000);
+};
+
+/* Myk's comments: This is fine. However, it reminds me to figure out and
+ specify whether iteration is ordered. If so, we'll want to change this
+ test in the future to test that the discontiguous selections are returned in
+ the appropriate order. In the meantime, add a comment to that effect here */
+exports.testGetHTMLMultipleSelection =
+ function testGetHTMLMultipleSelection(test) {
+ let selection = require("selection");
+ primeTestCase(HTML_MULTIPLE, test, function(window, test) {
+ selectAllDivs(window);
+ let assertions = false;
+ for each (let i in selection) {
+ test.assertEqual(true, [DIV1, DIV2].some(function(t) t == i.html),
+ "get multiple selection html works");
+ assertions = true;
+ }
+ // Ensure we ran at least one assertEqual()
+ test.assert(assertions, "No assertions were called");
+ });
+
+ test.waitUntilDone(5000);
+};
+
+exports.testGetHTMLNull = function testGetHTMLNull(test) {
+ let selection = require("selection");
+ primeTestCase(HTML_SINGLE, test, function(window, test) {
+ test.assertEqual(selection.html, null, "get html null works");
+ });
+
+ test.waitUntilDone(5000);
+};
+
+exports.testGetHTMLWeird = function testGetHTMLWeird(test) {
+ let selection = require("selection");
+ // If the getter is used when there are contiguous selections, the first
+ // selection should be returned
+ primeTestCase(HTML_MULTIPLE, test, function(window, test) {
+ selectAllDivs(window);
+ test.assertEqual(selection.html, DIV1, "get html weird works");
+ });
+
+ test.waitUntilDone(5000);
+};
+
+exports.testGetHTMLNullInTextareaSelection =
+ function testGetHTMLNullInTextareaSelection(test) {
+ let selection = require("selection");
+
+ primeTestCase(TEXT_FIELD, test, function(window, test) {
+ selectTextarea(window);
+
+ test.assertEqual(selection.html, null, "get html null in textarea works")
+ });
+
+ test.waitUntilDone(5000);
+};
+
+const REPLACEMENT_HTML = "<b>Lorem ipsum dolor sit amet</b>";
+
+exports.testSetHTMLSelection = function testSetHTMLSelection(test) {
+ let selection = require("selection");
+ primeTestCase(HTML_SINGLE, test, function(window, test) {
+ selectAllDivs(window);
+ selection.html = REPLACEMENT_HTML;
+ test.assertEqual(selection.html, "<span>" + REPLACEMENT_HTML +
+ "</span>", "selection html works");
+ });
+
+ test.waitUntilDone(5000);
+};
+
+exports.testSetHTMLException = function testSetHTMLException(test) {
+ let selection = require("selection");
+ primeTestCase(HTML_SINGLE, test, function(window, test) {
+ try {
+ selection.html = REPLACEMENT_HTML;
+ test.fail("set HTML throws when there's no selection.");
+ }
+ catch (e) {
+ test.pass("set HTML throws when there's no selection.");
+ }
+ });
+
+ test.waitUntilDone(5000);
+};
+
+const TEXT1 = "foo";
+const TEXT2 = "noodles";
+const TEXT_MULTIPLE = "<html><body><div>" + TEXT1 + "</div><div>" + TEXT2 +
+ "</div></body></html>";
+const TEXT_SINGLE = "<html><body><div>" + TEXT1 + "</div></body></html>";
+const TEXT_FIELD = "<html><body><textarea>" + TEXT1 + "</textarea></body></html>";
+
+// Text tests
+
+exports.testSetHTMLinTextareaSelection =
+ function testSetHTMLinTextareaSelection(test) {
+ let selection = require("selection");
+
+ primeTestCase(TEXT_FIELD, test, function(window, test) {
+ selectTextarea(window);
+
+ // HTML string is set as plain text in textareas, that's because
+ // `selection.html` and `selection.text` are basically aliases when a
+ // value is set. See bug 677269
+ selection.html = REPLACEMENT_HTML;
+
+ test.assertEqual(selection.text, REPLACEMENT_HTML,
+ "set selection html in textarea works");
+ });
+
+ test.waitUntilDone(5000);
+};
+
+exports.testGetTextSingleSelection =
+ function testGetTextSingleSelection(test) {
+ let selection = require("selection");
+ primeTestCase(TEXT_SINGLE, test, function(window, test) {
+ selectAllDivs(window);
+ test.assertEqual(selection.text, TEXT1, "get text selection works");
+ });
+
+ test.waitUntilDone(5000);
+};
+
+exports.testGetTextMultipleSelection =
+ function testGetTextMultipleSelection(test) {
+ let selection = require("selection");
+ primeTestCase(TEXT_MULTIPLE, test, function(window, test) {
+ selectAllDivs(window);
+ let assertions = false;
+ for each (let i in selection) {
+ test.assertEqual(true, [TEXT1, TEXT2].some(function(t) t == i.text),
+ "get multiple selection text works");
+ assertions = true;
+ }
+ // Ensure we ran at least one assertEqual()
+ test.assert(assertions, "No assertions were called");
+ });
+
+ test.waitUntilDone(5000);
+};
+
+exports.testGetTextNull = function testGetTextNull(test) {
+ let selection = require("selection");
+ primeTestCase(TEXT_SINGLE, test, function(window, test) {
+ test.assertEqual(selection.text, null, "get text null works");
+ });
+
+ test.waitUntilDone(5000);
+};
+
+exports.testGetTextWeird = function testGetTextWeird(test) {
+ let selection = require("selection");
+ // If the getter is used when there are contiguous selections, the first
+ // selection should be returned
+ primeTestCase(TEXT_MULTIPLE, test, function(window, test) {
+ selectAllDivs(window);
+ test.assertEqual(selection.text, TEXT1, "get text weird works");
+ });
+
+ test.waitUntilDone(5000);
+};
+
+exports.testGetTextNullInTextareaSelection =
+ function testGetTextInTextareaSelection(test) {
+ let selection = require("selection");
+
+ primeTestCase(TEXT_FIELD, test, function(window, test) {
+ test.assertEqual(selection.text, null, "get text null in textarea works")
+ });
+
+ test.waitUntilDone(5000);
+};
+
+exports.testGetTextInTextareaSelection =
+ function testGetTextInTextareaSelection(test) {
+ let selection = require("selection");
+
+ primeTestCase(TEXT_FIELD, test, function(window, test) {
+ selectTextarea(window);
+
+ test.assertEqual(selection.text, TEXT1, "get text null in textarea works")
+ });
+
+ test.waitUntilDone(5000);
+};
+
+const REPLACEMENT_TEXT = "Lorem ipsum dolor sit amet";
+
+exports.testSetTextSelection = function testSetTextSelection(test) {
+ let selection = require("selection");
+ primeTestCase(TEXT_SINGLE, test, function(window, test) {
+ selectAllDivs(window);
+ selection.text = REPLACEMENT_TEXT;
+ test.assertEqual(selection.text, REPLACEMENT_TEXT, "selection text works");
+ });
+
+ test.waitUntilDone(5000);
+};
+
+exports.testSetHTMLException = function testSetHTMLException(test) {
+ let selection = require("selection");
+ primeTestCase(TEXT_SINGLE, test, function(window, test) {
+ try {
+ selection.text = REPLACEMENT_TEXT;
+ test.fail("set HTML throws when there's no selection.");
+ }
+ catch (e) {
+ test.pass("set HTML throws when there's no selection.");
+ }
+ });
+
+ test.waitUntilDone(5000);
+};
+
+exports.testSetTextInTextareaSelection =
+ function testSetTextInTextareaSelection(test) {
+ let selection = require("selection");
+
+ primeTestCase(TEXT_FIELD, test, function(window, test) {
+ selectTextarea(window);
+
+ selection.text = REPLACEMENT_TEXT;
+
+ test.assertEqual(selection.text, REPLACEMENT_TEXT,
+ "set selection text in textarea works");
+ });
+
+ test.waitUntilDone(5000);
+};
+
+// Iterator tests
+
+exports.testIterator = function testIterator(test) {
+ let selection = require("selection");
+ let selectionCount = 0;
+ primeTestCase(TEXT_MULTIPLE, test, function(window, test) {
+ selectAllDivs(window);
+ for each (let i in selection)
+ selectionCount++;
+ test.assertEqual(2, selectionCount, "iterator works.");
+ });
+
+ test.waitUntilDone(5000);
+};
+
+exports.testIteratorWithTextareaSelection =
+ function testIteratorWithTextareaSelection(test) {
+ let selection = require("selection");
+ let selectionCount = 0;
+
+ primeTestCase(TEXT_FIELD, test, function(window, test) {
+ selectTextarea(window);
+
+ for each (let i in selection)
+ selectionCount++;
+
+ test.assertEqual(1, selectionCount, "iterator works in textarea.");
+ });
+
+ test.waitUntilDone(5000);
+};
+
+/* onSelect tests */
+
+/*
+function sendSelectionSetEvent(window) {
+ const Ci = Components.interfaces;
+ let utils = window.QueryInterface(Ci.nsIInterfaceRequestor).
+ getInterface(Ci.nsIDOMWindowUtils);
+ if (!utils.sendSelectionSetEvent(0, 1, false))
+ dump("**** sendSelectionSetEvent did not select anything\n");
+ else
+ dump("**** sendSelectionSetEvent succeeded\n");
+}
+
+// testOnSelect() requires nsIDOMWindowUtils, which is only available in
+// Firefox 3.7+.
+exports.testOnSelect = function testOnSelect(test) {
+ let selection = require("selection");
+ let callbackCount = 0;
+ primeTestCase(TEXT_SINGLE, test, function(window, test) {
+ selection.onSelect = function() {callbackCount++};
+ // Now simulate the user selecting stuff
+ sendSelectionSetEvent(window);
+ selection.text = REPLACEMENT_TEXT;
+ test.assertEqual(1, callbackCount, "onSelect text listener works.");
+ //test.pass();
+ //test.done();
+ });
+
+ test.waitUntilDone(5000);
+};
+
+// testOnSelectExceptionNoBubble() requires nsIDOMWindowUtils, which is only
+// available in Firefox 3.7+.
+exports.testOnSelectExceptionNoBubble =
+ function testOnSelectTextSelection(test) {
+ let selection = require("selection");
+ primeTestCase(HTML_SINGLE, test, function(window, test) {
+ selection.onSelect = function() {
+ throw new Error("Exception thrown in testOnSelectExceptionNoBubble");
+ };
+ // Now simulate the user selecting stuff
+ sendSelectionSetEvent(window);
+ test.pass("onSelect catches exceptions.");
+ });
+
+ test.waitUntilDone(5000);
+};
+*/
+
+// If the module doesn't support the app we're being run in, require() will
+// throw. In that case, remove all tests above from exports, and add one dummy
+// test that passes.
+try {
+ require("selection");
+}
+catch (err) {
+ // This bug should be mentioned in the error message.
+ let bug = "https://bugzilla.mozilla.org/show_bug.cgi?id=560716";
+ if (err.message.indexOf(bug) < 0)
+ throw err;
+ for (let [prop, val] in Iterator(exports)) {
+ if (/^test/.test(prop) && typeof(val) === "function")
+ delete exports[prop];
+ }
+ exports.testAppNotSupported = function (test) {
+ test.pass("The selection module does not support this application.");
+ };
+}
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-simple-prefs.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-simple-prefs.js
new file mode 100644
index 0000000..7452a8a
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-simple-prefs.js
@@ -0,0 +1,175 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+const { Loader } = require("./helpers");
+const { setTimeout } = require("timers");
+const { notify } = require("observer-service");
+const { jetpackID } = require("@packaging");
+
+exports.testSetGetBool = function(test) {
+ test.waitUntilDone();
+
+ let loader = Loader(module);
+ let sp = loader.require("simple-prefs").prefs;
+
+ test.assertEqual(sp.test, undefined, "Value should not exist");
+ sp.test = true;
+ test.assert(sp.test, "Value read should be the value previously set");
+
+ loader.unload();
+ test.done();
+};
+
+exports.testSetGetInt = function(test) {
+ test.waitUntilDone();
+
+ // Load the module once, set a value.
+ let loader = Loader(module);
+ let sp = loader.require("simple-prefs").prefs;
+
+ test.assertEqual(sp["test-int"], undefined, "Value should not exist");
+ sp["test-int"] = 1;
+ test.assertEqual(sp["test-int"], 1, "Value read should be the value previously set");
+
+ loader.unload();
+ test.done();
+};
+
+exports.testSetComplex = function(test) {
+ test.waitUntilDone();
+
+ let loader = Loader(module);
+ let sp = loader.require("simple-prefs").prefs;
+
+ try {
+ sp["test-complex"] = {test: true};
+ test.fail("Complex values are not allowed");
+ }
+ catch (e) {
+ test.pass("Complex values are not allowed");
+ }
+
+ loader.unload();
+ test.done();
+};
+
+exports.testSetGetString = function(test) {
+ test.waitUntilDone();
+
+ let loader = Loader(module);
+ let sp = loader.require("simple-prefs").prefs;
+
+ test.assertEqual(sp["test-string"], undefined, "Value should not exist");
+ sp["test-string"] = "test";
+ test.assertEqual(sp["test-string"], "test", "Value read should be the value previously set");
+
+ loader.unload();
+ test.done();
+};
+
+exports.testHasAndRemove = function(test) {
+ test.waitUntilDone();
+
+ let loader = Loader(module);
+ let sp = loader.require("simple-prefs").prefs;
+
+ sp.test = true;
+ test.assert(("test" in sp), "Value exists");
+ delete sp.test;
+ test.assertEqual(sp.test, undefined, "Value should be undefined");
+
+ loader.unload();
+ test.done();
+
+};
+
+exports.testPrefListener = function(test) {
+ test.waitUntilDone();
+
+ let loader = Loader(module);
+ let sp = loader.require("simple-prefs");
+
+ let listener = function(prefName) {
+ test.assertEqual(prefName, "test-listen", "The prefs listener heard the right event");
+ test.done();
+ };
+
+ sp.on("test-listen", listener);
+
+ sp.prefs["test-listen"] = true;
+ loader.unload();
+};
+
+exports.testBtnListener = function(test) {
+ test.waitUntilDone();
+
+ let loader = Loader(module);
+ let sp = loader.require("simple-prefs");
+
+ sp.on("test-btn-listen", function() {
+ test.pass("Button press event was heard");
+ test.done();
+ });
+ notify((jetpackID + "-cmdPressed"), "", "test-btn-listen");
+
+ loader.unload();
+};
+
+exports.testPrefRemoveListener = function(test) {
+ test.waitUntilDone();
+
+ let loader = Loader(module);
+ let sp = loader.require("simple-prefs");
+ let counter = 0;
+
+ let listener = function() {
+ test.pass("The prefs listener was not removed yet");
+
+ if (++counter > 1)
+ test.fail("The prefs listener was not removed");
+
+ sp.removeListener("test-listen2", listener);
+
+ sp.prefs["test-listen2"] = false;
+
+ setTimeout(function() {
+ test.pass("The prefs listener was removed");
+ loader.unload();
+ test.done();
+ }, 250);
+ };
+
+ sp.on("test-listen2", listener);
+
+ // emit change
+ sp.prefs["test-listen2"] = true;
+};
+
+// Bug 710117: Test that simple-pref listeners are removed on unload
+exports.testPrefUnloadListener = function(test) {
+ test.waitUntilDone();
+
+ let loader = Loader(module);
+ let sp = loader.require("simple-prefs");
+ let counter = 0;
+
+ let listener = function() {
+ test.assertEqual(++counter, 1, "This listener should only be called once");
+
+ loader.unload();
+
+ // this may not execute after unload, but definitely shouldn't fire listener
+ sp.prefs["test-listen3"] = false;
+ // this should execute, but also definitely shouldn't fire listener
+ require("simple-prefs").prefs["test-listen3"] = false; //
+
+ test.done();
+ };
+
+ sp.on("test-listen3", listener);
+
+ // emit change
+ sp.prefs["test-listen3"] = true;
+};
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-simple-storage.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-simple-storage.js
new file mode 100644
index 0000000..25d0770
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-simple-storage.js
@@ -0,0 +1,311 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim:set ts=2 sw=2 sts=2 et filetype=javascript
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const file = require("file");
+const prefs = require("preferences-service");
+
+const QUOTA_PREF = "extensions.addon-sdk.simple-storage.quota";
+
+let {Cc,Ci} = require("chrome");
+
+const { Loader } = require("./helpers");
+const options = require("@packaging");
+
+let storeFile = Cc["@mozilla.org/file/directory_service;1"].
+ getService(Ci.nsIProperties).
+ get("ProfD", Ci.nsIFile);
+storeFile.append("jetpack");
+storeFile.append(options.jetpackID);
+storeFile.append("simple-storage");
+storeFile.append("store.json");
+let storeFilename = storeFile.path;
+
+function manager(loader) loader.sandbox("simple-storage").manager;
+
+exports.testSetGet = function (test) {
+ test.waitUntilDone();
+
+ // Load the module once, set a value.
+ let loader = Loader(module);
+ let ss = loader.require("simple-storage");
+ manager(loader).jsonStore.onWrite = function (storage) {
+ test.assert(file.exists(storeFilename), "Store file should exist");
+
+ // Load the module again and make sure the value stuck.
+ loader = Loader(module);
+ ss = loader.require("simple-storage");
+ manager(loader).jsonStore.onWrite = function (storage) {
+ file.remove(storeFilename);
+ test.done();
+ };
+ test.assertEqual(ss.storage.foo, val, "Value should persist");
+ loader.unload();
+ };
+ let val = "foo";
+ ss.storage.foo = val;
+ test.assertEqual(ss.storage.foo, val, "Value read should be value set");
+ loader.unload();
+};
+
+exports.testSetGetRootArray = function (test) {
+ setGetRoot(test, [1, 2, 3], function (arr1, arr2) {
+ if (arr1.length !== arr2.length)
+ return false;
+ for (let i = 0; i < arr1.length; i++) {
+ if (arr1[i] !== arr2[i])
+ return false;
+ }
+ return true;
+ });
+};
+
+exports.testSetGetRootBool = function (test) {
+ setGetRoot(test, true);
+};
+
+exports.testSetGetRootFunction = function (test) {
+ setGetRootError(test, function () {},
+ "Setting storage to a function should fail");
+};
+
+exports.testSetGetRootNull = function (test) {
+ setGetRoot(test, null);
+};
+
+exports.testSetGetRootNumber = function (test) {
+ setGetRoot(test, 3.14);
+};
+
+exports.testSetGetRootObject = function (test) {
+ setGetRoot(test, { foo: 1, bar: 2 }, function (obj1, obj2) {
+ for (let [prop, val] in Iterator(obj1)) {
+ if (!(prop in obj2) || obj2[prop] !== val)
+ return false;
+ }
+ for (let [prop, val] in Iterator(obj2)) {
+ if (!(prop in obj1) || obj1[prop] !== val)
+ return false;
+ }
+ return true;
+ });
+};
+
+exports.testSetGetRootString = function (test) {
+ setGetRoot(test, "sho' 'nuff");
+};
+
+exports.testSetGetRootUndefined = function (test) {
+ setGetRootError(test, undefined, "Setting storage to undefined should fail");
+};
+
+exports.testEmpty = function (test) {
+ let loader = Loader(module);
+ let ss = loader.require("simple-storage");
+ loader.unload();
+ test.assert(!file.exists(storeFilename), "Store file should not exist");
+};
+
+exports.testMalformed = function (test) {
+ let stream = file.open(storeFilename, "w");
+ stream.write("i'm not json");
+ stream.close();
+ let loader = Loader(module);
+ let ss = loader.require("simple-storage");
+ let empty = true;
+ for (let key in ss.storage) {
+ empty = false;
+ break;
+ }
+ test.assert(empty, "Malformed storage should cause root to be empty");
+ loader.unload();
+};
+
+// Go over quota and handle it by listener.
+exports.testQuotaExceededHandle = function (test) {
+ test.waitUntilDone();
+ prefs.set(QUOTA_PREF, 18);
+
+ let loader = Loader(module);
+ let ss = loader.require("simple-storage");
+ ss.on("OverQuota", function () {
+ test.pass("OverQuota was emitted as expected");
+ test.assertEqual(this, ss, "`this` should be simple storage");
+ ss.storage = { x: 4, y: 5 };
+
+ manager(loader).jsonStore.onWrite = function () {
+ loader = Loader(module);
+ ss = loader.require("simple-storage");
+ let numProps = 0;
+ for (let prop in ss.storage)
+ numProps++;
+ test.assert(numProps, 2,
+ "Store should contain 2 values: " + ss.storage.toSource());
+ test.assertEqual(ss.storage.x, 4, "x value should be correct");
+ test.assertEqual(ss.storage.y, 5, "y value should be correct");
+ manager(loader).jsonStore.onWrite = function (storage) {
+ prefs.reset(QUOTA_PREF);
+ test.done();
+ };
+ loader.unload();
+ };
+ loader.unload();
+ });
+ // This will be JSON.stringify()ed to: {"a":1,"b":2,"c":3} (19 bytes)
+ ss.storage = { a: 1, b: 2, c: 3 };
+ manager(loader).jsonStore.write();
+};
+
+// Go over quota but don't handle it. The last good state should still persist.
+exports.testQuotaExceededNoHandle = function (test) {
+ test.waitUntilDone();
+ prefs.set(QUOTA_PREF, 5);
+
+ let loader = Loader(module);
+ let ss = loader.require("simple-storage");
+
+ manager(loader).jsonStore.onWrite = function (storage) {
+ loader = Loader(module);
+ ss = loader.require("simple-storage");
+ test.assertEqual(ss.storage, val,
+ "Value should have persisted: " + ss.storage);
+ ss.storage = "some very long string that is very long";
+ ss.on("OverQuota", function () {
+ test.pass("OverQuota emitted as expected");
+ manager(loader).jsonStore.onWrite = function () {
+ test.fail("Over-quota value should not have been written");
+ };
+ loader.unload();
+
+ loader = Loader(module);
+ ss = loader.require("simple-storage");
+ test.assertEqual(ss.storage, val,
+ "Over-quota value should not have been written, " +
+ "old value should have persisted: " + ss.storage);
+ loader.unload();
+ prefs.reset(QUOTA_PREF);
+ test.done();
+ });
+ manager(loader).jsonStore.write();
+ };
+
+ let val = "foo";
+ ss.storage = val;
+ loader.unload();
+};
+
+exports.testQuotaUsage = function (test) {
+ test.waitUntilDone();
+
+ let quota = 21;
+ prefs.set(QUOTA_PREF, quota);
+
+ let loader = Loader(module);
+ let ss = loader.require("simple-storage");
+
+ // {"a":1} (7 bytes)
+ ss.storage = { a: 1 };
+ test.assertEqual(ss.quotaUsage, 7 / quota, "quotaUsage should be correct");
+
+ // {"a":1,"bb":2} (14 bytes)
+ ss.storage = { a: 1, bb: 2 };
+ test.assertEqual(ss.quotaUsage, 14 / quota, "quotaUsage should be correct");
+
+ // {"a":1,"bb":2,"cc":3} (21 bytes)
+ ss.storage = { a: 1, bb: 2, cc: 3 };
+ test.assertEqual(ss.quotaUsage, 21 / quota, "quotaUsage should be correct");
+
+ manager(loader).jsonStore.onWrite = function () {
+ prefs.reset(QUOTA_PREF);
+ test.done();
+ };
+ loader.unload();
+};
+
+exports.testUninstall = function (test) {
+ test.waitUntilDone();
+ let loader = Loader(module);
+ let ss = loader.require("simple-storage");
+ manager(loader).jsonStore.onWrite = function () {
+ test.assert(file.exists(storeFilename), "Store file should exist");
+
+ loader = Loader(module);
+ ss = loader.require("simple-storage");
+ loader.unload("uninstall");
+ test.assert(!file.exists(storeFilename), "Store file should be removed");
+ test.done();
+ };
+ ss.storage.foo = "foo";
+ loader.unload();
+};
+
+exports.testSetNoSetRead = function (test) {
+ test.waitUntilDone();
+
+ // Load the module, set a value.
+ let loader = Loader(module);
+ let ss = loader.require("simple-storage");
+ manager(loader).jsonStore.onWrite = function (storage) {
+ test.assert(file.exists(storeFilename), "Store file should exist");
+
+ // Load the module again but don't access ss.storage.
+ loader = Loader(module);
+ ss = loader.require("simple-storage");
+ manager(loader).jsonStore.onWrite = function (storage) {
+ test.fail("Nothing should be written since `storage` was not accessed.");
+ };
+ loader.unload();
+
+ // Load the module a third time and make sure the value stuck.
+ loader = Loader(module);
+ ss = loader.require("simple-storage");
+ manager(loader).jsonStore.onWrite = function (storage) {
+ file.remove(storeFilename);
+ test.done();
+ };
+ test.assertEqual(ss.storage.foo, val, "Value should persist");
+ loader.unload();
+ };
+ let val = "foo";
+ ss.storage.foo = val;
+ test.assertEqual(ss.storage.foo, val, "Value read should be value set");
+ loader.unload();
+};
+
+
+function setGetRoot(test, val, compare) {
+ test.waitUntilDone();
+
+ compare = compare || function (a, b) a === b;
+
+ // Load the module once, set a value.
+ let loader = Loader(module);
+ let ss = loader.require("simple-storage");
+ manager(loader).jsonStore.onWrite = function () {
+ test.assert(file.exists(storeFilename), "Store file should exist");
+
+ // Load the module again and make sure the value stuck.
+ loader = Loader(module);
+ ss = loader.require("simple-storage");
+ manager(loader).jsonStore.onWrite = function () {
+ file.remove(storeFilename);
+ test.done();
+ };
+ test.assert(compare(ss.storage, val), "Value should persist");
+ loader.unload();
+ };
+ ss.storage = val;
+ test.assert(compare(ss.storage, val), "Value read should be value set");
+ loader.unload();
+}
+
+function setGetRootError(test, val, msg) {
+ let pred = "storage must be one of the following types: " +
+ "array, boolean, null, number, object, string";
+ let loader = Loader(module);
+ let ss = loader.require("simple-storage");
+ test.assertRaises(function () ss.storage = val, pred, msg);
+ loader.unload();
+}
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-tabs.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-tabs.js
new file mode 100644
index 0000000..5719ab4
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-tabs.js
@@ -0,0 +1,900 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+var {Cc,Ci} = require("chrome");
+const { Loader } = require("./helpers");
+
+// test tab.activeTab getter
+exports.testActiveTab_getter = function(test) {
+ test.waitUntilDone();
+
+ openBrowserWindow(function(window, browser) {
+ let tabs = require("tabs");
+
+ let url = "data:text/html,<html><head><title>foo</title></head></html>";
+ require("tab-browser").addTab(
+ url,
+ {
+ onLoad: function(e) {
+ test.assert(tabs.activeTab);
+ test.assertEqual(tabs.activeTab.url, url);
+ test.assertEqual(tabs.activeTab.title, "foo");
+ closeBrowserWindow(window, function() test.done());
+ }
+ }
+ );
+ });
+};
+
+// test 'BrowserWindow' instance creation on tab 'activate' event
+// See bug 648244: there was a infinite loop.
+exports.testBrowserWindowCreationOnActivate = function(test) {
+ test.waitUntilDone();
+
+ let windows = require("windows").browserWindows;
+ let tabs = require("tabs");
+
+ let gotActivate = false;
+
+ tabs.once('activate', function onActivate(eventTab) {
+ test.assert(windows.activeWindow, "Is able to fetch activeWindow");
+ gotActivate = true;
+ });
+
+ openBrowserWindow(function(window, browser) {
+ test.assert(gotActivate, "Received activate event before openBrowserWindow's callback is called");
+ closeBrowserWindow(window, function () test.done());
+ });
+}
+
+// test tab.activeTab setter
+exports.testActiveTab_setter = function(test) {
+ test.waitUntilDone();
+
+ openBrowserWindow(function(window, browser) {
+ let tabs = require("tabs");
+ let url = "data:text/html,<html><head><title>foo</title></head></html>";
+
+ tabs.on('ready', function onReady(tab) {
+ tabs.removeListener('ready', onReady);
+ test.assertEqual(tabs.activeTab.url, "about:blank", "activeTab url has not changed");
+ test.assertEqual(tab.url, url, "url of new background tab matches");
+ tabs.on('activate', function onActivate(eventTab) {
+ tabs.removeListener('activate', onActivate);
+ test.assertEqual(tabs.activeTab.url, url, "url after activeTab setter matches");
+ test.assertEqual(eventTab, tab, "event argument is the activated tab");
+ test.assertEqual(eventTab, tabs.activeTab, "the tab is the active one");
+ closeBrowserWindow(window, function() test.done());
+ });
+ tab.activate();
+ })
+
+ tabs.open({
+ url: url,
+ inBackground: true
+ });
+ });
+};
+
+exports.testAutomaticDestroy = function(test) {
+ test.waitUntilDone();
+
+ openBrowserWindow(function(window, browser) {
+ let tabs = require("tabs");
+
+ // Create a second tab instance that we will destroy
+ let called = false;
+
+ let loader = Loader(module);
+ let tabs2 = loader.require("tabs");
+ tabs2.on('open', function onOpen(tab) {
+ called = true;
+ });
+
+ loader.unload();
+
+ // Fire a tab event an ensure that this destroyed tab is inactive
+ tabs.once('open', function () {
+ require("timer").setTimeout(function () {
+ test.assert(!called, "Unloaded tab module is destroyed and inactive");
+ closeBrowserWindow(window, function() test.done());
+ }, 0);
+ });
+
+ tabs.open("data:text/html,foo");
+
+ });
+};
+
+// test tab properties
+exports.testTabProperties = function(test) {
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ let tabs= require("tabs");
+ let url = "data:text/html,<html><head><title>foo</title></head><body>foo</body></html>";
+ tabs.open({
+ url: url,
+ onReady: function(tab) {
+ test.assertEqual(tab.title, "foo", "title of the new tab matches");
+ test.assertEqual(tab.url, url, "URL of the new tab matches");
+ test.assert(tab.favicon, "favicon of the new tab is not empty");
+ test.assertEqual(tab.style, null, "style of the new tab matches");
+ test.assertEqual(tab.index, 1, "index of the new tab matches");
+ test.assertNotEqual(tab.getThumbnail(), null, "thumbnail of the new tab matches");
+ closeBrowserWindow(window, function() test.done());
+ }
+ });
+ });
+};
+
+// test tabs iterator and length property
+exports.testTabsIteratorAndLength = function(test) {
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ let tabs = require("tabs");
+ let startCount = 0;
+ for each (let t in tabs) startCount++;
+ test.assertEqual(startCount, tabs.length, "length property is correct");
+ let url = "data:text/html,default";
+ tabs.open(url);
+ tabs.open(url);
+ tabs.open({
+ url: url,
+ onOpen: function(tab) {
+ let count = 0;
+ for each (let t in tabs) count++;
+ test.assertEqual(count, startCount + 3, "iterated tab count matches");
+ test.assertEqual(startCount + 3, tabs.length, "iterated tab count matches length property");
+ closeBrowserWindow(window, function() test.done());
+ }
+ });
+ });
+};
+
+// test tab.url setter
+exports.testTabLocation = function(test) {
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ let tabs = require("tabs");
+ let url1 = "data:text/html,foo";
+ let url2 = "data:text/html,bar";
+
+ tabs.on('ready', function onReady(tab) {
+ if (tab.url != url2)
+ return;
+ tabs.removeListener('ready', onReady);
+ test.pass("tab.load() loaded the correct url");
+ closeBrowserWindow(window, function() test.done());
+ });
+
+ tabs.open({
+ url: url1,
+ onOpen: function(tab) {
+ tab.url = url2
+ }
+ });
+ });
+};
+
+// test tab.close()
+exports.testTabClose = function(test) {
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ let tabs = require("tabs");
+ let url = "data:text/html,foo";
+
+ test.assertNotEqual(tabs.activeTab.url, url, "tab is now the active tab");
+ tabs.on('ready', function onReady(tab) {
+ tabs.removeListener('ready', onReady);
+ test.assertEqual(tabs.activeTab.url, tab.url, "tab is now the active tab");
+ tab.close(function() {
+ closeBrowserWindow(window, function() test.done());
+ });
+ test.assertNotEqual(tabs.activeTab.url, url, "tab is no longer the active tab");
+ });
+
+ tabs.open(url);
+ });
+};
+
+// test tab.reload()
+exports.testTabReload = function(test) {
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ let tabs = require("tabs");
+ let url = "data:text/html,<!doctype%20html><title></title>";
+
+ tabs.open({ url: url, onReady: function onReady(tab) {
+ tab.removeListener("ready", onReady);
+
+ browser.addEventListener(
+ "load",
+ function onLoad() {
+ browser.removeEventListener("load", onLoad, true);
+
+ browser.addEventListener(
+ "load",
+ function onReload() {
+ browser.removeEventListener("load", onReload, true);
+ test.pass("the tab was loaded again");
+ test.assertEqual(tab.url, url, "the tab has the same URL");
+ closeBrowserWindow(window, function() test.done());
+ },
+ true
+ );
+ tab.reload();
+ },
+ true
+ );
+ }});
+ });
+};
+
+// test tab.move()
+exports.testTabMove = function(test) {
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ let tabs = require("tabs");
+ let url = "data:text/html,foo";
+
+ tabs.open({
+ url: url,
+ onOpen: function(tab) {
+ test.assertEqual(tab.index, 1, "tab index before move matches");
+ tab.index = 0;
+ test.assertEqual(tab.index, 0, "tab index after move matches");
+ closeBrowserWindow(window, function() test.done());
+ }
+ });
+ });
+};
+
+// open tab with default options
+exports.testOpen = function(test) {
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ let tabs = require("tabs");
+ let url = "data:text/html,default";
+ tabs.open({
+ url: url,
+ onReady: function(tab) {
+ test.assertEqual(tab.url, url, "URL of the new tab matches");
+ test.assertEqual(window.content.location, url, "URL of active tab in the current window matches");
+ closeBrowserWindow(window, function() test.done());
+ }
+ });
+ });
+};
+
+// open pinned tab
+exports.testOpenPinned = function(test) {
+ const xulApp = require("xul-app");
+ if (xulApp.versionInRange(xulApp.platformVersion, "2.0b2", "*")) {
+ // test tab pinning
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ let tabs = require("tabs");
+ let url = "data:text/html,default";
+ tabs.open({
+ url: url,
+ isPinned: true,
+ onOpen: function(tab) {
+ test.assertEqual(tab.isPinned, true, "The new tab is pinned");
+ closeBrowserWindow(window, function() test.done());
+ }
+ });
+ });
+ }
+ else {
+ test.pass("Pinned tabs are not supported in this application.");
+ }
+};
+
+// pin/unpin opened tab
+exports.testPinUnpin = function(test) {
+ const xulApp = require("xul-app");
+ if (xulApp.versionInRange(xulApp.platformVersion, "2.0b2", "*")) {
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ let tabs = require("tabs");
+ let url = "data:text/html,default";
+ tabs.open({
+ url: url,
+ onOpen: function(tab) {
+ tab.pin();
+ test.assertEqual(tab.isPinned, true, "The tab was pinned correctly");
+ tab.unpin();
+ test.assertEqual(tab.isPinned, false, "The tab was unpinned correctly");
+ closeBrowserWindow(window, function() test.done());
+ }
+ });
+ });
+ }
+ else {
+ test.pass("Pinned tabs are not supported in this application.");
+ }
+};
+
+// open tab in background
+exports.testInBackground = function(test) {
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ let tabs = require("tabs");
+ let activeUrl = tabs.activeTab.url;
+ let url = "data:text/html,background";
+ test.assertEqual(activeWindow, window, "activeWindow matches this window");
+ tabs.on('ready', function onReady(tab) {
+ tabs.removeListener('ready', onReady);
+ test.assertEqual(tabs.activeTab.url, activeUrl, "URL of active tab has not changed");
+ test.assertEqual(tab.url, url, "URL of the new background tab matches");
+ test.assertEqual(activeWindow, window, "a new window was not opened");
+ test.assertNotEqual(tabs.activeTab.url, url, "URL of active tab is not the new URL");
+ closeBrowserWindow(window, function() test.done());
+ });
+ tabs.open({
+ url: url,
+ inBackground: true
+ });
+ });
+};
+
+// open tab in new window
+exports.testOpenInNewWindow = function(test) {
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ let tabs = require("tabs");
+
+ let cache = [];
+ let windowUtils = require("window-utils");
+ let wt = new windowUtils.WindowTracker({
+ onTrack: function(win) {
+ cache.push(win);
+ },
+ onUntrack: function(win) {
+ cache.splice(cache.indexOf(win), 1)
+ }
+ });
+ let startWindowCount = cache.length;
+
+ let url = "data:text/html,newwindow";
+ tabs.open({
+ url: url,
+ inNewWindow: true,
+ onReady: function(tab) {
+ let newWindow = cache[cache.length - 1];
+ test.assertEqual(cache.length, startWindowCount + 1, "a new window was opened");
+ test.assertEqual(activeWindow, newWindow, "new window is active");
+ test.assertEqual(tab.url, url, "URL of the new tab matches");
+ test.assertEqual(newWindow.content.location, url, "URL of new tab in new window matches");
+ test.assertEqual(tabs.activeTab.url, url, "URL of activeTab matches");
+ for (var i in cache) cache[i] = null;
+ wt.unload();
+ closeBrowserWindow(newWindow, function() {
+ closeBrowserWindow(window, function() test.done());
+ });
+ }
+ });
+ });
+};
+
+// onOpen event handler
+exports.testTabsEvent_onOpen = function(test) {
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ var tabs = require("tabs");
+ let url = "data:text/html,1";
+ let eventCount = 0;
+
+ // add listener via property assignment
+ function listener1(tab) {
+ eventCount++;
+ };
+ tabs.on('open', listener1);
+
+ // add listener via collection add
+ tabs.on('open', function listener2(tab) {
+ test.assertEqual(++eventCount, 2, "both listeners notified");
+ tabs.removeListener('open', listener1);
+ tabs.removeListener('open', listener2);
+ closeBrowserWindow(window, function() test.done());
+ });
+
+ tabs.open(url);
+ });
+};
+
+// onClose event handler
+exports.testTabsEvent_onClose = function(test) {
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ var tabs = require("tabs");
+ let url = "data:text/html,onclose";
+ let eventCount = 0;
+
+ // add listener via property assignment
+ function listener1(tab) {
+ eventCount++;
+ }
+ tabs.on('close', listener1);
+
+ // add listener via collection add
+ tabs.on('close', function listener2(tab) {
+ test.assertEqual(++eventCount, 2, "both listeners notified");
+ tabs.removeListener('close', listener1);
+ tabs.removeListener('close', listener2);
+ closeBrowserWindow(window, function() test.done());
+ });
+
+ tabs.on('ready', function onReady(tab) {
+ tabs.removeListener('ready', onReady);
+ tab.close();
+ });
+
+ tabs.open(url);
+ });
+};
+
+// onClose event handler when a window is closed
+exports.testTabsEvent_onCloseWindow = function(test) {
+ test.waitUntilDone();
+
+ openBrowserWindow(function(window, browser) {
+ var tabs = require("tabs");
+
+ let closeCount = 0, individualCloseCount = 0;
+ function listener() {
+ closeCount++;
+ }
+ tabs.on('close', listener);
+
+ // One tab is already open with the window
+ let openTabs = 1;
+ function testCasePossiblyLoaded() {
+ if (++openTabs == 4) {
+ beginCloseWindow();
+ }
+ }
+
+ tabs.open({
+ url: "data:text/html,tab2",
+ onOpen: function() testCasePossiblyLoaded(),
+ onClose: function() individualCloseCount++
+ });
+
+ tabs.open({
+ url: "data:text/html,tab3",
+ onOpen: function() testCasePossiblyLoaded(),
+ onClose: function() individualCloseCount++
+ });
+
+ tabs.open({
+ url: "data:text/html,tab4",
+ onOpen: function() testCasePossiblyLoaded(),
+ onClose: function() individualCloseCount++
+ });
+
+ function beginCloseWindow() {
+ closeBrowserWindow(window, function testFinished() {
+ tabs.removeListener("close", listener);
+
+ test.assertEqual(closeCount, 4, "Correct number of close events received");
+ test.assertEqual(individualCloseCount, 3,
+ "Each tab with an attached onClose listener received a close " +
+ "event when the window was closed");
+
+ test.done();
+ });
+ }
+
+ });
+}
+
+// onReady event handler
+exports.testTabsEvent_onReady = function(test) {
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ var tabs = require("tabs");
+ let url = "data:text/html,onready";
+ let eventCount = 0;
+
+ // add listener via property assignment
+ function listener1(tab) {
+ eventCount++;
+ };
+ tabs.on('ready', listener1);
+
+ // add listener via collection add
+ tabs.on('ready', function listener2(tab) {
+ test.assertEqual(++eventCount, 2, "both listeners notified");
+ tabs.removeListener('ready', listener1);
+ tabs.removeListener('ready', listener2);
+ closeBrowserWindow(window, function() test.done());
+ });
+
+ tabs.open(url);
+ });
+};
+
+// onActivate event handler
+exports.testTabsEvent_onActivate = function(test) {
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ var tabs = require("tabs");
+ let url = "data:text/html,onactivate";
+ let eventCount = 0;
+
+ // add listener via property assignment
+ function listener1(tab) {
+ eventCount++;
+ };
+ tabs.on('activate', listener1);
+
+ // add listener via collection add
+ tabs.on('activate', function listener2(tab) {
+ test.assertEqual(++eventCount, 2, "both listeners notified");
+ tabs.removeListener('activate', listener1);
+ tabs.removeListener('activate', listener2);
+ closeBrowserWindow(window, function() test.done());
+ });
+
+ tabs.open(url);
+ });
+};
+
+// onDeactivate event handler
+exports.testTabsEvent_onDeactivate = function(test) {
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ var tabs = require("tabs");
+ let url = "data:text/html,ondeactivate";
+ let eventCount = 0;
+
+ // add listener via property assignment
+ function listener1(tab) {
+ eventCount++;
+ };
+ tabs.on('deactivate', listener1);
+
+ // add listener via collection add
+ tabs.on('deactivate', function listener2(tab) {
+ test.assertEqual(++eventCount, 2, "both listeners notified");
+ tabs.removeListener('deactivate', listener1);
+ tabs.removeListener('deactivate', listener2);
+ closeBrowserWindow(window, function() test.done());
+ });
+
+ tabs.on('open', function onOpen(tab) {
+ tabs.removeListener('open', onOpen);
+ tabs.open("data:text/html,foo");
+ });
+
+ tabs.open(url);
+ });
+};
+
+exports.testTabsEvent_pinning = function(test) {
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ var tabs = require("tabs");
+ let url = "data:text/html,1";
+
+ tabs.on('open', function onOpen(tab) {
+ tabs.removeListener('open', onOpen);
+ tab.pin();
+ });
+
+ tabs.on('pinned', function onPinned(tab) {
+ tabs.removeListener('pinned', onPinned);
+ test.assert(tab.isPinned, "notified tab is pinned");
+ tab.unpin();
+ });
+
+ tabs.on('unpinned', function onUnpinned(tab) {
+ tabs.removeListener('unpinned', onUnpinned);
+ test.assert(!tab.isPinned, "notified tab is not pinned");
+ closeBrowserWindow(window, function() test.done());
+ });
+
+ tabs.open(url);
+ });
+};
+
+// per-tab event handlers
+exports.testPerTabEvents = function(test) {
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ var tabs = require("tabs");
+ let eventCount = 0;
+
+ tabs.open({
+ url: "data:text/html,foo",
+ onOpen: function(tab) {
+ // add listener via property assignment
+ function listener1() {
+ eventCount++;
+ };
+ tab.on('ready', listener1);
+
+ // add listener via collection add
+ tab.on('ready', function listener2() {
+ test.assertEqual(eventCount, 1, "both listeners notified");
+ tab.removeListener('ready', listener1);
+ tab.removeListener('ready', listener2);
+ closeBrowserWindow(window, function() test.done());
+ });
+ }
+ });
+ });
+};
+
+exports.testAttachOnOpen = function (test) {
+ // Take care that attach has to be called on tab ready and not on tab open.
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ let tabs = require("tabs");
+
+ tabs.open({
+ url: "data:text/html,foobar",
+ onOpen: function (tab) {
+ let worker = tab.attach({
+ contentScript: 'self.postMessage(document.location.href); ',
+ onMessage: function (msg) {
+ test.assertEqual(msg, "about:blank",
+ "Worker document url is about:blank on open");
+ worker.destroy();
+ closeBrowserWindow(window, function() test.done());
+ }
+ });
+ }
+ });
+
+ });
+}
+
+exports.testAttachOnMultipleDocuments = function (test) {
+ // Example of attach that process multiple tab documents
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ let tabs = require("tabs");
+ let firstLocation = "data:text/html,foobar";
+ let secondLocation = "data:text/html,bar";
+ let thirdLocation = "data:text/html,fox";
+ let onReadyCount = 0;
+ let worker1 = null;
+ let worker2 = null;
+ let detachEventCount = 0;
+ tabs.open({
+ url: firstLocation,
+ onReady: function (tab) {
+ onReadyCount++;
+ if (onReadyCount == 1) {
+ worker1 = tab.attach({
+ contentScript: 'self.on("message", ' +
+ ' function () self.postMessage(document.location.href)' +
+ ');',
+ onMessage: function (msg) {
+ test.assertEqual(msg, firstLocation,
+ "Worker url is equal to the 1st document");
+ tab.url = secondLocation;
+ },
+ onDetach: function () {
+ detachEventCount++;
+ test.pass("Got worker1 detach event");
+ test.assertRaises(function () {
+ worker1.postMessage("ex-1");
+ },
+ /The page has been destroyed/,
+ "postMessage throw because worker1 is destroyed");
+ checkEnd();
+ }
+ });
+ worker1.postMessage("new-doc-1");
+ }
+ else if (onReadyCount == 2) {
+
+ worker2 = tab.attach({
+ contentScript: 'self.on("message", ' +
+ ' function () self.postMessage(document.location.href)' +
+ ');',
+ onMessage: function (msg) {
+ test.assertEqual(msg, secondLocation,
+ "Worker url is equal to the 2nd document");
+ tab.url = thirdLocation;
+ },
+ onDetach: function () {
+ detachEventCount++;
+ test.pass("Got worker2 detach event");
+ test.assertRaises(function () {
+ worker2.postMessage("ex-2");
+ },
+ /The page has been destroyed/,
+ "postMessage throw because worker2 is destroyed");
+ checkEnd();
+ }
+ });
+ worker2.postMessage("new-doc-2");
+ }
+ else if (onReadyCount == 3) {
+
+ tab.close();
+
+ }
+
+ }
+ });
+
+ function checkEnd() {
+ if (detachEventCount != 2)
+ return;
+
+ test.pass("Got all detach events");
+
+ closeBrowserWindow(window, function() test.done());
+ }
+
+ });
+}
+
+
+exports.testAttachWrappers = function (test) {
+ // Check that content script has access to wrapped values by default
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ let tabs = require("tabs");
+ let document = "data:text/html,<script>var globalJSVar = true; " +
+ " document.getElementById = 3;</script>";
+ let count = 0;
+
+ tabs.open({
+ url: document,
+ onReady: function (tab) {
+ let worker = tab.attach({
+ contentScript: 'try {' +
+ ' self.postMessage(!("globalJSVar" in window));' +
+ ' self.postMessage(typeof window.globalJSVar == "undefined");' +
+ '} catch(e) {' +
+ ' self.postMessage(e.message);' +
+ '}',
+ onMessage: function (msg) {
+ test.assertEqual(msg, true, "Worker has wrapped objects ("+count+")");
+ if (count++ == 1)
+ closeBrowserWindow(window, function() test.done());
+ }
+ });
+ }
+ });
+
+ });
+}
+
+/*
+// We do not offer unwrapped access to DOM since bug 601295 landed
+// See 660780 to track progress of unwrap feature
+exports.testAttachUnwrapped = function (test) {
+ // Check that content script has access to unwrapped values through unsafeWindow
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ let tabs = require("tabs");
+ let document = "data:text/html,<script>var globalJSVar=true;</script>";
+ let count = 0;
+
+ tabs.open({
+ url: document,
+ onReady: function (tab) {
+ let worker = tab.attach({
+ contentScript: 'try {' +
+ ' self.postMessage(unsafeWindow.globalJSVar);' +
+ '} catch(e) {' +
+ ' self.postMessage(e.message);' +
+ '}',
+ onMessage: function (msg) {
+ test.assertEqual(msg, true, "Worker has access to javascript content globals ("+count+")");
+ closeBrowserWindow(window, function() test.done());
+ }
+ });
+ }
+ });
+
+ });
+}
+*/
+
+exports['test window focus changes active tab'] = function(test) {
+ test.waitUntilDone();
+ let win1 = openBrowserWindow(function() {
+ let win2 = openBrowserWindow(function() {
+ let tabs = require("tabs");
+ tabs.on("activate", function onActivate() {
+ tabs.removeListener("activate", onActivate);
+ test.pass("activate was called on windows focus change.");
+ closeBrowserWindow(win1, function() {
+ closeBrowserWindow(win2, function() { test.done(); });
+ });
+ });
+ win1.focus();
+ }, "data:text/html,test window focus changes active tab</br><h1>Window #2");
+ }, "data:text/html,test window focus changes active tab</br><h1>Window #1");
+};
+
+exports['test ready event on new window tab'] = function(test) {
+ test.waitUntilDone();
+ let uri = encodeURI("data:text/html,Waiting for ready event!");
+
+ require("tabs").on("ready", function onReady(tab) {
+ if (tab.url === uri) {
+ require("tabs").removeListener("ready", onReady);
+ test.pass("ready event was emitted");
+ closeBrowserWindow(window, function() {
+ test.done();
+ });
+ }
+ });
+
+ let window = openBrowserWindow(function(){}, uri);
+};
+/******************* helpers *********************/
+
+// Helper for getting the active window
+this.__defineGetter__("activeWindow", function activeWindow() {
+ return Cc["@mozilla.org/appshell/window-mediator;1"].
+ getService(Ci.nsIWindowMediator).
+ getMostRecentWindow("navigator:browser");
+});
+
+// Utility function to open a new browser window.
+function openBrowserWindow(callback, url) {
+ let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
+ getService(Ci.nsIWindowWatcher);
+ let urlString = Cc["@mozilla.org/supports-string;1"].
+ createInstance(Ci.nsISupportsString);
+ urlString.data = url;
+ let window = ww.openWindow(null, "chrome://browser/content/browser.xul",
+ "_blank", "chrome,all,dialog=no", urlString);
+
+ if (callback) {
+ window.addEventListener("load", function onLoad(event) {
+ if (event.target && event.target.defaultView == window) {
+ window.removeEventListener("load", onLoad, true);
+ let browsers = window.document.getElementsByTagName("tabbrowser");
+ try {
+ require("timer").setTimeout(function () {
+ callback(window, browsers[0]);
+ }, 10);
+ } catch (e) { console.exception(e); }
+ }
+ }, true);
+ }
+
+ return window;
+}
+
+// Helper for calling code at window close
+function closeBrowserWindow(window, callback) {
+ window.addEventListener("unload", function unload() {
+ window.removeEventListener("unload", unload, false);
+ callback();
+ }, false);
+ window.close();
+}
+
+// If the module doesn't support the app we're being run in, require() will
+// throw. In that case, remove all tests above from exports, and add one dummy
+// test that passes.
+try {
+ require("tabs");
+}
+catch (err) {
+ // This bug should be mentioned in the error message.
+ let bug = "https://bugzilla.mozilla.org/show_bug.cgi?id=560716";
+ if (err.message.indexOf(bug) < 0)
+ throw err;
+ for (let [prop, val] in Iterator(exports)) {
+ if (/^test/.test(prop) && typeof(val) === "function")
+ delete exports[prop];
+ }
+ exports.testAppNotSupported = function (test) {
+ test.pass("the tabs module does not support this application.");
+ };
+}
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-timers.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-timers.js
new file mode 100644
index 0000000..90b26bf
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-timers.js
@@ -0,0 +1,12 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+const timers = require("timers");
+
+exports.testTimeout = function (test) {
+ test.waitUntilDone();
+ timers.setTimeout(function () {
+ test.pass("timers.setTimeout works");
+ test.done();
+ }, 0);
+}
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-widget.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-widget.js
new file mode 100644
index 0000000..5d3475b
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-widget.js
@@ -0,0 +1,1010 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {Cc,Ci} = require("chrome");
+const { Loader } = require('./helpers');
+const widgets = require("widget");
+const url = require("url");
+const windowUtils = require("window-utils");
+const tabBrowser = require("tab-browser");
+
+exports.testConstructor = function(test) {
+ test.waitUntilDone(30000);
+
+ let browserWindow = windowUtils.activeBrowserWindow;
+ let doc = browserWindow.document;
+ let AddonsMgrListener = browserWindow.AddonsMgrListener;
+
+ function container() doc.getElementById("addon-bar");
+ function widgetCount() container() ? container().getElementsByTagName("toolbaritem").length : 0;
+ let widgetStartCount = widgetCount();
+ function widgetNode(index) container() ? container().getElementsByTagName("toolbaritem")[index] : null;
+
+ // Test basic construct/destroy
+ AddonsMgrListener.onInstalling();
+ let w = widgets.Widget({ id: "fooID", label: "foo", content: "bar" });
+ AddonsMgrListener.onInstalled();
+ test.assertEqual(widgetCount(), widgetStartCount + 1, "panel has correct number of child elements after widget construction");
+
+ // test widget height
+ test.assertEqual(widgetNode(0).firstChild.boxObject.height, 16, "widget has correct default height");
+
+ AddonsMgrListener.onUninstalling();
+ w.destroy();
+ AddonsMgrListener.onUninstalled();
+ w.destroy();
+ test.pass("Multiple destroys do not cause an error");
+ test.assertEqual(widgetCount(), widgetStartCount, "panel has correct number of child elements after destroy");
+
+ // Test automatic widget destroy on unload
+ let loader = Loader(module);
+ let widgetsFromLoader = loader.require("widget");
+ let widgetStartCount = widgetCount();
+ let w = widgetsFromLoader.Widget({ id: "fooID", label: "foo", content: "bar" });
+ test.assertEqual(widgetCount(), widgetStartCount + 1, "widget has been correctly added");
+ loader.unload();
+ test.assertEqual(widgetCount(), widgetStartCount, "widget has been destroyed on module unload");
+
+ // Test nothing
+ test.assertRaises(
+ function() widgets.Widget({}),
+ "The widget must have a non-empty label property.",
+ "throws on no properties");
+
+ // Test no label
+ test.assertRaises(
+ function() widgets.Widget({content: "foo"}),
+ "The widget must have a non-empty label property.",
+ "throws on no label");
+
+ // Test empty label
+ test.assertRaises(
+ function() widgets.Widget({label: "", content: "foo"}),
+ "The widget must have a non-empty label property.",
+ "throws on empty label");
+
+ // Test no content or image
+ test.assertRaises(
+ function() widgets.Widget({id: "fooID", label: "foo"}),
+ "No content or contentURL property found. Widgets must have one or the other.",
+ "throws on no content");
+
+ // Test empty content, no image
+ test.assertRaises(
+ function() widgets.Widget({id:"fooID", label: "foo", content: ""}),
+ "No content or contentURL property found. Widgets must have one or the other.",
+ "throws on empty content");
+
+ // Test empty image, no content
+ test.assertRaises(
+ function() widgets.Widget({id:"fooID", label: "foo", image: ""}),
+ "No content or contentURL property found. Widgets must have one or the other.",
+ "throws on empty content");
+
+ // Test empty content, empty image
+ test.assertRaises(
+ function() widgets.Widget({id:"fooID", label: "foo", content: "", image: ""}),
+ "No content or contentURL property found. Widgets must have one or the other.",
+ "throws on empty content");
+
+ // Test duplicated ID
+ let duplicateID = widgets.Widget({id: "foo", label: "foo", content: "bar"});
+ test.assertRaises(
+ function() widgets.Widget({id: "foo", label: "bar", content: "bar"}),
+ /This widget ID is already used:/,
+ "throws on duplicated id");
+ duplicateID.destroy();
+
+ // Test Bug 652527
+ test.assertRaises(
+ function() widgets.Widget({id: "", label: "bar", content: "bar"}),
+ /You have to specify a unique value for the id property of/,
+ "throws on falsey id");
+
+ // Test duplicate label, different ID
+ let w1 = widgets.Widget({id: "id1", label: "foo", content: "bar"});
+ let w2 = widgets.Widget({id: "id2", label: "foo", content: "bar"});
+ w1.destroy();
+ w2.destroy();
+
+ // Test position restore on create/destroy/create
+ // Create 3 ordered widgets
+ let w1 = widgets.Widget({id: "first", label:"first", content: "bar"});
+ let w2 = widgets.Widget({id: "second", label:"second", content: "bar"});
+ let w3 = widgets.Widget({id: "third", label:"third", content: "bar"});
+ // Remove the middle widget
+ test.assertEqual(widgetNode(1).getAttribute("label"), "second", "second widget is the second widget inserted");
+ w2.destroy();
+ test.assertEqual(widgetNode(1).getAttribute("label"), "third", "second widget is removed, so second widget is now the third one");
+ w2 = widgets.Widget({id: "second", label:"second", content: "bar"});
+ test.assertEqual(widgetNode(1).getAttribute("label"), "second", "second widget is created again, at the same location");
+ // Cleanup this testcase
+ AddonsMgrListener.onUninstalling();
+ w1.destroy();
+ w2.destroy();
+ w3.destroy();
+ AddonsMgrListener.onUninstalled();
+
+ // Test concurrent widget module instances on addon-bar hiding
+ let loader = Loader(module);
+ let anotherWidgetsInstance = loader.require("widget");
+ test.assert(container().collapsed, "UI is hidden when no widgets");
+ AddonsMgrListener.onInstalling();
+ let w1 = widgets.Widget({id: "foo", label: "foo", content: "bar"});
+ // Ideally we would let AddonsMgrListener display the addon bar
+ // But, for now, addon bar is immediatly displayed by sdk code
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=627484
+ test.assert(!container().collapsed, "UI is already visible when we just added the widget");
+ AddonsMgrListener.onInstalled();
+ test.assert(!container().collapsed, "UI become visible when we notify AddonsMgrListener about end of addon installation");
+ let w2 = anotherWidgetsInstance.Widget({id: "bar", label: "bar", content: "foo"});
+ test.assert(!container().collapsed, "UI still visible when we add a second widget");
+ AddonsMgrListener.onUninstalling();
+ w1.destroy();
+ AddonsMgrListener.onUninstalled();
+ test.assert(!container().collapsed, "UI still visible when we remove one of two widgets");
+ AddonsMgrListener.onUninstalling();
+ w2.destroy();
+ test.assert(!container().collapsed, "UI is still visible when we have removed all widget but still not called onUninstalled");
+ AddonsMgrListener.onUninstalled();
+ test.assert(container().collapsed, "UI is hidden when we have removed all widget and called onUninstalled");
+
+ // Helper for testing a single widget.
+ // Confirms proper addition and content setup.
+ function testSingleWidget(widgetOptions) {
+ // We have to display which test is being run, because here we do not
+ // use the regular test framework but rather a custom one that iterates
+ // the `tests` array.
+ console.info("executing: " + widgetOptions.id);
+
+ let startCount = widgetCount();
+ let widget = widgets.Widget(widgetOptions);
+ let node = widgetNode(startCount);
+ test.assert(node, "widget node at index");
+ test.assertEqual(node.tagName, "toolbaritem", "widget element is correct");
+ test.assertEqual(widget.width + "px", node.style.minWidth, "widget width is correct");
+ test.assertEqual(widgetCount(), startCount + 1, "container has correct number of child elements");
+ let content = node.firstElementChild;
+ test.assert(content, "found content");
+ test.assertMatches(content.tagName, /iframe|image/, "content is iframe or image");
+ return widget;
+ }
+
+ // Array of widgets to test
+ // and a function to test them.
+ let tests = [];
+ function nextTest() {
+ test.assertEqual(widgetCount(), 0, "widget in last test property cleaned itself up");
+ if (!tests.length)
+ test.done();
+ else
+ require("timer").setTimeout(tests.shift(), 0);
+ }
+ function doneTest() nextTest();
+
+ // text widget
+ tests.push(function testTextWidget() testSingleWidget({
+ id: "text",
+ label: "text widget",
+ content: "oh yeah",
+ contentScript: "self.postMessage(document.body.innerHTML);",
+ contentScriptWhen: "end",
+ onMessage: function (message) {
+ test.assertEqual(this.content, message, "content matches");
+ this.destroy();
+ doneTest();
+ }
+ }));
+
+ // html widget
+ tests.push(function testHTMLWidget() testSingleWidget({
+ id: "html",
+ label: "html widget",
+ content: "<div>oh yeah</div>",
+ contentScript: "self.postMessage(document.body.innerHTML);",
+ contentScriptWhen: "end",
+ onMessage: function (message) {
+ test.assertEqual(this.content, message, "content matches");
+ this.destroy();
+ doneTest();
+ }
+ }));
+
+ // image url widget
+ tests.push(function testImageURLWidget() testSingleWidget({
+ id: "image",
+ label: "image url widget",
+ contentURL: require("self").data.url("test.html"),
+ contentScript: "self.postMessage({title: document.title, " +
+ "tag: document.body.firstElementChild.tagName, " +
+ "content: document.body.firstElementChild.innerHTML});",
+ contentScriptWhen: "end",
+ onMessage: function (message) {
+ test.assertEqual(message.title, "foo", "title matches");
+ test.assertEqual(message.tag, "P", "element matches");
+ test.assertEqual(message.content, "bar", "element content matches");
+ this.destroy();
+ doneTest();
+ }
+ }));
+
+ // web uri widget
+ tests.push(function testWebURIWidget() testSingleWidget({
+ id: "web",
+ label: "web uri widget",
+ contentURL: require("self").data.url("test.html"),
+ contentScript: "self.postMessage({title: document.title, " +
+ "tag: document.body.firstElementChild.tagName, " +
+ "content: document.body.firstElementChild.innerHTML});",
+ contentScriptWhen: "end",
+ onMessage: function (message) {
+ test.assertEqual(message.title, "foo", "title matches");
+ test.assertEqual(message.tag, "P", "element matches");
+ test.assertEqual(message.content, "bar", "element content matches");
+ this.destroy();
+ doneTest();
+ }
+ }));
+
+ // event: onclick + content
+ tests.push(function testOnclickEventContent() testSingleWidget({
+ id: "click",
+ label: "click test widget - content",
+ content: "<div id='me'>foo</div>",
+ contentScript: "var evt = document.createEvent('HTMLEvents'); " +
+ "evt.initEvent('click', true, true ); " +
+ "document.getElementById('me').dispatchEvent(evt);",
+ contentScriptWhen: "end",
+ onClick: function() {
+ test.pass("onClick called");
+ this.destroy();
+ doneTest();
+ }
+ }));
+
+ // event: onmouseover + content
+ tests.push(function testOnmouseoverEventContent() testSingleWidget({
+ id: "mouseover",
+ label: "mouseover test widget - content",
+ content: "<div id='me'>foo</div>",
+ contentScript: "var evt = document.createEvent('HTMLEvents'); " +
+ "evt.initEvent('mouseover', true, true ); " +
+ "document.getElementById('me').dispatchEvent(evt);",
+ contentScriptWhen: "end",
+ onMouseover: function() {
+ test.pass("onMouseover called");
+ this.destroy();
+ doneTest();
+ }
+ }));
+
+ // event: onmouseout + content
+ tests.push(function testOnmouseoutEventContent() testSingleWidget({
+ id: "mouseout",
+ label: "mouseout test widget - content",
+ content: "<div id='me'>foo</div>",
+ contentScript: "var evt = document.createEvent('HTMLEvents'); " +
+ "evt.initEvent('mouseout', true, true ); " +
+ "document.getElementById('me').dispatchEvent(evt);",
+ contentScriptWhen: "end",
+ onMouseout: function() {
+ test.pass("onMouseout called");
+ this.destroy();
+ doneTest();
+ }
+ }));
+
+ // event: onclick + image
+ tests.push(function testOnclickEventImage() testSingleWidget({
+ id: "click",
+ label: "click test widget - image",
+ contentURL: require("self").data.url("moz_favicon.ico"),
+ contentScript: "var evt = document.createEvent('HTMLEvents'); " +
+ "evt.initEvent('click', true, true ); " +
+ "document.body.firstElementChild.dispatchEvent(evt);",
+ contentScriptWhen: "end",
+ onClick: function() {
+ test.pass("onClick called");
+ this.destroy();
+ doneTest();
+ }
+ }));
+
+ // event: onmouseover + image
+ tests.push(function testOnmouseoverEventImage() testSingleWidget({
+ id: "mouseover",
+ label: "mouseover test widget - image",
+ contentURL: require("self").data.url("moz_favicon.ico"),
+ contentScript: "var evt = document.createEvent('HTMLEvents'); " +
+ "evt.initEvent('mouseover', true, true ); " +
+ "document.body.firstElementChild.dispatchEvent(evt);",
+ contentScriptWhen: "end",
+ onMouseover: function() {
+ test.pass("onMouseover called");
+ this.destroy();
+ doneTest();
+ }
+ }));
+
+ // event: onmouseout + image
+ tests.push(function testOnmouseoutEventImage() testSingleWidget({
+ id: "mouseout",
+ label: "mouseout test widget - image",
+ contentURL: require("self").data.url("moz_favicon.ico"),
+ contentScript: "var evt = document.createEvent('HTMLEvents'); " +
+ "evt.initEvent('mouseout', true, true ); " +
+ "document.body.firstElementChild.dispatchEvent(evt);",
+ contentScriptWhen: "end",
+ onMouseout: function() {
+ test.pass("onMouseout called");
+ this.destroy();
+ doneTest();
+ }
+ }));
+
+ // test multiple widgets
+ tests.push(function testMultipleWidgets() {
+ let w1 = widgets.Widget({id: "first", label: "first widget", content: "first content"});
+ let w2 = widgets.Widget({id: "second", label: "second widget", content: "second content"});
+
+ w1.destroy();
+ w2.destroy();
+
+ doneTest();
+ });
+
+ // test updating widget content
+ let loads = 0;
+ tests.push(function testUpdatingWidgetContent() testSingleWidget({
+ id: "content",
+ label: "content update test widget",
+ content: "<div id='me'>foo</div>",
+ contentScript: "self.postMessage(1)",
+ contentScriptWhen: "ready",
+ onMessage: function(message) {
+ if (!this.flag) {
+ this.content = "<div id='me'>bar</div>";
+ this.flag = 1;
+ }
+ else {
+ test.assertEqual(this.content, "<div id='me'>bar</div>");
+ this.destroy();
+ doneTest();
+ }
+ }
+ }));
+
+ // test updating widget contentURL
+ let url1 = "data:text/html,<body>foodle</body>";
+ let url2 = "data:text/html,<body>nistel</body>";
+
+ tests.push(function testUpdatingContentURL() testSingleWidget({
+ id: "content",
+ label: "content update test widget",
+ contentURL: url1,
+ contentScript: "self.postMessage(document.location.href);",
+ contentScriptWhen: "end",
+ onMessage: function(message) {
+ if (!this.flag) {
+ test.assertEqual(this.contentURL.toString(), url1);
+ test.assertEqual(message, url1);
+ this.contentURL = url2;
+ this.flag = 1;
+ }
+ else {
+ test.assertEqual(this.contentURL.toString(), url2);
+ test.assertEqual(message, url2);
+ this.destroy();
+ doneTest();
+ }
+ }
+ }));
+
+ // test tooltip
+ tests.push(function testTooltip() testSingleWidget({
+ id: "text",
+ label: "text widget",
+ content: "oh yeah",
+ tooltip: "foo",
+ contentScript: "self.postMessage(1)",
+ contentScriptWhen: "ready",
+ onMessage: function(message) {
+ test.assertEqual(this.tooltip, "foo", "tooltip matches");
+ this.destroy();
+ doneTest();
+ }
+ }));
+
+ // test tooltip fallback to label
+ tests.push(function testTooltipFallback() testSingleWidget({
+ id: "fallback",
+ label: "fallback",
+ content: "oh yeah",
+ contentScript: "self.postMessage(1)",
+ contentScriptWhen: "ready",
+ onMessage: function(message) {
+ test.assertEqual(this.tooltip, this.label, "tooltip fallbacks to label");
+ this.destroy();
+ doneTest();
+ }
+ }));
+
+ // test updating widget tooltip
+ let updated = false;
+ tests.push(function testUpdatingTooltip() testSingleWidget({
+ id: "tooltip",
+ label: "tooltip update test widget",
+ tooltip: "foo",
+ content: "<div id='me'>foo</div>",
+ contentScript: "self.postMessage(1)",
+ contentScriptWhen: "ready",
+ onMessage: function(message) {
+ this.tooltip = "bar";
+ test.assertEqual(this.tooltip, "bar", "tooltip gets updated");
+ this.destroy();
+ doneTest();
+ }
+ }));
+
+ // test allow attribute
+ tests.push(function testDefaultAllow() testSingleWidget({
+ id: "allow",
+ label: "allow.script attribute",
+ content: "<script>document.title = 'ok';</script>",
+ contentScript: "self.postMessage(document.title)",
+ onMessage: function(message) {
+ test.assertEqual(message, "ok", "scripts are evaluated by default");
+ this.destroy();
+ doneTest();
+ }
+ }));
+
+ tests.push(function testExplicitAllow() testSingleWidget({
+ id: "allow",
+ label: "allow.script attribute",
+ allow: {script: true},
+ content: "<script>document.title = 'ok';</script>",
+ contentScript: "self.postMessage(document.title)",
+ onMessage: function(message) {
+ test.assertEqual(message, "ok", "scripts are evaluated when we want to");
+ this.destroy();
+ doneTest();
+ }
+ }));
+
+ tests.push(function testExplicitDisallow() testSingleWidget({
+ id: "allow",
+ label: "allow.script attribute",
+ content: "<script>document.title = 'ok';</script>",
+ allow: {script: false},
+ contentScript: "self.postMessage(document.title)",
+ onMessage: function(message) {
+ test.assertNotEqual(message, "ok", "scripts aren't evaluated when " +
+ "explicitly blocked it");
+ this.destroy();
+ doneTest();
+ }
+ }));
+
+ // test multiple windows
+ tests.push(function testMultipleWindows() {
+ tabBrowser.addTab("about:blank", { inNewWindow: true, onLoad: function(e) {
+ let browserWindow = e.target.defaultView;
+ let doc = browserWindow.document;
+ function container() doc.getElementById("addon-bar");
+ function widgetCount2() container() ? container().childNodes.length : 0;
+ let widgetStartCount2 = widgetCount2();
+
+ let w1Opts = {id:"first", label: "first widget", content: "first content"};
+ let w1 = testSingleWidget(w1Opts);
+ test.assertEqual(widgetCount2(), widgetStartCount2 + 1, "2nd window has correct number of child elements after first widget");
+
+ let w2Opts = {id:"second", label: "second widget", content: "second content"};
+ let w2 = testSingleWidget(w2Opts);
+ test.assertEqual(widgetCount2(), widgetStartCount2 + 2, "2nd window has correct number of child elements after second widget");
+
+ w1.destroy();
+ test.assertEqual(widgetCount2(), widgetStartCount2 + 1, "2nd window has correct number of child elements after first destroy");
+ w2.destroy();
+ test.assertEqual(widgetCount2(), widgetStartCount2, "2nd window has correct number of child elements after second destroy");
+
+ closeBrowserWindow(browserWindow, function() {
+ doneTest();
+ });
+ }});
+ });
+
+ // test window closing
+ tests.push(function testWindowClosing() {
+ // 1/ Create a new widget
+ let w1Opts = {
+ id:"first",
+ label: "first widget",
+ content: "first content",
+ contentScript: "self.port.on('event', function () self.port.emit('event'))"
+ };
+ let widget = testSingleWidget(w1Opts);
+ let windows = require("windows").browserWindows;
+
+ // 2/ Retrieve a WidgetView for the initial browser window
+ let acceptDetach = false;
+ let mainView = widget.getView(windows.activeWindow);
+ test.assert(mainView, "Got first widget view");
+ mainView.on("detach", function () {
+ // 8/ End of our test. Accept detach event only when it occurs after
+ // widget.destroy()
+ if (acceptDetach)
+ doneTest();
+ else
+ test.fail("View on initial window should not be destroyed");
+ });
+ mainView.port.on("event", function () {
+ // 7/ Receive event sent during 6/ and cleanup our test
+ acceptDetach = true;
+ widget.destroy();
+ });
+
+ // 3/ First: open a new browser window
+ windows.open({
+ url: "about:blank",
+ onOpen: function(window) {
+ // 4/ Retrieve a WidgetView for this new window
+ let view = widget.getView(window);
+ test.assert(view, "Got second widget view");
+ view.port.on("event", function () {
+ test.fail("We should not receive event on the detach view");
+ });
+ view.on("detach", function () {
+ // The related view is destroyed
+ // 6/ Send a custom event
+ test.assertRaises(function () {
+ view.port.emit("event");
+ },
+ /The widget has been destroyed and can no longer be used./,
+ "emit on a destroyed view should throw");
+ widget.port.emit("event");
+ });
+
+ // 5/ Destroy this window
+ window.close();
+ }
+ });
+ });
+
+ tests.push(function testAddonBarHide() {
+ // Hide the addon-bar
+ browserWindow.setToolbarVisibility(container(), false);
+
+ // Then open a browser window and verify that the addon-bar remains hidden
+ tabBrowser.addTab("about:blank", { inNewWindow: true, onLoad: function(e) {
+ let browserWindow = e.target.defaultView;
+ let doc = browserWindow.document;
+ function container2() doc.getElementById("addon-bar");
+ function widgetCount2() container2() ? container2().childNodes.length : 0;
+ let widgetStartCount2 = widgetCount2();
+
+ let w1Opts = {id:"first", label: "first widget", content: "first content"};
+ let w1 = testSingleWidget(w1Opts);
+ test.assertEqual(widgetCount2(), widgetStartCount2 + 1, "2nd window has correct number of child elements after widget creation");
+
+ w1.destroy();
+ test.assertEqual(widgetCount2(), widgetStartCount2, "2nd window has correct number of child elements after widget destroy");
+
+ test.assert(container().collapsed, "1st window has an hidden addon-bar");
+ test.assert(container2().collapsed, "2nd window has an hidden addon-bar");
+
+ browserWindow.setToolbarVisibility(container(), true);
+
+ closeBrowserWindow(browserWindow, function() {
+ doneTest();
+ });
+ }});
+ });
+
+ // test widget.width
+ tests.push(function testWidgetWidth() testSingleWidget({
+ id: "text",
+ label: "test widget.width",
+ content: "test width",
+ width: 200,
+ contentScript: "self.postMessage(1)",
+ contentScriptWhen: "ready",
+ onMessage: function(message) {
+ test.assertEqual(this.width, 200);
+
+ let node = widgetNode(0);
+ test.assertEqual(this.width, node.style.minWidth.replace("px", ""));
+ test.assertEqual(this.width, node.firstElementChild.style.width.replace("px", ""));
+ this.width = 300;
+ test.assertEqual(this.width, node.style.minWidth.replace("px", ""));
+ test.assertEqual(this.width, node.firstElementChild.style.width.replace("px", ""));
+
+ this.destroy();
+ doneTest();
+ }
+ }));
+
+ // test click handler not respond to right-click
+ let clickCount = 0;
+ tests.push(function testNoRightClick() testSingleWidget({
+ id: "click-content",
+ label: "click test widget - content",
+ content: "<div id='me'>foo</div>",
+ contentScript: "var evt = document.createEvent('MouseEvents'); " +
+ "evt.initMouseEvent('click', true, true, window, " +
+ " 0, 0, 0, 0, 0, false, false, false, false, 2, null); " +
+ "document.getElementById('me').dispatchEvent(evt); " +
+ "evt = document.createEvent('HTMLEvents'); " +
+ "evt.initEvent('click', true, true ); " +
+ "document.getElementById('me').dispatchEvent(evt); " +
+ "evt = document.createEvent('HTMLEvents'); " +
+ "evt.initEvent('mouseover', true, true ); " +
+ "document.getElementById('me').dispatchEvent(evt);",
+ contentScriptWhen: "end",
+ onClick: function() clickCount++,
+ onMouseover: function() {
+ test.assertEqual(clickCount, 1, "right click wasn't sent to click handler");
+ this.destroy();
+ doneTest();
+ }
+ }));
+
+ // kick off test execution
+ doneTest();
+};
+
+exports.testPanelWidget1 = function testPanelWidget1(test) {
+ const widgets = require("widget");
+
+ let widget1 = widgets.Widget({
+ id: "panel1",
+ label: "panel widget 1",
+ content: "<div id='me'>foo</div>",
+ contentScript: "var evt = document.createEvent('HTMLEvents'); " +
+ "evt.initEvent('click', true, true ); " +
+ "document.body.dispatchEvent(evt);",
+ contentScriptWhen: "end",
+ panel: require("panel").Panel({
+ contentURL: "data:text/html,<body>Look ma, a panel!</body>",
+ onShow: function() {
+ widget1.destroy();
+ test.pass("panel displayed on click");
+ test.done();
+ }
+ })
+ });
+ test.waitUntilDone();
+};
+
+exports.testPanelWidget2 = function testPanelWidget2(test) {
+ const widgets = require("widget");
+ test.assertRaises(
+ function() {
+ widgets.Widget({
+ id: "panel2",
+ label: "panel widget 2",
+ panel: {}
+ });
+ },
+ "The option \"panel\" must be one of the following types: null, undefined, object",
+ "widget.panel must be a Panel object"
+ );
+};
+
+exports.testPanelWidget3 = function testPanelWidget3(test) {
+ const widgets = require("widget");
+ let onClickCalled = false;
+ let widget3 = widgets.Widget({
+ id: "panel3",
+ label: "panel widget 3",
+ content: "<div id='me'>foo</div>",
+ contentScript: "var evt = document.createEvent('HTMLEvents'); " +
+ "evt.initEvent('click', true, true ); " +
+ "document.body.firstElementChild.dispatchEvent(evt);",
+ contentScriptWhen: "end",
+ onClick: function() {
+ onClickCalled = true;
+ this.panel.show();
+ },
+ panel: require("panel").Panel({
+ contentURL: "data:text/html,<body>Look ma, a panel!</body>",
+ onShow: function() {
+ test.assert(
+ onClickCalled,
+ "onClick called on click for widget with both panel and onClick"
+ );
+ widget3.destroy();
+ test.done();
+ }
+ })
+ });
+ test.waitUntilDone();
+};
+
+exports.testWidgetMessaging = function testWidgetMessaging(test) {
+ test.waitUntilDone();
+ let origMessage = "foo";
+ const widgets = require("widget");
+ let widget = widgets.Widget({
+ id: "foo",
+ label: "foo",
+ content: "<bar>baz</bar>",
+ contentScriptWhen: "end",
+ contentScript: "self.on('message', function(data) { self.postMessage(data); }); self.postMessage('ready');",
+ onMessage: function(message) {
+ if (message == "ready")
+ widget.postMessage(origMessage);
+ else {
+ test.assertEqual(origMessage, message);
+ widget.destroy();
+ test.done();
+ }
+ }
+ });
+};
+
+exports.testWidgetViews = function testWidgetViews(test) {
+ test.waitUntilDone();
+ const widgets = require("widget");
+ let widget = widgets.Widget({
+ id: "foo",
+ label: "foo",
+ content: "<bar>baz</bar>",
+ contentScriptWhen: "ready",
+ contentScript: "self.on('message', function(data) self.postMessage(data)); self.postMessage('ready')",
+ onAttach: function(view) {
+ test.pass("WidgetView created");
+ view.on("message", function () {
+ test.pass("Got message in WidgetView");
+ widget.destroy();
+ });
+ view.on("detach", function () {
+ test.pass("WidgetView destroyed");
+ test.done();
+ });
+ }
+ });
+
+};
+
+exports.testWidgetViewsUIEvents = function testWidgetViewsUIEvents(test) {
+ test.waitUntilDone();
+ const widgets = require("widget");
+ let view = null;
+ let widget = widgets.Widget({
+ id: "foo",
+ label: "foo",
+ content: "<div id='me'>foo</div>",
+ contentScript: "var evt = document.createEvent('HTMLEvents'); " +
+ "evt.initEvent('click', true, true ); " +
+ "document.getElementById('me').dispatchEvent(evt);",
+ contentScriptWhen: "ready",
+ onAttach: function(attachView) {
+ view = attachView;
+ test.pass("Got attach event");
+ },
+ onClick: function (eventView) {
+ test.assertEqual(view, eventView,
+ "event first argument is equal to the WidgetView");
+ let view2 = widget.getView(require("windows").browserWindows.activeWindow);
+ test.assertEqual(view, view2,
+ "widget.getView return the same WidgetView");
+ widget.destroy();
+ test.done();
+ }
+ });
+};
+
+exports.testWidgetViewsCustomEvents = function testWidgetViewsCustomEvents(test) {
+ test.waitUntilDone();
+ const widgets = require("widget");
+ let widget = widgets.Widget({
+ id: "foo",
+ label: "foo",
+ content: "<div id='me'>foo</div>",
+ contentScript: "self.port.emit('event', 'ok');",
+ contentScriptWhen: "ready",
+ onAttach: function(view) {
+ view.port.on("event", function (data) {
+ test.assertEqual(data, "ok",
+ "event argument is valid on WidgetView");
+ });
+ },
+ });
+ widget.port.on("event", function (data) {
+ test.assertEqual(data, "ok",
+ "event argument is valid on Widget");
+ widget.destroy();
+ test.done();
+ });
+};
+
+exports.testWidgetViewsTooltip = function testWidgetViewsTooltip(test) {
+ test.waitUntilDone();
+ const widgets = require("widget");
+
+ let widget = new widgets.Widget({
+ id: "foo",
+ label: "foo",
+ content: "foo"
+ });
+ let view = widget.getView(require("windows").browserWindows.activeWindow);
+ widget.tooltip = null;
+ test.assertEqual(view.tooltip, "foo",
+ "view tooltip defaults to base widget label");
+ test.assertEqual(widget.tooltip, "foo",
+ "tooltip defaults to base widget label");
+ widget.destroy();
+ test.done();
+};
+
+exports.testWidgetMove = function testWidgetMove(test) {
+ test.waitUntilDone();
+
+ let windowUtils = require("window-utils");
+ let widgets = require("widget");
+
+ let browserWindow = windowUtils.activeBrowserWindow;
+ let doc = browserWindow.document;
+
+ let label = "unique-widget-label";
+ let origMessage = "message after node move";
+ let gotFirstReady = false;
+
+ let widget = widgets.Widget({
+ id: "foo",
+ label: label,
+ content: "<bar>baz</bar>",
+ contentScriptWhen: "ready",
+ contentScript: "self.on('message', function(data) { self.postMessage(data); }); self.postMessage('ready');",
+ onMessage: function(message) {
+ if (message == "ready") {
+ if (!gotFirstReady) {
+ test.pass("Got first ready event");
+ let widgetNode = doc.querySelector('toolbaritem[label="' + label + '"]');
+ let parent = widgetNode.parentNode;
+ parent.insertBefore(widgetNode, parent.firstChild);
+ gotFirstReady = true;
+ } else {
+ test.pass("Got second ready event");
+ widget.postMessage(origMessage);
+ }
+ }
+ else {
+ test.assertEqual(origMessage, message, "Got message after node move");
+ widget.destroy();
+ test.done();
+ }
+ }
+ });
+};
+
+/*
+The bug is exhibited when a widget with HTML content has it's content
+changed to new HTML content with a pound in it. Because the src of HTML
+content is converted to a data URI, the underlying iframe doesn't
+consider the content change a navigation change, so doesn't load
+the new content.
+*/
+exports.testWidgetWithPound = function testWidgetWithPound(test) {
+ test.waitUntilDone();
+
+ function getWidgetContent(widget) {
+ let windowUtils = require("window-utils");
+ let browserWindow = windowUtils.activeBrowserWindow;
+ let doc = browserWindow.document;
+ let widgetNode = doc.querySelector('toolbaritem[label="' + widget.label + '"]');
+ test.assert(widgetNode, 'found widget node in the front-end');
+ return widgetNode.firstChild.contentDocument.body.innerHTML;
+ }
+
+ let widgets = require("widget");
+ let count = 0;
+ let widget = widgets.Widget({
+ id: "1",
+ label: "foo",
+ content: "foo",
+ contentScript: "window.addEventListener('load', self.postMessage, false);",
+ onMessage: function() {
+ count++;
+ if (count == 1) {
+ widget.content = "foo#";
+ }
+ else {
+ test.assertEqual(getWidgetContent(widget), "foo#", "content updated to pound?");
+ widget.destroy();
+ test.done();
+ }
+ }
+ });
+};
+
+exports.testNavigationBarWidgets = function testNavigationBarWidgets(test) {
+ test.waitUntilDone();
+
+ let w1 = widgets.Widget({id: "1st", label: "1st widget", content: "1"});
+ let w2 = widgets.Widget({id: "2nd", label: "2nd widget", content: "2"});
+ let w3 = widgets.Widget({id: "3rd", label: "3rd widget", content: "3"});
+
+ // Hack to move 2nd and 3rd widgets manually to the navigation bar, in 5th
+ // position, i.e. after search box. 3rd widget will be in 5th and 2nd in 6th.
+ function getWidgetNode(toolbar, position) {
+ return toolbar.getElementsByTagName("toolbaritem")[position];
+ }
+ let browserWindow = windowUtils.activeBrowserWindow;
+ let doc = browserWindow.document;
+ let addonBar = doc.getElementById("addon-bar");
+ let w2Toolbaritem = getWidgetNode(addonBar, 1);
+ let w3ToolbarItem = getWidgetNode(addonBar, 2);
+ let navBar = doc.getElementById("nav-bar");
+ navBar.insertItem(w2Toolbaritem.id, navBar.childNodes[6], null, false);
+ navBar.insertItem(w3ToolbarItem.id, navBar.childNodes[6], null, false);
+ // Widget and Firefox codes rely on this `currentset` attribute,
+ // so ensure it is correctly saved
+ navBar.setAttribute("currentset", navBar.currentSet);
+ doc.persist(navBar.id, "currentset");
+ // Update addonbar too as we removed widget from there.
+ // Otherwise, widgets may still be added to this toolbar.
+ addonBar.setAttribute("currentset", addonBar.currentSet);
+ doc.persist(addonBar.id, "currentset");
+
+ tabBrowser.addTab("about:blank", { inNewWindow: true, onLoad: function(e) {
+ let browserWindow = e.target.defaultView;
+ let doc = browserWindow.document;
+ let navBar = doc.getElementById("nav-bar");
+ let addonBar = doc.getElementById("addon-bar");
+
+ // Ensure that 1st is in addon bar
+ test.assertEqual(getWidgetNode(addonBar, 0).getAttribute("label"), w1.label);
+ // And that 2nd and 3rd keep their original positions in navigation bar
+ test.assertEqual(navBar.childNodes[5].getAttribute("label"), w3.label);
+ test.assertEqual(navBar.childNodes[6].getAttribute("label"), w2.label);
+
+ w1.destroy();
+ w2.destroy();
+ w3.destroy();
+
+ closeBrowserWindow(browserWindow, function() {
+ test.done();
+ });
+ }});
+};
+
+/******************* helpers *********************/
+
+// Helper for calling code at window close
+function closeBrowserWindow(window, callback) {
+ require("timer").setTimeout(function() {
+ window.addEventListener("unload", function onUnload() {
+ window.removeEventListener("unload", onUnload, false);
+ callback();
+ }, false);
+ window.close();
+ }, 0);
+}
+
+// ADD NO TESTS BELOW THIS LINE! ///////////////////////////////////////////////
+
+// If the module doesn't support the app we're being run in, require() will
+// throw. In that case, remove all tests above from exports, and add one dummy
+// test that passes.
+try {
+ require("widget");
+}
+catch (err) {
+ // This bug should be mentioned in the error message.
+ let bug = "https://bugzilla.mozilla.org/show_bug.cgi?id=560716";
+ if (err.message.indexOf(bug) < 0)
+ throw err;
+ for (let [prop, val] in Iterator(exports)) {
+ if (/^test/.test(prop) && typeof(val) === "function")
+ delete exports[prop];
+ }
+ exports.testAppNotSupported = function (test) {
+ test.pass("widget does not support this application.");
+ };
+}
+
diff --git a/tools/addon-sdk-1.7/packages/addon-kit/tests/test-windows.js b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-windows.js
new file mode 100644
index 0000000..b85fec7
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/addon-kit/tests/test-windows.js
@@ -0,0 +1,309 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const {Cc, Ci} = require("chrome");
+const { setTimeout } = require("timer");
+const { Loader } = require('./helpers');
+const wm = Cc["@mozilla.org/appshell/window-mediator;1"].
+ getService(Ci.nsIWindowMediator);
+let browserWindows;
+
+function getTestRunnerWindow() wm.getMostRecentWindow("test:runner")
+
+exports.testOpenAndCloseWindow = function(test) {
+ test.waitUntilDone();
+
+ test.assertEqual(browserWindows.length, 1, "Only one window open");
+
+ browserWindows.open({
+ url: "data:text/html,<title>windows API test</title>",
+ onOpen: function(window) {
+ test.assertEqual(this, browserWindows,
+ "The 'this' object is the windows object.");
+ test.assertEqual(window.tabs.length, 1, "Only one tab open");
+ test.assertEqual(browserWindows.length, 2, "Two windows open");
+ window.tabs.activeTab.on('ready', function onReady(tab) {
+ tab.removeListener('ready', onReady);
+ test.assert(window.title.indexOf("windows API test") != -1,
+ "URL correctly loaded");
+ window.close();
+ });
+ },
+ onClose: function(window) {
+ test.assertEqual(window.tabs.length, 0, "Tabs were cleared");
+ test.assertEqual(browserWindows.length, 1, "Only one window open");
+ test.done();
+ }
+ });
+};
+
+exports.testAutomaticDestroy = function(test) {
+
+ test.waitUntilDone();
+ let windows = browserWindows;
+
+ // Create a second windows instance that we will unload
+ let called = false;
+ let loader = Loader(module);
+ let windows2 = loader.require("windows").browserWindows;
+ windows2.on("open", function() {
+ called = true;
+ });
+
+ loader.unload();
+
+ // Fire a windows event and check that this unloaded instance is inactive
+ windows.open({
+ url: "data:text/html,foo",
+ onOpen: function(window) {
+ setTimeout(function () {
+ test.assert(!called,
+ "Unloaded windows instance is destroyed and inactive");
+ window.close(function () {
+ test.done();
+ });
+ });
+ }
+ });
+
+};
+
+exports.testOnOpenOnCloseListeners = function(test) {
+ test.waitUntilDone();
+ let windows = browserWindows;
+
+ test.assertEqual(browserWindows.length, 1, "Only one window open");
+
+ let received = {
+ listener1: false,
+ listener2: false,
+ listener3: false,
+ listener4: false
+ }
+
+ function listener1() {
+ test.assertEqual(this, windows, "The 'this' object is the windows object.");
+ if (received.listener1)
+ test.fail("Event received twice");
+ received.listener1 = true;
+ }
+
+ function listener2() {
+ if (received.listener2)
+ test.fail("Event received twice");
+ received.listener2 = true;
+ }
+
+ function listener3() {
+ test.assertEqual(this, windows, "The 'this' object is the windows object.");
+ if (received.listener3)
+ test.fail("Event received twice");
+ received.listener3 = true;
+ }
+
+ function listener4() {
+ if (received.listener4)
+ test.fail("Event received twice");
+ received.listener4 = true;
+ }
+
+ windows.on('open', listener1);
+ windows.on('open', listener2);
+ windows.on('close', listener3);
+ windows.on('close', listener4);
+
+ function verify() {
+ test.assert(received.listener1, "onOpen handler called");
+ test.assert(received.listener2, "onOpen handler called");
+ test.assert(received.listener3, "onClose handler called");
+ test.assert(received.listener4, "onClose handler called");
+
+ windows.removeListener('open', listener1);
+ windows.removeListener('open', listener2);
+ windows.removeListener('close', listener3);
+ windows.removeListener('close', listener4);
+ test.done();
+ }
+
+
+ windows.open({
+ url: "data:text/html,foo",
+ onOpen: function(window) {
+ window.close(verify);
+ }
+ });
+};
+
+exports.testWindowTabsObject = function(test) {
+ test.waitUntilDone();
+
+ browserWindows.open({
+ url: "data:text/html,<title>tab 1</title>",
+ onOpen: function onOpen(window) {
+ test.assertEqual(window.tabs.length, 1, "Only 1 tab open");
+
+ window.tabs.open({
+ url: "data:text/html,<title>tab 2</title>",
+ inBackground: true,
+ onReady: function onReady(newTab) {
+ test.assertEqual(window.tabs.length, 2, "New tab open");
+ test.assertEqual(newTab.title, "tab 2", "Correct new tab title");
+ test.assertEqual(window.tabs.activeTab.title, "tab 1", "Correct active tab");
+
+ let i = 1;
+ for each (let tab in window.tabs)
+ test.assertEqual(tab.title, "tab " + i++, "Correct title");
+
+ window.close();
+ }
+ });
+ },
+ onClose: function onClose(window) {
+ test.assertEqual(window.tabs.length, 0, "No more tabs on closed window");
+ test.done();
+ }
+ });
+};
+
+exports.testActiveWindow = function(test) {
+ const xulApp = require("xul-app");
+ if (xulApp.versionInRange(xulApp.platformVersion, "1.9.2", "1.9.2.*")) {
+ test.pass("This test is disabled on 3.6. For more information, see bug 598525");
+ return;
+ }
+
+ let windows = browserWindows;
+
+ // API window objects
+ let window2, window3;
+
+ // Raw window objects
+ let nonBrowserWindow = getTestRunnerWindow(), rawWindow2, rawWindow3;
+
+ test.waitUntilDone();
+
+ let testSteps = [
+ function() {
+ test.assertEqual(windows.length, 3, "Correct number of browser windows");
+ let count = 0;
+ for (let window in windows)
+ count++;
+ test.assertEqual(count, 3, "Correct number of windows returned by iterator");
+
+ rawWindow2.focus();
+ continueAfterFocus(rawWindow2);
+ },
+ function() {
+ nonBrowserWindow.focus();
+ continueAfterFocus(nonBrowserWindow);
+ },
+ function() {
+ /**
+ * Bug 614079: This test fails intermittently on some specific linux
+ * environnements, without being able to reproduce it in same
+ * distribution with same window manager.
+ * Disable it until being able to reproduce it easily.
+
+ // On linux, focus is not consistent, so we can't be sure
+ // what window will be on top.
+ // Here when we focus "non-browser" window,
+ // Any Browser window may be selected as "active".
+ test.assert(windows.activeWindow == window2 || windows.activeWindow == window3,
+ "Non-browser windows aren't handled by this module");
+ */
+ window2.activate();
+ continueAfterFocus(rawWindow2);
+ },
+ function() {
+ test.assertEqual(windows.activeWindow.title, window2.title, "Correct active window - 2");
+ window3.activate();
+ continueAfterFocus(rawWindow3);
+ },
+ function() {
+ test.assertEqual(windows.activeWindow.title, window3.title, "Correct active window - 3");
+ nonBrowserWindow.focus();
+ finishTest();
+ }
+ ];
+
+ windows.open({
+ url: "data:text/html,<title>window 2</title>",
+ onOpen: function(window) {
+ window2 = window;
+ rawWindow2 = wm.getMostRecentWindow("navigator:browser");
+
+ windows.open({
+ url: "data:text/html,<title>window 3</title>",
+ onOpen: function(window) {
+ window.tabs.activeTab.on('ready', function onReady() {
+ window3 = window;
+ rawWindow3 = wm.getMostRecentWindow("navigator:browser");
+ nextStep()
+ });
+ }
+ });
+ }
+ });
+
+ function nextStep() {
+ if (testSteps.length > 0)
+ testSteps.shift()();
+ }
+
+ function continueAfterFocus(targetWindow) {
+
+ // Based on SimpleTest.waitForFocus
+ var fm = Cc["@mozilla.org/focus-manager;1"].
+ getService(Ci.nsIFocusManager);
+
+ var childTargetWindow = {};
+ fm.getFocusedElementForWindow(targetWindow, true, childTargetWindow);
+ childTargetWindow = childTargetWindow.value;
+
+ var focusedChildWindow = {};
+ if (fm.activeWindow) {
+ fm.getFocusedElementForWindow(fm.activeWindow, true, focusedChildWindow);
+ focusedChildWindow = focusedChildWindow.value;
+ }
+
+ var focused = (focusedChildWindow == childTargetWindow);
+ if (focused) {
+ nextStep();
+ } else {
+ childTargetWindow.addEventListener("focus", function focusListener() {
+ childTargetWindow.removeEventListener("focus", focusListener, true);
+ nextStep();
+ }, true);
+ }
+
+ }
+
+ function finishTest() {
+ window3.close(function() {
+ window2.close(function() {
+ test.done();
+ });
+ });
+ }
+};
+
+// If the module doesn't support the app we're being run in, require() will
+// throw. In that case, remove all tests above from exports, and add one dummy
+// test that passes.
+try {
+ browserWindows = require("windows").browserWindows;
+}
+catch (err) {
+ // This bug should be mentioned in the error message.
+ let bug = "https://bugzilla.mozilla.org/show_bug.cgi?id=571449";
+ if (err.message.indexOf(bug) < 0)
+ throw err;
+ for (let [prop, val] in Iterator(exports)) {
+ if (/^test/.test(prop) && typeof(val) === "function")
+ delete exports[prop];
+ }
+ exports.testAppNotSupported = function (test) {
+ test.pass("the windows module does not support this application.");
+ };
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/README.md b/tools/addon-sdk-1.7/packages/api-utils/README.md
new file mode 100644
index 0000000..55adb57
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/README.md
@@ -0,0 +1,35 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+API Utils provides a basic CommonJS infrastructure for
+developing traditional XULRunner add-ons and applications. It is
+the basis for the Add-on SDK.
+
+To address issues present in traditional add-on development,
+API Utils provides mechanisms for:
+
+* writing and executing test cases, inspired by Python's [nose][]
+ package,
+* tracking JS objects of interest to aid in memory profiling and leak
+ detection,
+* registering callbacks that perform cleanup tasks when modules are
+ unloaded,
+* easily reporting errors with full stack tracebacks.
+
+API Utils also has the following characteristics:
+
+* Beautiful, concise documentation.
+* A rigorous test suite ensuring that the library doesn't break as the
+ Mozilla platform evolves.
+* Solid developer ergonomics ensuring that developers can easily find
+ out why something they're doing isn't working.
+
+API Utils is intended to be very small and only contain the bare
+minimum of functionality that all add-ons need.
+
+Note that the API Utils package has not fully stabilized yet, meaning that
+we do still expect to make incompatible changes to its APIs in future releases
+of the SDK.
+
+ [nose]: http://code.google.com/p/python-nose/
diff --git a/tools/addon-sdk-1.7/packages/api-utils/data/content-proxy.js b/tools/addon-sdk-1.7/packages/api-utils/data/content-proxy.js
new file mode 100644
index 0000000..f0a39d3
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/data/content-proxy.js
@@ -0,0 +1,847 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+let Ci = Components.interfaces;
+
+/**
+ * Access key that allows privileged code to unwrap proxy wrappers through
+ * valueOf:
+ * let xpcWrapper = proxyWrapper.valueOf(UNWRAP_ACCESS_KEY);
+ * This key should only be used by proxy unit test.
+ */
+ const UNWRAP_ACCESS_KEY = {};
+
+
+ /**
+ * Returns a closure that wraps arguments before calling the given function,
+ * which can be given to native functions that accept a function, such that when
+ * the closure is called, the given function is called with wrapped arguments.
+ *
+ * @param fun {Function}
+ * the function for which to create a closure wrapping its arguments
+ * @param obj {Object}
+ * target object from which `fun` comes from
+ * (optional, for debugging purpose)
+ * @param name {String}
+ * name of the attribute from which `fun` is binded on `obj`
+ * (optional, for debugging purpose)
+ *
+ * Example:
+ * function contentScriptListener(event) {}
+ * let wrapper = ContentScriptFunctionWrapper(contentScriptListener);
+ * xray.addEventListener("...", wrapper, false);
+ * -> Allow to `event` to be wrapped
+ */
+function ContentScriptFunctionWrapper(fun, obj, name) {
+ if ("___proxy" in fun && typeof fun.___proxy == "function")
+ return fun.___proxy;
+
+ let wrappedFun = function () {
+ let args = [];
+ for (let i = 0, l = arguments.length; i < l; i++)
+ args.push(wrap(arguments[i]));
+
+ //console.log("Called from native :"+obj+"."+name);
+ //console.log(">args "+arguments.length);
+ //console.log(fun);
+
+ // Native code can execute this callback with `this` being the wrapped
+ // function. For example, window.mozRequestAnimationFrame.
+ if (this == wrappedFun)
+ return fun.apply(fun, args);
+
+ return fun.apply(wrap(this), args);
+ };
+
+ Object.defineProperty(fun, "___proxy", {value : wrappedFun,
+ writable : false,
+ enumerable : false,
+ configurable : false});
+
+ return wrappedFun;
+}
+
+/**
+ * Returns a closure that unwraps arguments before calling the `fun` function,
+ * which can be used to build a wrapper for a native function that accepts
+ * wrapped arguments, since native function only accept unwrapped arguments.
+ *
+ * @param fun {Function}
+ * the function to wrap
+ * @param originalObject {Object}
+ * target object from which `fun` comes from
+ * (optional, for debugging purpose)
+ * @param name {String}
+ * name of the attribute from which `fun` is binded on `originalObject`
+ * (optional, for debugging purpose)
+ *
+ * Example:
+ * wrapper.appendChild = NativeFunctionWrapper(xray.appendChild, xray);
+ * wrapper.appendChild(anotherWrapper);
+ * -> Allow to call xray.appendChild with unwrapped version of anotherWrapper
+ */
+function NativeFunctionWrapper(fun, originalObject, name) {
+ return function () {
+ let args = [];
+ let obj = this && typeof this.valueOf == "function" ?
+ this.valueOf(UNWRAP_ACCESS_KEY) : this;
+
+ for (let i = 0, l = arguments.length; i < l; i++)
+ args.push( unwrap(arguments[i], obj, name) );
+
+ //if (name != "toString")
+ //console.log(">>calling native ["+(name?name:'#closure#')+"]: \n"+fun.apply+"\n"+obj+"\n("+args.join(', ')+")\nthis :"+obj+"from:"+originalObject+"\n");
+
+ // Need to use Function.prototype.apply.apply because XMLHttpRequest
+ // is a function (typeof return 'function') and fun.apply is null :/
+ let unwrapResult = Function.prototype.apply.apply(fun, [obj, args]);
+ let result = wrap(unwrapResult, obj, name);
+
+ //console.log("<< "+rr+" -> "+r);
+
+ return result;
+ };
+}
+
+/*
+ * Unwrap a JS value that comes from the content script.
+ * Mainly converts proxy wrapper to XPCNativeWrapper.
+ */
+function unwrap(value, obj, name) {
+ //console.log("unwrap : "+value+" ("+name+")");
+ if (!value)
+ return value;
+ let type = typeof value;
+
+ // In case of proxy, unwrap them recursively
+ // (it should not be recursive, just in case of)
+ if (["object", "function"].indexOf(type) !== -1 &&
+ "__isWrappedProxy" in value) {
+ while("__isWrappedProxy" in value)
+ value = value.valueOf(UNWRAP_ACCESS_KEY);
+ return value;
+ }
+
+ // In case of functions we need to return a wrapper that converts native
+ // arguments applied to this function into proxies.
+ if (type == "function")
+ return ContentScriptFunctionWrapper(value, obj, name);
+
+ // We must wrap objects coming from content script too, as they may have
+ // a function that will be called by a native method.
+ // For example:
+ // addEventListener(..., { handleEvent: function(event) {} }, ...);
+ if (type == "object")
+ return ContentScriptObjectWrapper(value);
+
+ if (["string", "number", "boolean"].indexOf(type) !== -1)
+ return value;
+ //console.log("return non-wrapped to native : "+typeof value+" -- "+value);
+ return value;
+}
+
+/**
+ * Returns an XrayWrapper proxy object that allow to wrap any of its function
+ * though `ContentScriptFunctionWrapper`. These proxies are given to
+ * XrayWrappers in order to automatically wrap values when they call a method
+ * of these proxies. So that they are only used internaly and content script,
+ * nor web page have ever access to them. As a conclusion, we can consider
+ * this code as being safe regarding web pages overload.
+ *
+ *
+ * @param obj {Object}
+ * object coming from content script context to wrap
+ *
+ * Example:
+ * let myListener = { handleEvent: function (event) {} };
+ * node.addEventListener("click", myListener, false);
+ * `event` has to be wrapped, so handleEvent has to be wrapped using
+ * `ContentScriptFunctionWrapper` function.
+ * In order to do so, we build this new kind of proxies.
+ */
+function ContentScriptObjectWrapper(obj) {
+ if ("___proxy" in obj && typeof obj.___proxy == "object")
+ return obj.___proxy;
+
+ function valueOf(key) {
+ if (key === UNWRAP_ACCESS_KEY)
+ return obj;
+ return this;
+ }
+
+ let proxy = Proxy.create({
+ // Fundamental traps
+ getPropertyDescriptor: function(name) {
+ return Object.getOwnPropertyDescriptor(obj, name);
+ },
+ defineProperty: function(name, desc) {
+ return Object.defineProperty(obj, name, desc);
+ },
+ getOwnPropertyNames: function () {
+ return Object.getOwnPropertyNames(obj);
+ },
+ delete: function(name) {
+ return delete obj[name];
+ },
+ // derived traps
+ has: function(name) {
+ return name === "__isXrayWrapperProxy" ||
+ name in obj;
+ },
+ hasOwn: function(name) {
+ return Object.prototype.hasOwnProperty.call(obj, name);
+ },
+ get: function(receiver, name) {
+ if (name == "valueOf")
+ return valueOf;
+ let value = obj[name];
+ if (!value)
+ return value;
+
+ return unwrap(value);
+ },
+ set: function(receiver, name, val) {
+ obj[name] = val;
+ return true;
+ },
+ enumerate: function() {
+ var result = [];
+ for each (let name in obj) {
+ result.push(name);
+ };
+ return result;
+ },
+ keys: function() {
+ return Object.keys(obj);
+ }
+ });
+
+ Object.defineProperty(obj, "___proxy", {value : proxy,
+ writable : false,
+ enumerable : false,
+ configurable : false});
+
+ return proxy;
+}
+
+// List of all existing typed arrays.
+// Can be found here:
+// http://mxr.mozilla.org/mozilla-central/source/js/src/jsapi.cpp#1790
+const typedArraysCtor = [
+ ArrayBuffer,
+ Int8Array,
+ Uint8Array,
+ Int16Array,
+ Uint16Array,
+ Int32Array,
+ Uint32Array,
+ Float32Array,
+ Float64Array,
+ Uint8ClampedArray
+];
+
+/*
+ * Wrap a JS value coming from the document by building a proxy wrapper.
+ */
+function wrap(value, obj, name, debug) {
+ if (!value)
+ return value;
+ let type = typeof value;
+ if (type == "object") {
+ // Bug 671016: Typed arrays don't need to be proxified.
+ // We avoid checking the whole constructor list on all objects
+ // by doing this check only on non-extensible objects:
+ if (!Object.isExtensible(value) &&
+ typedArraysCtor.indexOf(value.constructor) !== -1)
+ return value;
+
+ // Bug 715755: do not proxify COW wrappers
+ // These wrappers throw an exception when trying to access
+ // any attribute that is not in a white list
+ try {
+ ("nonExistantAttribute" in value);
+ }
+ catch(e) {
+ if (e.message.indexOf("Permission denied to access property") !== -1)
+ return value;
+ }
+
+ // We may have a XrayWrapper proxy.
+ // For example:
+ // let myListener = { handleEvent: function () {} };
+ // node.addEventListener("click", myListener, false);
+ // When native code want to call handleEvent,
+ // we go though ContentScriptFunctionWrapper that calls `wrap(this)`
+ // `this` is the XrayWrapper proxy of myListener.
+ // We return this object without building a CS proxy as it is already
+ // a value coming from the CS.
+ if ("__isXrayWrapperProxy" in value)
+ return value.valueOf(UNWRAP_ACCESS_KEY);
+
+ // Unwrap object before wrapping it.
+ // It should not happen with CS proxy objects.
+ while("__isWrappedProxy" in value) {
+ value = value.valueOf(UNWRAP_ACCESS_KEY);
+ }
+
+ if (XPCNativeWrapper.unwrap(value) !== value)
+ return getProxyForObject(value);
+ // In case of Event, HTMLCollection or NodeList or ???
+ // XPCNativeWrapper.unwrap(value) === value
+ // but it's still a XrayWrapper so let's build a proxy
+ return getProxyForObject(value);
+ }
+ if (type == "function") {
+ if (XPCNativeWrapper.unwrap(value) !== value
+ || (typeof value.toString === "function" &&
+ value.toString().match(/\[native code\]/))) {
+ return getProxyForFunction(value, NativeFunctionWrapper(value, obj, name));
+ }
+ return value;
+ }
+ if (type == "string")
+ return value;
+ if (type == "number")
+ return value;
+ if (type == "boolean")
+ return value;
+ //console.log("return non-wrapped to wrapped : "+value);
+ return value;
+}
+
+/*
+ * Wrap an object from the document to a proxy wrapper
+ */
+function getProxyForObject(obj) {
+ if (typeof obj != "object") {
+ let msg = "tried to proxify something other than an object: " + typeof obj;
+ console.warn(msg);
+ throw msg;
+ }
+ if ("__isWrappedProxy" in obj) {
+ return obj;
+ }
+ // Check if there is a proxy cached on this wrapper,
+ // but take care of prototype ___proxy attribute inheritance!
+ if (obj && obj.___proxy && obj.___proxy.valueOf(UNWRAP_ACCESS_KEY) === obj) {
+ return obj.___proxy;
+ }
+
+ let proxy = Proxy.create(handlerMaker(obj));
+
+ Object.defineProperty(obj, "___proxy", {value : proxy,
+ writable : false,
+ enumerable : false,
+ configurable : false});
+ return proxy;
+}
+
+/*
+ * Wrap a function from the document to a proxy wrapper
+ */
+function getProxyForFunction(fun, callTrap) {
+ if (typeof fun != "function") {
+ let msg = "tried to proxify something other than a function: " + typeof fun;
+ console.warn(msg);
+ throw msg;
+ }
+ if ("__isWrappedProxy" in fun)
+ return obj;
+ if ("___proxy" in fun)
+ return fun.___proxy;
+
+ let proxy = Proxy.createFunction(handlerMaker(fun), callTrap);
+
+ Object.defineProperty(fun, "___proxy", {value : proxy,
+ writable : false,
+ enumerable : false,
+ configurable : false});
+
+ return proxy;
+}
+
+/*
+ * Check if a DOM attribute name is an event name.
+ */
+function isEventName(id) {
+ if (id.indexOf("on") != 0 || id.length == 2)
+ return false;
+ // Taken from:
+ // http://mxr.mozilla.org/mozilla-central/source/dom/base/nsDOMClassInfo.cpp#7616
+ switch (id[2]) {
+ case 'a' :
+ return (id == "onabort" ||
+ id == "onafterscriptexecute" ||
+ id == "onafterprint");
+ case 'b' :
+ return (id == "onbeforeunload" ||
+ id == "onbeforescriptexecute" ||
+ id == "onblur" ||
+ id == "onbeforeprint");
+ case 'c' :
+ return (id == "onchange" ||
+ id == "onclick" ||
+ id == "oncontextmenu" ||
+ id == "oncopy" ||
+ id == "oncut" ||
+ id == "oncanplay" ||
+ id == "oncanplaythrough");
+ case 'd' :
+ return (id == "ondblclick" ||
+ id == "ondrag" ||
+ id == "ondragend" ||
+ id == "ondragenter" ||
+ id == "ondragleave" ||
+ id == "ondragover" ||
+ id == "ondragstart" ||
+ id == "ondrop" ||
+ id == "ondurationchange");
+ case 'e' :
+ return (id == "onerror" ||
+ id == "onemptied" ||
+ id == "onended");
+ case 'f' :
+ return id == "onfocus";
+ case 'h' :
+ return id == "onhashchange";
+ case 'i' :
+ return (id == "oninput" ||
+ id == "oninvalid");
+ case 'k' :
+ return (id == "onkeydown" ||
+ id == "onkeypress" ||
+ id == "onkeyup");
+ case 'l' :
+ return (id == "onload" ||
+ id == "onloadeddata" ||
+ id == "onloadedmetadata" ||
+ id == "onloadstart");
+ case 'm' :
+ return (id == "onmousemove" ||
+ id == "onmouseout" ||
+ id == "onmouseover" ||
+ id == "onmouseup" ||
+ id == "onmousedown" ||
+ id == "onmessage");
+ case 'p' :
+ return (id == "onpaint" ||
+ id == "onpageshow" ||
+ id == "onpagehide" ||
+ id == "onpaste" ||
+ id == "onpopstate" ||
+ id == "onpause" ||
+ id == "onplay" ||
+ id == "onplaying" ||
+ id == "onprogress");
+ case 'r' :
+ return (id == "onreadystatechange" ||
+ id == "onreset" ||
+ id == "onresize" ||
+ id == "onratechange");
+ case 's' :
+ return (id == "onscroll" ||
+ id == "onselect" ||
+ id == "onsubmit" ||
+ id == "onseeked" ||
+ id == "onseeking" ||
+ id == "onstalled" ||
+ id == "onsuspend");
+ case 't':
+ return id == "ontimeupdate"
+ /*
+ // TODO: Make it work for mobile version
+ ||
+ (nsDOMTouchEvent::PrefEnabled() &&
+ (id == "ontouchstart" ||
+ id == "ontouchend" ||
+ id == "ontouchmove" ||
+ id == "ontouchenter" ||
+ id == "ontouchleave" ||
+ id == "ontouchcancel"))*/;
+
+ case 'u' :
+ return id == "onunload";
+ case 'v':
+ return id == "onvolumechange";
+ case 'w':
+ return id == "onwaiting";
+ }
+
+ return false;
+}
+
+// XrayWrappers miss some attributes.
+// Here is a list of functions that return a value when it detects a miss:
+const NODES_INDEXED_BY_NAME = ["IMG", "FORM", "APPLET", "EMBED", "OBJECT"];
+const xRayWrappersMissFixes = [
+
+ // Fix bug with XPCNativeWrapper on HTMLCollection
+ // We can only access array item once, then it's undefined :o
+ function (obj, name) {
+ let i = parseInt(name);
+ if (obj.toString().match(/HTMLCollection|NodeList/) &&
+ i >= 0 && i < obj.length) {
+ return wrap(XPCNativeWrapper(obj.wrappedJSObject[name]), obj, name);
+ }
+ return null;
+ },
+
+ // Trap access to document["form name"]
+ // that may refer to an existing form node
+ // http://mxr.mozilla.org/mozilla-central/source/dom/base/nsDOMClassInfo.cpp#9285
+ function (obj, name) {
+ if ("nodeType" in obj && obj.nodeType == 9) {
+ let node = obj.wrappedJSObject[name];
+ // List of supported tag:
+ // http://mxr.mozilla.org/mozilla-central/source/content/html/content/src/nsGenericHTMLElement.cpp#1267
+ if (node && NODES_INDEXED_BY_NAME.indexOf(node.tagName) != -1)
+ return wrap(XPCNativeWrapper(node));
+ }
+ return null;
+ },
+
+ // Trap access to window["frame name"] and window.frames[i]
+ // that refer to an (i)frame internal window object
+ // http://mxr.mozilla.org/mozilla-central/source/dom/base/nsDOMClassInfo.cpp#6824
+ function (obj, name) {
+ if (typeof obj == "object" && "document" in obj) {
+ // Ensure that we are on a window object
+ try {
+ obj.QueryInterface(Ci.nsIDOMWindow);
+ }
+ catch(e) {
+ return null;
+ }
+
+ // Integer case:
+ let i = parseInt(name);
+ if (i >= 0 && i in obj) {
+ return wrap(XPCNativeWrapper(obj[i]));
+ }
+
+ // String name case:
+ if (name in obj.wrappedJSObject) {
+ let win = obj.wrappedJSObject[name];
+ let nodes = obj.document.getElementsByName(name);
+ for (let i = 0, l = nodes.length; i < l; i++) {
+ let node = nodes[i];
+ if ("contentWindow" in node && node.contentWindow == win)
+ return wrap(node.contentWindow);
+ }
+ }
+ }
+ return null;
+ },
+
+ // Trap access to form["node name"]
+ // http://mxr.mozilla.org/mozilla-central/source/dom/base/nsDOMClassInfo.cpp#9477
+ function (obj, name) {
+ if (typeof obj == "object" && obj.tagName == "FORM") {
+ let match = obj.wrappedJSObject[name];
+ let nodes = obj.ownerDocument.getElementsByName(name);
+ for (let i = 0, l = nodes.length; i < l; i++) {
+ let node = nodes[i];
+ if (node == match)
+ return wrap(node);
+ }
+ }
+ return null;
+ },
+
+ // Fix XPathResult's constants being undefined on XrayWrappers
+ // these constants are defined here:
+ // http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/xpath/nsIDOMXPathResult.idl
+ // and are only numbers.
+ // The platform bug 665279 was fixed in Gecko 10.0a1.
+ // FIXME: remove this workaround once the SDK no longer supports Firefox 9.
+ function (obj, name) {
+ if (typeof obj == "object" && name in Ci.nsIDOMXPathResult) {
+ let value = Ci.nsIDOMXPathResult[name];
+ if (typeof value == "number" && value === obj.wrappedJSObject[name])
+ return value;
+ }
+ return null;
+ }
+
+];
+
+// XrayWrappers have some buggy methods.
+// Here is the list of them with functions returning some replacement
+// for a given object `obj`:
+const xRayWrappersMethodsFixes = {
+ // postMessage method is checking the Javascript global
+ // and it expects it to be a window object.
+ // But in our case, the global object is our sandbox global object.
+ // See nsGlobalWindow::CallerInnerWindow():
+ // http://mxr.mozilla.org/mozilla-central/source/dom/base/nsGlobalWindow.cpp#5893
+ // nsCOMPtr<nsPIDOMWindow> win = do_QueryWrappedNative(wrapper);
+ // win is null
+ postMessage: function (obj) {
+ // Ensure that we are on a window object
+ try {
+ obj.QueryInterface(Ci.nsIDOMWindow);
+ }
+ catch(e) {
+ return null;
+ }
+ // Create a wrapper that is going to call `postMessage` through `eval`
+ let f = function postMessage(message, targetOrigin) {
+ message = message.toString().replace(/['\\]/g,"\\$&");
+ targetOrigin = targetOrigin.toString().replace(/['\\]/g,"\\$&");
+
+ let jscode = "this.postMessage('" + message + "', '" +
+ targetOrigin + "')";
+ return this.wrappedJSObject.eval(jscode);
+ };
+ return getProxyForFunction(f, NativeFunctionWrapper(f));
+ },
+
+ // Fix mozMatchesSelector uses that is broken on XrayWrappers
+ // when we use document.documentElement.mozMatchesSelector.call(node, expr)
+ // It's only working if we call mozMatchesSelector on the node itself.
+ // SEE BUG 658909: mozMatchesSelector returns incorrect results with XrayWrappers
+ mozMatchesSelector: function (obj) {
+ // Ensure that we are on an object to expose this buggy method
+ try {
+ // Bug 707576 removed nsIDOMNSElement.
+ // Can be simplified as soon as Firefox 11 become the minversion
+ obj.QueryInterface("nsIDOMElement" in Ci ? Ci.nsIDOMElement :
+ Ci.nsIDOMNSElement);
+ }
+ catch(e) {
+ return null;
+ }
+ // We can't use `wrap` function as `f` is not a native function,
+ // so wrap it manually:
+ let f = function mozMatchesSelector(selectors) {
+ return this.mozMatchesSelector(selectors);
+ };
+
+ return getProxyForFunction(f, NativeFunctionWrapper(f));
+ },
+
+ // Bug 679054: History API doesn't work with Proxy objects. We have to pass
+ // regular JS objects on `pushState` and `replaceState` methods.
+ // In addition, the first argument has to come from the same compartment.
+ pushState: function (obj) {
+ // Ensure that we are on an object that expose History API
+ try {
+ obj.QueryInterface(Ci.nsIDOMHistory);
+ }
+ catch(e) {
+ return null;
+ }
+ let f = function fix() {
+ // Call native method with JSON objects
+ // (need to convert `arguments` to an array via `slice`)
+ return this.pushState.apply(this, JSON.parse(JSON.stringify(Array.slice(arguments))));
+ };
+
+ return getProxyForFunction(f, NativeFunctionWrapper(f));
+ },
+ replaceState: function (obj) {
+ // Ensure that we are on an object that expose History API
+ try {
+ obj.QueryInterface(Ci.nsIDOMHistory);
+ }
+ catch(e) {
+ return null;
+ }
+ let f = function fix() {
+ // Call native method with JSON objects
+ // (need to convert `arguments` to an array via `slice`)
+ return this.replaceState.apply(this, JSON.parse(JSON.stringify(Array.slice(arguments))));
+ };
+
+ return getProxyForFunction(f, NativeFunctionWrapper(f));
+ }
+};
+
+/*
+ * Generate handler for proxy wrapper
+ */
+function handlerMaker(obj) {
+ // Overloaded attributes dictionary
+ let overload = {};
+ // Expando attributes dictionary (i.e. onclick, onfocus, on* ...)
+ let expando = {};
+ // Cache of methods overloaded to fix XrayWrapper bug
+ let methodFixes = {};
+ return {
+ // Fundamental traps
+ getPropertyDescriptor: function(name) {
+ return Object.getOwnPropertyDescriptor(obj, name);
+ },
+ defineProperty: function(name, desc) {
+ return Object.defineProperty(obj, name, desc);
+ },
+ getOwnPropertyNames: function () {
+ return Object.getOwnPropertyNames(obj);
+ },
+ delete: function(name) {
+ delete expando[name];
+ delete overload[name];
+ return delete obj[name];
+ },
+
+ // derived traps
+ has: function(name) {
+ if (name == "___proxy") return false;
+ if (isEventName(name)) {
+ // XrayWrappers throw exception when we try to access expando attributes
+ // even on "name in wrapper". So avoid doing it!
+ return name in expando;
+ }
+ return name in obj || name in overload || name == "__isWrappedProxy" ||
+ undefined !== this.get(null, name);
+ },
+ hasOwn: function(name) {
+ return Object.prototype.hasOwnProperty.call(obj, name);
+ },
+ get: function(receiver, name) {
+ if (name == "___proxy")
+ return undefined;
+
+ // Overload toString in order to avoid returning "[XrayWrapper [object HTMLElement]]"
+ // or "[object Function]" for function's Proxy
+ if (name == "toString") {
+ // Bug 714778: we should not pass obj.wrappedJSObject.toString
+ // in order to avoid sharing its proxy between two contents scripts.
+ // (not that `unwrappedObj` can be equal to `obj` when `obj` isn't
+ // an xraywrapper)
+ let unwrappedObj = XPCNativeWrapper.unwrap(obj);
+ return wrap(function () {
+ return unwrappedObj.toString.call(
+ this.valueOf(UNWRAP_ACCESS_KEY), arguments);
+ }, obj, name);
+ }
+
+ // Offer a way to retrieve XrayWrapper from a proxified node through `valueOf`
+ if (name == "valueOf")
+ return function (key) {
+ if (key === UNWRAP_ACCESS_KEY)
+ return obj;
+ return this;
+ };
+
+ // Return overloaded value if there is one.
+ // It allows to overload native methods like addEventListener that
+ // are not saved, even on the wrapper itself.
+ // (And avoid some methods like toSource from being returned here! [__proto__ test])
+ if (name in overload &&
+ overload[name] != Object.getPrototypeOf(overload)[name] &&
+ name != "__proto__") {
+ return overload[name];
+ }
+
+ // Catch exceptions thrown by XrayWrappers when we try to access on*
+ // attributes like onclick, onfocus, ...
+ if (isEventName(name)) {
+ //console.log("expando:"+obj+" - "+obj.nodeType);
+ return name in expando ? expando[name].original : undefined;
+ }
+
+ // Overload some XrayWrappers method in order to fix its bugs
+ if (name in methodFixes &&
+ methodFixes[name] != Object.getPrototypeOf(methodFixes)[name] &&
+ name != "__proto__")
+ return methodFixes[name];
+ if (Object.keys(xRayWrappersMethodsFixes).indexOf(name) !== -1) {
+ let fix = xRayWrappersMethodsFixes[name](obj);
+ if (fix)
+ return methodFixes[name] = fix;
+ }
+
+ let o = obj[name];
+
+ // XrayWrapper miss some attributes, try to catch these and return a value
+ if (!o) {
+ for each(let atttributeFixer in xRayWrappersMissFixes) {
+ let fix = atttributeFixer(obj, name);
+ if (fix)
+ return fix;
+ }
+ }
+
+ // Generic case
+ return wrap(o, obj, name);
+
+ },
+
+ set: function(receiver, name, val) {
+
+ if (isEventName(name)) {
+ //console.log("SET on* attribute : " + name + " / " + val + "/" + obj);
+ let shortName = name.replace(/^on/,"");
+
+ // Unregister previously set listener
+ if (expando[name]) {
+ obj.removeEventListener(shortName, expando[name], true);
+ delete expando[name];
+ }
+
+ // Only accept functions
+ if (typeof val != "function")
+ return false;
+
+ // Register a new listener
+ let original = val;
+ val = ContentScriptFunctionWrapper(val);
+ expando[name] = val;
+ val.original = original;
+ obj.addEventListener(name.replace(/^on/, ""), val, true);
+ return true;
+ }
+
+ obj[name] = val;
+
+ // Handle native method not overloaded on XrayWrappers:
+ // obj.addEventListener = val; -> obj.addEventlistener = native method
+ // And, XPCNativeWrapper bug where nested values appear to be wrapped:
+ // obj.customNestedAttribute = val -> obj.customNestedAttribute !== val
+ // obj.customNestedAttribute = "waive wrapper something"
+ // SEE BUG 658560: Fix identity problem with CrossOriginWrappers
+ // TODO: check that DOM can't be updated by the document itself and so overloaded value becomes wrong
+ // but I think such behavior is limited to primitive type
+ if ((typeof val == "function" || typeof val == "object") && name) {
+ overload[name] = val;
+ }
+
+ return true;
+ },
+
+ enumerate: function() {
+ var result = [];
+ for each (let name in Object.keys(obj)) {
+ result.push(name);
+ };
+ return result;
+ },
+
+ keys: function() {
+ return Object.keys(obj);
+ }
+ };
+};
+
+
+/*
+ * Wrap an object from the document to a proxy wrapper.
+ */
+function create(object) {
+ if ("wrappedJSObject" in object)
+ object = object.wrappedJSObject;
+ let xpcWrapper = XPCNativeWrapper(object);
+ // If we can't build an XPCNativeWrapper, it doesn't make sense to build
+ // a proxy. All proxy code is based on having such wrapper that store
+ // different JS attributes set.
+ // (we can't build XPCNativeWrapper when object is from the same
+ // principal/domain)
+ if (object === xpcWrapper) {
+ return object;
+ }
+ return getProxyForObject(xpcWrapper);
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/data/test-content-symbiont.js b/tools/addon-sdk-1.7/packages/api-utils/data/test-content-symbiont.js
new file mode 100644
index 0000000..65a2a21
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/data/test-content-symbiont.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// test-content-symbiont
diff --git a/tools/addon-sdk-1.7/packages/api-utils/data/test-message-manager.js b/tools/addon-sdk-1.7/packages/api-utils/data/test-message-manager.js
new file mode 100644
index 0000000..d647bd8
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/data/test-message-manager.js
@@ -0,0 +1,6 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const TEST_VALUE = 11;
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/data/test-trusted-document.html b/tools/addon-sdk-1.7/packages/api-utils/data/test-trusted-document.html
new file mode 100644
index 0000000..5845cf5
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/data/test-trusted-document.html
@@ -0,0 +1,17 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<html>
+<head>
+ <title>Worker test</title>
+</head>
+<body>
+ <p id="paragraph">Lorem ipsum dolor sit amet.</p>
+ <script>
+ addon.port.on('addon-to-document', function (arg) {
+ addon.port.emit('document-to-addon', arg);
+ });
+ </script>
+</body>
+</html>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/data/worker.js b/tools/addon-sdk-1.7/packages/api-utils/data/worker.js
new file mode 100644
index 0000000..aba594d
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/data/worker.js
@@ -0,0 +1,247 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const ContentWorker = Object.freeze({
+ // TODO: Bug 727854 Use same implementation than common JS modules,
+ // i.e. EventEmitter module
+
+ /**
+ * Create an EventEmitter instance.
+ */
+ createEventEmitter: function createEventEmitter(emit) {
+ let listeners = Object.create(null);
+ let eventEmitter = Object.freeze({
+ emit: emit,
+ on: function on(name, callback) {
+ if (typeof callback !== "function")
+ return this;
+ if (!(name in listeners))
+ listeners[name] = [];
+ listeners[name].push(callback);
+ return this;
+ },
+ once: function once(name, callback) {
+ eventEmitter.on(name, function onceCallback() {
+ eventEmitter.removeListener(name, onceCallback);
+ callback.apply(callback, arguments);
+ });
+ },
+ removeListener: function removeListener(name, callback) {
+ if (!(name in listeners))
+ return;
+ let index = listeners[name].indexOf(name);
+ if (index == -1)
+ return;
+ listeners[name].splice(index, 1);
+ }
+ });
+ function onEvent(name) {
+ if (!(name in listeners))
+ return [];
+ let args = Array.slice(arguments, 1);
+ let results = [];
+ for each (let callback in listeners[name]) {
+ results.push(callback.apply(null, args));
+ }
+ return results;
+ }
+ function hasListenerFor(name) {
+ if (!(name in listeners))
+ return false;
+ return listeners[name].length > 0;
+ }
+ return {
+ eventEmitter: eventEmitter,
+ emit: onEvent,
+ hasListenerFor: hasListenerFor
+ };
+ },
+
+ /**
+ * Create an EventEmitter instance to communicate with chrome module
+ * by passing only strings between compartments.
+ * This function expects `emitToChrome` function, that allows to send
+ * events to the chrome module. It returns the EventEmitter as `pipe`
+ * attribute, and, `onChromeEvent` a function that allows chrome module
+ * to send event into the EventEmitter.
+ *
+ * pipe.emit --> emitToChrome
+ * onChromeEvent --> callback registered through pipe.on
+ */
+ createPipe: function createPipe(emitToChrome) {
+ function onEvent() {
+ // Convert to real array
+ let args = Array.slice(arguments);
+ // JSON.stringify is buggy with cross-sandbox values,
+ // it may return "{}" on functions. Use a replacer to match them correctly.
+ function replacer(k, v) {
+ return typeof v === "function" ? undefined : v;
+ }
+ let str = JSON.stringify(args, replacer);
+ emitToChrome(str);
+ }
+
+ let { eventEmitter, emit, hasListenerFor } =
+ ContentWorker.createEventEmitter(onEvent);
+
+ return {
+ pipe: eventEmitter,
+ onChromeEvent: function onChromeEvent(array) {
+ // We either receive a stringified array, or a real array.
+ // We still allow to pass an array of objects, in WorkerSandbox.emitSync
+ // in order to allow sending DOM node reference between content script
+ // and modules (only used for context-menu API)
+ let args = typeof array == "string" ? JSON.parse(array) : array;
+ return emit.apply(null, args);
+ },
+ hasListenerFor: hasListenerFor
+ };
+ },
+
+ injectConsole: function injectConsole(exports, pipe) {
+ exports.console = Object.freeze({
+ log: pipe.emit.bind(null, "console", "log"),
+ info: pipe.emit.bind(null, "console", "info"),
+ warn: pipe.emit.bind(null, "console", "warn"),
+ error: pipe.emit.bind(null, "console", "error"),
+ debug: pipe.emit.bind(null, "console", "debug"),
+ exception: pipe.emit.bind(null, "console", "exception"),
+ trace: pipe.emit.bind(null, "console", "trace")
+ });
+ },
+
+ injectTimers: function injectTimers(exports, chromeAPI, pipe, console) {
+ // wrapped functions from `'timer'` module.
+ // Wrapper adds `try catch` blocks to the callbacks in order to
+ // emit `error` event on a symbiont if exception is thrown in
+ // the Worker global scope.
+ // @see http://www.w3.org/TR/workers/#workerutils
+
+ // List of all living timeouts/intervals
+ let _timers = Object.create(null);
+
+ // Keep a reference to original timeout functions
+ let {
+ setTimeout: chromeSetTimeout,
+ setInterval: chromeSetInterval,
+ clearTimeout: chromeClearTimeout,
+ clearInterval: chromeClearInterval
+ } = chromeAPI.timers;
+
+ exports.setTimeout = function ContentScriptSetTimeout(callback, delay) {
+ let params = Array.slice(arguments, 2);
+ let id = chromeSetTimeout(function() {
+ try {
+ delete _timers[id];
+ callback.apply(null, params);
+ } catch(e) {
+ console.exception(e);
+ }
+ }, delay);
+ _timers[id] = "timeout";
+ return id;
+ };
+ exports.clearTimeout = function ContentScriptClearTimeout(id) {
+ delete _timers[id];
+ return chromeClearTimeout(id);
+ };
+
+ exports.setInterval = function ContentScriptSetInterval(callback, delay) {
+ let params = Array.slice(arguments, 2);
+ let id = chromeSetInterval(function() {
+ try {
+ callback.apply(null, params);
+ } catch(e) {
+ console.exception(e);
+ }
+ }, delay);
+ _timers[id] = "interval";
+ return id;
+ };
+ exports.clearInterval = function ContentScriptClearInterval(id) {
+ delete _timers[id];
+ return chromeClearInterval(id);
+ };
+ pipe.on("destroy", function clearTimeouts() {
+ // Unregister all setTimeout/setInterval on page unload
+ for (let id in _timers) {
+ let kind = _timers[id];
+ if (kind == "timeout")
+ chromeClearTimeout(id);
+ else
+ chromeClearInterval(id);
+ }
+ });
+ },
+
+ injectMessageAPI: function injectMessageAPI(exports, pipe) {
+
+ let { eventEmitter: port, emit : portEmit } =
+ ContentWorker.createEventEmitter(pipe.emit.bind(null, "event"));
+ pipe.on("event", portEmit);
+
+ let self = Object.freeze({
+ port: port,
+ postMessage: pipe.emit.bind(null, "message"),
+ on: pipe.on.bind(null),
+ once: pipe.once.bind(null),
+ removeListener: pipe.removeListener.bind(null),
+ });
+ Object.defineProperty(exports, "self", {
+ value: self
+ });
+
+ // Deprecated use of on/postMessage from globals
+ exports.postMessage = function deprecatedPostMessage() {
+ console.warn("The global `postMessage()` function in content " +
+ "scripts is deprecated in favor of the " +
+ "`self.postMessage()` function, which works the same. " +
+ "Replace calls to `postMessage()` with calls to " +
+ "`self.postMessage()`." +
+ "For more info on `self.on`, see " +
+ "<https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/addon-development/web-content.html>.");
+ return self.postMessage.apply(null, arguments);
+ };
+ exports.on = function deprecatedOn() {
+ console.warn("The global `on()` function in content scripts is " +
+ "deprecated in favor of the `self.on()` function, " +
+ "which works the same. Replace calls to `on()` with " +
+ "calls to `self.on()`" +
+ "For more info on `self.on`, see " +
+ "<https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/addon-development/web-content.html>.");
+ return self.on.apply(null, arguments);
+ };
+
+ // Deprecated use of `onMessage` from globals
+ let onMessage = null;
+ Object.defineProperty(exports, "onMessage", {
+ get: function () onMessage,
+ set: function (v) {
+ if (onMessage)
+ self.removeListener("message", onMessage);
+ console.warn("The global `onMessage` function in content scripts " +
+ "is deprecated in favor of the `self.on()` function. " +
+ "Replace `onMessage = function (data){}` definitions " +
+ "with calls to `self.on('message', function (data){})`. " +
+ "For more info on `self.on`, see " +
+ "<https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/addon-development/web-content.html>.");
+ onMessage = v;
+ if (typeof onMessage == "function")
+ self.on("message", onMessage);
+ }
+ });
+ },
+
+ inject: function (exports, chromeAPI, emitToChrome) {
+ let { pipe, onChromeEvent, hasListenerFor } =
+ ContentWorker.createPipe(emitToChrome);
+ ContentWorker.injectConsole(exports, pipe);
+ ContentWorker.injectTimers(exports, chromeAPI, pipe, exports.console);
+ ContentWorker.injectMessageAPI(exports, pipe);
+ return {
+ emitToContent: onChromeEvent,
+ hasListenerFor: hasListenerFor
+ };
+ }
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/api-utils.md b/tools/addon-sdk-1.7/packages/api-utils/docs/api-utils.md
new file mode 100644
index 0000000..aee88da
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/api-utils.md
@@ -0,0 +1,157 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Drew Willcoxon [adw@mozilla.com] -->
+<!-- edited by Noelle Murata [fiveinchpixie@gmail.com] -->
+
+The `api-utils` module provides some helpers useful to the SDK's high-level API
+implementations.
+
+Introduction
+------------
+
+The SDK high-level API design guidelines make a number of recommendations.
+This module implements some of those patterns so that your own implementations
+don't need to reinvent them.
+
+For example, public constructors should be callable both with and without the
+`new` keyword. Your module can implement this recommendation using the
+`publicConstructor` function.
+
+Options objects or "dictionaries" are also common throughout the high-level
+APIs. The guidelines recommend that public constructors should generally define
+a single `options` parameter rather than defining many parameters. Since one of
+the SDK's principles is to be friendly to developers, ideally all properties on
+options dictionaries should be checked for correct type, and informative error
+messages should be generated when clients make mistakes. With the
+`validateOptions` function, your module can easily do so.
+
+And objects are sometimes iterable over a custom set of key/value pairs.
+Such objects should have custom iterators that let consumers iterate keys,
+values, or [key, value] pairs. The `addIterator` function makes it easy to do
+so in a way that is consistent with the behavior of default iterators during
+`for...in`, `for each...in`, and `for...in Iterator()` loops.
+
+<api name="publicConstructor">
+@function
+Returns a function *C* that creates an instance of `privateConstructor`. *C*
+may be called with or without the `new` keyword.
+
+The prototype of each instance returned from *C* is *C*.`prototype`, and
+*C*.`prototype` is an object whose prototype is
+`privateConstructor.prototype`. Instances returned from *C* are therefore
+instances of both *C* and `privateConstructor`.
+
+Additionally, the constructor of each instance returned from *C* is *C*.
+
+Instances returned from *C* are automatically memory tracked using
+`memory.track` under the bin name `privateConstructor.name`.
+
+**Example**
+
+ function MyObject() {}
+ exports.MyObject = apiUtils.publicConstructor(MyObject);
+
+@returns {function}
+A function that makes new instances of `privateConstructor`.
+
+@param privateConstructor {constructor}
+</api>
+
+<api name="validateOptions">
+@function
+A function to validate an options dictionary according to the specified
+constraints.
+
+`map`, `is`, and `ok` are used in that order.
+
+The return value is an object whose keys are those keys in `requirements` that
+are also in `options` and whose values are the corresponding return values of
+`map` or the corresponding values in `options`. Note that any keys not shared
+by both `requirements` and `options` are not in the returned object.
+
+**Examples**
+
+A typical use:
+
+ var opts = { foo: 1337 };
+ var requirements = {
+ foo: {
+ map: function (val) val.toString(),
+ is: ["string"],
+ ok: function (val) val.length > 0,
+ msg: "foo must be a non-empty string."
+ }
+ };
+ var validatedOpts = apiUtils.validateOptions(opts, requirements);
+ // validatedOpts == { foo: "1337" }
+
+If the key `foo` is optional and doesn't need to be mapped:
+
+ var opts = { foo: 1337 };
+ var validatedOpts = apiUtils.validateOptions(opts, { foo: {} });
+ // validatedOpts == { foo: 1337 }
+
+ opts = {};
+ validatedOpts = apiUtils.validateOptions(opts, { foo: {} });
+ // validatedOpts == {}
+
+@returns {object}
+A validated options dictionary given some requirements. If any of the
+requirements are not met, an exception is thrown.
+
+@param options {object}
+The options dictionary to validate. It's not modified. If it's null or
+otherwise falsey, an empty object is assumed.
+
+@param requirements {object}
+An object whose keys are the expected keys in `options`. Any key in
+`options` that is not present in `requirements` is ignored. Each
+value in `requirements` is itself an object describing the requirements
+of its key. The keys of that object are the following, and each is optional:
+
+@prop [map] {function}
+A function that's passed the value of the key in the `options`. `map`'s
+return value is taken as the key's value in the final validated options,
+`is`, and `ok`. If `map` throws an exception it is caught and discarded,
+and the key's value is its value in `options`.
+
+@prop [is] {array}
+An array containing the number of `typeof` type names. If the key's value is
+none of these types it fails validation. Arrays and nulls are identified by
+the special type names "array" and "null"; "object" will not match either.
+No type coercion is done.
+
+@prop [ok] {function}
+A function that is passed the key's value. If it returns false, the value
+fails validation.
+
+@prop [msg] {string}
+If the key's value fails validation, an exception is thrown. This string
+will be used as its message. If undefined, a generic message is used, unless
+`is` is defined, in which case the message will state that the value needs to
+be one of the given types.
+</api>
+
+<api name="addIterator">
+@function
+Adds an iterator to the specified object that iterates keys, values,
+or [key, value] pairs depending on how it is invoked, i.e.:
+
+ for (var key in obj) { ... } // iterate keys
+ for each (var val in obj) { ... } // iterate values
+ for (var [key, val] in Iterator(obj)) { ... } // iterate pairs
+
+If your object only iterates either keys or values, you don't need this
+function. Simply assign a generator function that iterates the keys/values
+to your object's `__iterator__` property instead, f.e.:
+
+ obj.__iterator__ = function () { for each (var i in items) yield i; }
+
+@param obj {object}
+the object to which to add the iterator
+
+@param keysValsGen {function}
+a generator function that yields [key, value] pairs
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/app-strings.md b/tools/addon-sdk-1.7/packages/api-utils/docs/app-strings.md
new file mode 100644
index 0000000..c40ddaf
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/app-strings.md
@@ -0,0 +1,65 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+The `app-strings` module gives you access to the host application's localized
+string bundles (`.properties` files).
+
+The module exports the `StringBundle` constructor function. To access a string
+bundle, construct an instance of `StringBundle`, passing it the bundle's URL:
+
+ var StringBundle = require("app-strings").StringBundle;
+ var bundle = StringBundle("chrome://browser/locale/browser.properties");
+
+To get the value of a string, call the object's `get` method, passing it
+the name of the string:
+
+ var accessKey = bundle.get("contextMenuSearchText.accesskey");
+ // "S" in the en-US locale
+
+To get the formatted value of a string that accepts arguments, call the object's
+`get` method, passing it the name of the string and an array of arguments
+with which to format the string:
+
+ var searchText = bundle.get("contextMenuSearchText",
+ ["universe", "signs of intelligent life"]);
+ // 'Search universe for "signs of intelligent life"' in the en-US locale
+
+To get all strings in the bundle, iterate the object, which returns arrays
+of the form [name, value]:
+
+ for (var [name, value] in Iterator(bundle))
+ console.log(name + " = " + value);
+
+Iteration
+---------
+
+<code>for (var name in bundle) { ... }</code>
+
+Iterate the names of strings in the bundle.
+
+<code>for each (var val in bundle) { ... }</code>
+
+Iterate the values of strings in the bundle.
+
+<code>for (var [name, value] in Iterator(bundle)) { ... }</code>
+
+Iterate the names and values of strings in the bundle.
+
+
+<api name="StringBundle">
+@class
+The `StringBundle` object represents a string bundle.
+<api name="StringBundle">
+@constructor
+Creates a StringBundle object that gives you access to a string bundle.
+@param url {string} the URL of the string bundle
+@returns {StringBundle} the string bundle
+</api>
+<api name="get">
+@method Get the value of the string with the given name.
+@param [name] {string} the name of the string to get
+@param [args] {array} (optional) strings that replace placeholders in the string
+@returns {string} the value of the string
+</api>
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/base.md b/tools/addon-sdk-1.7/packages/api-utils/docs/base.md
new file mode 100644
index 0000000..7a694f2
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/base.md
@@ -0,0 +1,207 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+### Inheritance ###
+
+Doing [inheritance in JavaScript](https://developer.mozilla.org/en/Introduction_to_Object-Oriented_JavaScript)
+is both verbose and painful. Reading or writing such code requires requires
+sharp eye and lot's of discipline, mainly due to code fragmentation and lots of
+machinery exposed:
+
+ // Defining a simple Class
+ function Dog(name) {
+ // Classes are for creating instances, calling them without `new` changes
+ // behavior, which in majority cases you need to handle, so you end up
+ // with additional boilerplate.
+ if (!(this instanceof Dog)) return new Dog(name);
+
+ this.name = name;
+ };
+ // To define methods you need to make a dance with a special 'prototype'
+ // property of the constructor function. This is too much machinery exposed.
+ Dog.prototype.type = 'dog';
+ Dog.prototype.bark = function bark() {
+ return 'Ruff! Ruff!'
+ };
+
+ // Subclassing a `Dog`
+ function Pet(name, breed) {
+ // Once again we do our little dance
+ if (!(this instanceof Pet)) return new Pet(name, breed);
+
+ Dog.call(this, name);
+ this.breed = breed;
+ }
+ // To subclass, you need to make another special dance with special
+ // 'prototype' properties.
+ Pet.prototype = Object.create(Dog.prototype);
+ // If you want correct instanceof behavior you need to make a dance with
+ // another special `constructor` property of the `prototype` object.
+ Object.defineProperty(Pet.prototype, 'contsructor', { value: Pet });
+ // Finally you can define some properties.
+ Pet.prototype.call = function(name) {
+ return this.name === name ? this.bark() : '';
+ };
+
+An "exemplar" is a factory for instances. Usually exemplars are defined as
+(constructor) functions as in examples above. But that does not necessary has
+to be the case. Prototype (object) can form far more simpler exemplars. After
+all what could be more object oriented than objects that inherit from objects.
+
+ var Dog = {
+ new: function(name) {
+ var instance = Object.create(this);
+ this.initialize.apply(instance, arguments);
+ return instance;
+ },
+ initialize: function initialize(name) {
+ this.name = name;
+ },
+ type: 'dog',
+ bark: function bark() {
+ return 'Ruff! Ruff!'
+ }
+ };
+ var fluffy = Dog.new('fluffy');
+
+
+ var Pet = Object.create(Dog);
+ Pet.initialize = function initialize(name, breed) {
+ Dog.initialize.call(this, name);
+ this.breed = breed;
+ };
+ Pet.call = function call(name) {
+ return this.name === name ? this.bark() : '';
+ };
+
+While this small trick solves some readability issues, there are still more. To
+address them this module exports `Base` exemplar with few methods predefined:
+
+ var Dog = Base.extend({
+ initialize: function initialize(name) {
+ this.name = name;
+ },
+ type: 'dog',
+ bark: function bark() {
+ return 'Ruff! Ruff!'
+ }
+ });
+
+ var Pet = Dog.extend({
+ initialize: function initialize(name, breed) {
+ Dog.initialize.call(this, name);
+ this.breed = breed;
+ },
+ function call(name) {
+ return this.name === name ? this.bark() : '';
+ }
+ });
+
+ var fluffy = Dog.new('fluffy');
+ dog.bark(); // 'Ruff! Ruff!'
+ Dog.isPrototypeOf(fluffy); // true
+ Pet.isPrototypeOf(fluffy); // true
+
+### Composition ###
+
+Even though (single) inheritance is very powerful it's not always enough.
+Sometimes it's more useful suitable to define reusable pieces of functionality
+and then compose bigger pieces out of them:
+
+ var HEX = Base.extend({
+ hex: function hex() {
+ return '#' + this.color
+ }
+ })
+
+ var RGB = Base.extend({
+ red: function red() {
+ return parseInt(this.color.substr(0, 2), 16)
+ },
+ green: function green() {
+ return parseInt(this.color.substr(2, 2), 16)
+ },
+ blue: function blue() {
+ return parseInt(this.color.substr(4, 2), 16)
+ }
+ })
+
+ var CMYK = Base.extend(RGB, {
+ black: function black() {
+ var color = Math.max(Math.max(this.red(), this.green()), this.blue())
+ return (1 - color / 255).toFixed(4)
+ },
+ magenta: function magenta() {
+ var K = this.black();
+ return (((1 - this.green() / 255).toFixed(4) - K) / (1 - K)).toFixed(4)
+ },
+ yellow: function yellow() {
+ var K = this.black();
+ return (((1 - this.blue() / 255).toFixed(4) - K) / (1 - K)).toFixed(4)
+ },
+ cyan: function cyan() {
+ var K = this.black();
+ return (((1 - this.red() / 255).toFixed(4) - K) / (1 - K)).toFixed(4)
+ }
+ })
+
+ // Composing `Color` prototype out of reusable components:
+ var Color = Base.extend(HEX, RGB, CMYK, {
+ initialize: function initialize(color) {
+ this.color = color
+ }
+ })
+
+ var pink = Color.new('FFC0CB')
+ // RGB
+ pink.red() // 255
+ pink.green() // 192
+ pink.blue() // 203
+
+ // CMYK
+ pink.magenta() // 0.2471
+ pink.yellow() // 0.2039
+ pink.cyan() // 0.0000
+
+### Combining composition & inheritance ###
+
+Also it's easy to mix composition with inheritance:
+
+ var Pixel = Color.extend({
+ initialize: function initialize(x, y, color) {
+ Color.initialize.call(this, color)
+ this.x = x
+ this.y = y
+ },
+ toString: function toString() {
+ return this.x + ':' + this.y + '@' + this.hex()
+ }
+ });
+
+ var pixel = Pixel.new(11, 23, 'CC3399');
+ pixel.toString() // 11:23@#CC3399
+ Pixel.isPrototypeOf(pixel) // true
+
+ // Pixel instances inhertis from `Color`
+ Color.isPrototypeOf(pixel); // true
+
+ // In fact `Pixel` itself inherits from `Color`, remember just simple and
+ // pure prototypal inheritance where object inherit from objects.
+ Color.isPrototypeOf(Pixel); // true
+
+### Classes ###
+
+Module exports `Class` function. `Class` takes argument of exemplar object
+extending `Base` and returns `constructor` function that can be used for
+simulating classes defined by given exemplar.
+
+ var CPixel = Class(Pixel);
+ var pixel = CPixel(11, 12, '000000');
+ pixel instanceof CPixel // true
+ Pixel.prototypeOf(pixel); // true
+
+ // Use of `new` is optional, but possible.
+ var p2 = CPixel(17, 2, 'cccccc');
+ p2 instanceof CPixel // true
+ p2.prototypeOf(pixel); // true
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/byte-streams.md b/tools/addon-sdk-1.7/packages/api-utils/docs/byte-streams.md
new file mode 100644
index 0000000..1238cd8
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/byte-streams.md
@@ -0,0 +1,68 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Drew Willcoxon [adw@mozilla.com] -->
+<!-- edited by Noelle Murata [fiveinchpixie@gmail.com] -->
+
+The `byte-streams` module provides streams for reading and writing bytes.
+
+<api name="ByteReader">
+@class
+<api name="ByteReader">
+@constructor
+ Creates a binary input stream that reads bytes from a backing stream.
+@param inputStream {stream}
+ The backing stream, an <a href="http://mxr.mozilla.org/mozilla-central/
+source/xpcom/io/nsIInputStream.idl"><code>nsIInputStream</code></a>.
+</api>
+<api name="closed">
+@property {boolean}
+ True if the stream is closed.
+</api>
+
+<api name="close">
+@method
+ Closes both the stream and its backing stream. If the stream is already
+ closed, an exception is thrown.
+</api>
+
+<api name="read">
+@method
+ Reads a string from the stream. If the stream is closed, an exception is
+ thrown.
+@param [numBytes] {number}
+ The number of bytes to read. If not given, the remainder of the entire stream
+ is read.
+@returns {string}
+ A string containing the bytes read. If the stream is at the end, returns the
+ empty string.
+</api>
+</api>
+
+<api name="ByteWriter">
+@class
+<api name="ByteWriter">
+@constructor
+ Creates a binary output stream that writes bytes to a backing stream.
+@param outputStream {stream}
+ The backing stream, an <a href="http://mxr.mozilla.org/mozilla-central/
+source/xpcom/io/nsIOutputStream.idl"><code>nsIOutputStream</code></a>.
+</api>
+<api name="closed">
+@property {boolean}
+ True if the stream is closed.
+</api>
+<api name="close">
+@method
+ Closes both the stream and its backing stream. If the stream is already
+ closed, an exception is thrown.
+</api>
+<api name="write">
+@method
+ Writes a string to the stream. If the stream is closed, an exception is
+ thrown.
+@param str {string}
+ The string to write.
+</api>
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/collection.md b/tools/addon-sdk-1.7/packages/api-utils/docs/collection.md
new file mode 100644
index 0000000..1e557c6
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/collection.md
@@ -0,0 +1,77 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Drew Willcoxon [adw@mozilla.com] -->
+<!-- edited by Noelle Murata [fiveinchpixie@gmail.com] -->
+
+The `collection` module provides a simple list-like class and utilities for
+using it. A collection is ordered, like an array, but its items are unique,
+like a set.
+
+<api name="Collection">
+@class
+A collection object provides for...in-loop iteration. Items are yielded in the
+order they were added. For example, the following code...
+
+ var collection = require("collection");
+ var c = new collection.Collection();
+ c.add(1);
+ c.add(2);
+ c.add(3);
+ for (item in c)
+ console.log(item);
+
+... would print this to the console:
+
+<pre>
+ 1
+ 2
+ 3
+</pre>
+
+Iteration proceeds over a copy of the collection made before iteration begins,
+so it is safe to mutate the collection during iteration; doing so does not
+affect the results of the iteration.
+
+<api name="Collection">
+@constructor
+Creates a new collection. The collection is backed by an array.
+@param [array] {array}
+If *array* is given, it will be used as the backing array. This way the caller
+can fully control the collection. Otherwise a new empty array will be used, and
+no one but the collection will have access to it.
+</api>
+<api name="length">
+@property {number}
+The number of items in the collection array.
+</api>
+<api name="add">
+@method
+Adds a single item or an array of items to the collection. Any items already
+contained in the collection are ignored.
+@param itemOrItems {object} An item or array of items.
+@returns {Collection} The Collection.
+</api>
+<api name="remove">
+@method
+Removes a single item or an array of items from the collection. Any items not
+contained in the collection are ignored.
+@param itemOrItems {object} An item or array of items.
+@returns {Collection} The Collection.
+</api>
+</api>
+
+<api name="addCollectionProperty">
+@function
+Adds a collection property to the given object. Setting the property to a
+scalar value empties the collection and adds the value. Setting it to an array
+empties the collection and adds all the items in the array.
+@param object {object}
+The property will be defined on this object.
+@param propName {string}
+The name of the property.
+@param [backingArray] {array}
+If given, this will be used as the collection's backing array.
+</api>
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/content.md b/tools/addon-sdk-1.7/packages/api-utils/docs/content.md
new file mode 100644
index 0000000..1c25eb4
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/content.md
@@ -0,0 +1,15 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Irakli Gozalishvili [gozala@mozilla.com] -->
+
+The `content` module exports three different traits [Loader][], [Worker][] and
+[Symbiont][]. None of this traits is intended to be used directly by programs.
+Rather, they are intended to be used by other modules that provide high
+level APIs to programs or libraries.
+
+[Loader]:packages/api-utils/content/loader.html
+[Worker]:packages/api-utils/content/worker.html
+[Symbiont]:packages/api-utils/content/symbiont.html
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/content/loader.md b/tools/addon-sdk-1.7/packages/api-utils/docs/content/loader.md
new file mode 100644
index 0000000..a460476
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/content/loader.md
@@ -0,0 +1,92 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Irakli Gozalishvili [gozala@mozilla.com] -->
+
+Loader is base trait and it provides set of core properties and associated
+validations. Trait is useful for all the compositions providing high level
+APIs for creating JavaScript contexts that can access web content.
+
+Loader is composed from the
+[EventEmitter](packages/api-utils/events.html) trait, therefore
+instances of Loader and their descendants expose all the public properties
+exposed by EventEmitter along with additional public properties:
+
+Value changes on all of the above mentioned properties emit `propertyChange`
+events on an instances.
+
+**Example:**
+
+The following code creates a wrapper on hidden frame that reloads a web page
+in frame every time `contentURL` property is changed:
+
+ var hiddenFrames = require("hidden-frame");
+ var { Loader } = require("content");
+ var PageLoader = Loader.compose({
+ constructor: function PageLoader(options) {
+ options = options || {};
+ if (options.contentURL)
+ this.contentURL = options.contentURL;
+ this.on('propertyChange', this._onChange = this._onChange.bind(this));
+ let self = this;
+ hiddenFrames.add(hiddenFrames.HiddenFrame({
+ onReady: function onReady() {
+ let frame = self._frame = this.element;
+ self._emit('propertyChange', { contentURL: self.contentURL });
+ }
+ }));
+ },
+ _onChange: function _onChange(e) {
+ if ('contentURL' in e)
+ this._frame.setAttribute('src', this._contentURL);
+ }
+ });
+
+<api name="Loader">
+@class
+<api name="contentScriptFile">
+@property {array}
+The local file URLs of content scripts to load. Content scripts specified by
+this property are loaded *before* those specified by the `contentScript`
+property.
+</api>
+
+<api name="contentScript">
+@property {array}
+The texts of content scripts to load. Content scripts specified by this
+property are loaded *after* those specified by the `contentScriptFile` property.
+</api>
+
+<api name="contentScriptWhen">
+@property {string}
+When to load the content scripts. This may take one of the following
+values:
+
+* "start": load content scripts immediately after the document
+element for the page is inserted into the DOM, but before the DOM content
+itself has been loaded
+* "ready": load content scripts once DOM content has been loaded,
+corresponding to the
+[DOMContentLoaded](https://developer.mozilla.org/en/Gecko-Specific_DOM_Events)
+event
+* "end": load content scripts once all the content (DOM, JS, CSS,
+images) for the page has been loaded, at the time the
+[window.onload event](https://developer.mozilla.org/en/DOM/window.onload)
+fires
+
+</api>
+
+<api name="contentURL">
+@property {string}
+The URL of the content loaded.
+</api>
+
+<api name="allow">
+@property {object}
+Permissions for the content, with the following keys:
+@prop script {boolean}
+ Whether or not to execute script in the content. Defaults to true.
+</api>
+</api>
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/content/proxy.md b/tools/addon-sdk-1.7/packages/api-utils/docs/content/proxy.md
new file mode 100644
index 0000000..095e8ff
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/content/proxy.md
@@ -0,0 +1,241 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Alexandre Poirot [apoirot@mozilla.com] -->
+
+Content scripts need access to the DOM of the pages they are attached to.
+However, those pages should be considered to be hostile environments: we
+have no control over any other scripts loaded by the web page that may be
+executing in the same context. If the content scripts and scripts loaded
+by the web page were to access the same DOM objects, there are two possible
+security problems:
+
+First, a malicious page might redefine functions and properties of DOM
+objects so they don't do what the add-on expects. For example, if a
+content script calls `document.getElementById()` to retrieve a DOM
+element, then a malicious page could redefine its behavior to return
+something unexpected:
+
+<pre><code>
+// If the web document contains the following script:
+document.getElementById = function (str) {
+ // Overload indexOf method of all string instances
+ str.__proto__.indexOf = function () {return -1;};
+ // Overload toString method of all object instances
+ str.__proto__.__proto__.toString = function () {return "evil";};
+};
+// After the following line, the content script will be compromised:
+var node = document.getElementById("element");
+// Then your content script is totally out of control.
+</code></pre>
+
+Second, changes the content script made to the DOM objects would be visible
+to the page, leaking information to it.
+
+The general approach to fixing these problems is to wrap DOM objects in
+[`XrayWrappers`](https://developer.mozilla.org/en/XPCNativeWrapper)
+(also know as `XPCNativeWrapper`). This guarantees that:
+
+* when the content script accesses DOM properties and functions it gets the
+original native version of them, ignoring any modifications made by the web
+page
+* changes to the DOM made by the content script are not visible to scripts
+running in the page.
+
+However, `XrayWrapper` has some limitations and bugs, which break many
+popular web frameworks. In particular, you can't:
+
+* define attributes like `onclick`: you have to use `addEventListener` syntax
+* overload native methods on DOM objects, like this:
+<pre><code>
+proxy.addEventListener = function () {};
+</code></pre>
+* access named elements using properties like `window[framename]` or
+`document[formname]`
+* use some other features that have bugs in the `XrayWrapper`
+implementation, like `mozMatchesSelector`
+
+The `proxy` module uses `XrayWrapper` in combination with the
+experimental
+[Proxy API](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Proxy)
+to address both the security vulnerabilities of content scripts and the
+limitations of `XrayWrapper`.
+
+<pre>
+ /--------------------\ /------------------------\
+ | Web document | | Content script sandbox |
+ | http://mozilla.org | | data/worker.js |
+ | | require('content-proxy'). | |
+ | window >-----------|- create(window) -|-> window |
+ \--------------------/ \------------------------/
+</pre>
+
+
+## The Big Picture ##
+
+The implementation defines two different kinds of proxy:
+
+ 1. Content script proxies that wrap DOM objects that are exposed to
+ content scripts as described above.
+ 2. XrayWrapper proxies that wrap objects from content scripts before handing
+ them over to XrayWrapper functions. These proxies are internal
+ and are not exposed to content scripts or document content.
+
+<pre>
+ /--------------------\ /------------------------\
+ | Web document | | Content script sandbox |
+ | http://mozilla.org | | data/worker.js |
+ | | /-------|-> myObject = {} |
+ | | /----------------v--\ | |
+ | | | XrayWrapper Proxy | | - document |
+ | | \---------v---------/ \----^-------------------/
+ | | v |
+ | | /-------------\ /----------\ |
+ | - document >-------|->| XrayWrapper |<-| CS proxy |-/
+ \--------------------/ \-------------/ \----------/
+</pre>
+
+Everything begins with a single call to the `create` function exported by the
+content-proxy module:
+
+ // Retrieve the unwrapped reference to the current web page window object
+ var win = gBrowser.contentDocument.defaultView.wrappedJSObject;
+ // Or in addon sdk style
+ var win = require("tab-browser").activeTab.linkedBrowser.contentWindow.wrappedJSObject;
+ // Now create a content script proxy for the window object
+ var windowProxy = require("api-utils/content/content-proxy").create(win);
+
+ // We finally use this window object as sandbox prototype,
+ // so that all web page globals are accessible in CS too:
+ var contentScriptSandbox = new Cu.Sandbox(win, {
+ sandboxPrototype: windowProxy
+ });
+
+Then all other proxies are created from this one. Attempts to access DOM
+attributes of this proxy are trapped, and the proxy constructs and returns
+content script proxies for those attributes:
+
+ // For example, if you simply do this:
+ var document = window.document;
+ // accessing the `document` attribute will be trapped by the `window` content script
+ // proxy, and that proxy will that create another content script proxy for `document`
+
+So the main responsibility of the content script proxy implementation is to
+ensure that we always return content script proxies to the content script.
+
+## Internal Implementation ##
+
+Each content script proxy keeps a reference to the `XrayWrapper` that enables
+it to be sure of calling native DOM methods.
+
+There are two internal functions to convert between content script proxy
+values and `XrayWrapper` values.
+
+1. __`wrap`__ takes an XrayWrapper value and wraps it in a content script
+proxy if needed.
+ This method is called when:
+ * a content script accesses an attribute of a content script proxy.
+ * XrayWrapper code calls a callback function defined in the content
+script, so that arguments passed into the function by the XrayWrapper are
+converted into content script proxies. For example, if a content script
+calls `addEventListener`, then the listener function will expect any arguments
+to be content script proxies.
+<br/><br/>
+2. __`unwrap`__ takes an object coming from the content script context and:
+ * if the object is a content script proxy, unwraps it back to an
+XrayWrapper reference
+ * if the object is not a content script proxy, wraps it in an XrayWrapper
+proxy.
+<br/><br/>
+This means we can call a XrayWrapper method either with:
+
+ * a raw XrayWrapper object.
+
+ // The following line doesn't work if child is a content script proxy,
+ // it has to be a raw XrayWrapper reference
+ xrayWrapper.appendChild(child)
+
+ * an XrayWrapper proxy when you pass a custom object from the content
+script context.
+
+ var myListener = {
+ handleEvent: function(event) {
+ // `event` should be a content script proxy
+ }
+ };
+ // `myListener` has to be another kind of Proxy: XrayWrapper proxy,
+ // that aims to catch the call to `handleEvent` in order to wrap its
+ // arguments in a content script proxy.
+ xrayWrapper.addEventListener("click", myListener, false);
+
+
+## Stack Traces ##
+
+The following code:
+
+ function listener(event) {
+
+ }
+ csProxy.addEventListener("message", listener, false);
+
+generates the following internal calls:
+
+ -> CS Proxy:: get("addEventListener")
+ -> wrap(xrayWrapper.addEventListener)
+ -> NativeFunctionWrapper(xrayWrapper.addEventListener)
+ // NativeFunctionWrapper generates:
+ function ("message", listener, false) {
+ return xraywrapper.addEventListener("message", unwrap(listener), false);
+ }
+ -> unwrap(listener)
+ -> ContentScriptFunctionWrapper(listener)
+ // ContentScriptFunctionWrapper generates:
+ function (event) {
+ return listener(wrap(event));
+ }
+
+<br>
+
+ // First, create an object from content script context
+ var myListener = {
+ handleEvent: function (event) {
+
+ }
+ };
+ // Then, pass this object as an argument to a CS proxy method
+ window.addEventListener("message", myListener, false);
+
+ // Generates the following internal calls:
+ -> CS Proxy:: get("addEventListener")
+ -> wrap(xrayWrapper.addEventListener)
+ -> NativeFunctionWrapper(xrayWrapper.addEventListener)
+ // Generate the following function:
+ function ("message", myListener, false) {
+ return xraywrapper.addEventListener("message", unwrap(myListener), false);
+ }
+ -> unwrap(myListener)
+ -> ContentScriptObjectWrapper(myListener)
+ // Generate an XrayWrapper proxy and give it to xrayWrapper method.
+ // Then when native code fires an event, the proxy will catch it:
+ -> XrayWrapper Proxy:: get("handleEvent")
+ -> unwrap(myListener.handleEvent)
+ -> ContentScriptFunctionWrapper(myListener.handleEvent)
+ // Generate following function:
+ function (event) {
+ return myListener.handleEvent(wrap(event));
+ }
+
+
+<api name="create">
+@function
+ Create a content script proxy. <br/>
+ Doesn't create a proxy if we are not able to create a XrayWrapper for
+ this object: for example, if the object comes from system principal.
+
+@param object {Object}
+ The object to proxify.
+
+@returns {Object}
+ A content script proxy that wraps `object`.
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/content/symbiont.md b/tools/addon-sdk-1.7/packages/api-utils/docs/content/symbiont.md
new file mode 100644
index 0000000..1ff7dd1
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/content/symbiont.md
@@ -0,0 +1,140 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Myk Melez [myk@mozilla.org] -->
+<!-- contributed by Irakli Gozalishvili [gozala@mozilla.com] -->
+
+
+This module is not intended to be used directly by programs. Rather, it is
+intended to be used by other modules that provide APIs to programs.
+
+
+This module exports `Symbiont` trait that can be used for creating JavaScript
+contexts that can access web content in host application frames (i.e. XUL
+`<iframe>` and `<browser>` elements) and communicate with programs via
+asynchronous JSON pipes. It is useful in the construction of APIs that
+are compatible with the execution model codenamed "electrolysis" in which
+programs run in separate processes from web content.
+
+Introduction
+------------
+
+`Symbiont` constructs a content symbiont for a given frame, it loads the
+specified contentURL and scripts into it, and plumbs an asynchronous
+JSON pipe between the content symbiont object and the content symbiont
+context. If frame is not provided hidden frame will be created.
+
+Examples
+--------
+
+ var { Symbiont } = require('content');
+ var Thing = Symbiont.resolve({ constructor: '_init' }).compose({
+ constructor: function Thing(options) {
+ // `getMyFrame` returns the host application frame in which
+ // the page is loaded.
+ this._frame = getMyFrame();
+ this._init(options)
+ }
+ });
+
+See the [panel][] module for a real-world example of usage of this module.
+
+[panel]:packages/addon-kit/panel.html
+
+Reference
+---------
+
+<api name="Symbiont">
+@class
+Symbiont is composed from the [Worker][] trait, therefore instances
+of Symbiont and their descendants expose all the public properties
+exposed by [Worker][] along with additional public properties that
+are listed below:
+
+[Worker]:packages/api-utils/content/worker.html
+
+<api name="Symbiont">
+@constructor
+Creates a content symbiont.
+@param options {object}
+ Options for the constructor. Includes all the keys that
+the [Worker](packages/api-utils/content/worker.html)
+constructor accepts and a few more:
+
+ @prop [frame] {object}
+ The host application frame in which the page is loaded.
+ If frame is not provided hidden one will be created.
+ @prop [contentScriptWhen="end"] {string}
+ When to load the content scripts. This may take one of the following
+ values:
+
+ * "start": load content scripts immediately after the document
+ element for the page is inserted into the DOM, but before the DOM content
+ itself has been loaded
+ * "ready": load content scripts once DOM content has been loaded,
+ corresponding to the
+ [DOMContentLoaded](https://developer.mozilla.org/en/Gecko-Specific_DOM_Events)
+ event
+ * "end": load content scripts once all the content (DOM, JS, CSS,
+ images) for the page has been loaded, at the time the
+ [window.onload event](https://developer.mozilla.org/en/DOM/window.onload)
+ fires
+
+ This property is optional and defaults to "end".
+
+ @prop [allow] {object}
+ Permissions for the content, with the following keys:
+ @prop [script] {boolean}
+ Whether or not to execute script in the content. Defaults to true.
+ Optional.
+ Optional.
+</api>
+
+<api name="contentScriptFile">
+@property {array}
+The local file URLs of content scripts to load. Content scripts specified by
+this property are loaded *before* those specified by the `contentScript`
+property.
+</api>
+
+<api name="contentScript">
+@property {array}
+The texts of content scripts to load. Content scripts specified by this
+property are loaded *after* those specified by the `contentScriptFile` property.
+</api>
+
+<api name="contentScriptWhen">
+@property {string}
+When to load the content scripts. This may have one of the following
+values:
+
+* "start": load content scripts immediately after the document
+element for the page is inserted into the DOM, but before the DOM content
+itself has been loaded
+* "ready": load content scripts once DOM content has been loaded,
+corresponding to the
+[DOMContentLoaded](https://developer.mozilla.org/en/Gecko-Specific_DOM_Events)
+event
+* "end": load content scripts once all the content (DOM, JS, CSS,
+images) for the page has been loaded, at the time the
+[window.onload event](https://developer.mozilla.org/en/DOM/window.onload)
+fires
+
+</api>
+
+<api name="contentURL">
+@property {string}
+The URL of the content loaded.
+</api>
+
+<api name="allow">
+@property {object}
+Permissions for the content, with a single boolean key called `script` which
+defaults to true and indicates whether or not to execute scripts in the
+content.
+</api>
+
+</api>
+
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/content/worker.md b/tools/addon-sdk-1.7/packages/api-utils/docs/content/worker.md
new file mode 100644
index 0000000..b3e17ea
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/content/worker.md
@@ -0,0 +1,130 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Irakli Gozalishvili [gozala@mozilla.com] -->
+
+This module exports the `Worker` trait, which may be used to construct objects
+implementing the [Worker][] interface defined by the W3C, with minor
+differences.
+
+Content workers are message-passing facilities for communication between
+[content scripts](dev-guide/guides/content-scripts/index.html) and the main
+add-on code.
+
+It is important to note that unlike "web workers," these workers run in the
+same process as web content and browser chrome, so code within workers can
+block the UI.
+
+[Worker]:http://www.w3.org/TR/workers/#worker
+
+<api name="Worker">
+@class
+Worker is composed from the [EventEmitter][] trait, therefore instances
+of Worker and their descendants expose all the public properties
+exposed by [EventEmitter][] along with additional public properties that
+are listed below.
+
+**Example**
+
+ var workers = require("content/worker");
+ let worker = workers.Worker({
+ window: require("window-utils").activeWindow,
+ contentScript:
+ "self.port.on('hello', function(name) { " +
+ " self.port.emit('response', window.location); " +
+ "});"
+ });
+ worker.port.emit("hello", { name: "worker"});
+ worker.port.on("response", function (location) {
+ console.log(location);
+ });
+
+[EventEmitter]:packages/api-utils/events.html
+
+<api name="Worker">
+@constructor
+Creates a content worker.
+@param options {object}
+Options for the constructor, with the following keys:
+ @prop window {object}
+ The content window to create JavaScript sandbox for communication with.
+ @prop [contentScriptFile] {string,array}
+ The local file URLs of content scripts to load. Content scripts specified
+ by this option are loaded *before* those specified by the `contentScript`
+ option. Optional.
+ @prop [contentScript] {string,array}
+ The texts of content scripts to load. Content scripts specified by this
+ option are loaded *after* those specified by the `contentScriptFile` option.
+ Optional.
+ @prop [onMessage] {function}
+ Functions that will registered as a listener to a 'message' events.
+ @prop [onError] {function}
+ Functions that will registered as a listener to an 'error' events.
+</api>
+
+<api name="port">
+@property {EventEmitter}
+[EventEmitter](packages/api-utils/events.html) object that allows you to:
+
+* send customized messages to the worker using the `port.emit` function
+* receive events from the worker using the `port.on` function
+
+</api>
+
+<api name="postMessage">
+@method
+Asynchronously emits `"message"` events in the enclosed worker, where content
+script was loaded.
+@param data {number,string,JSON}
+The data to send. Must be stringifiable to JSON.
+</api>
+
+<api name="destroy">
+@method
+Destroy the worker by removing the content script from the page and removing
+all registered listeners. A `detach` event is fired just before removal.
+</api>
+
+<api name="url">
+@property {string}
+The URL of the content.
+</api>
+
+<api name="tab">
+@property {object}
+If this worker is attached to a content document, returns the related
+[tab](packages/addon-kit/tabs.html).
+</api>
+
+<api name="message">
+@event
+This event allows the content worker to receive messages from its associated
+content scripts. Calling the `self.postMessage()` function from a content
+script will asynchronously emit the `message` event on the corresponding
+worker.
+
+@argument {value}
+The event listener is passed the message, which must be a
+<a href = "dev-guide/guides/content-scripts/using-port.html#json_serializable">JSON-serializable value</a>.
+</api>
+
+<api name="error">
+@event
+This event allows the content worker to react to an uncaught runtime script
+error that occurs in one of the content scripts.
+
+@argument {Error}
+The event listener is passed a single argument which is an
+[Error](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error)
+object.
+</api>
+
+<api name="detach">
+@event
+This event is emitted when the document associated with this worker is unloaded
+or the worker's `destroy()` method is called.
+</api>
+
+</api>
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/cortex.md b/tools/addon-sdk-1.7/packages/api-utils/docs/cortex.md
new file mode 100644
index 0000000..afae8cb
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/cortex.md
@@ -0,0 +1,160 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+
+## Property Encapsulation ##
+
+In JavaScript it is not possible to create properties that have limited or
+controlled accessibility. It is possible to create non-enumerable and
+non-writable properties, but still they can be discovered and accessed.
+Usually so called "closure capturing" is used to encapsulate such properties
+in lexical scope:
+
+ function Foo() {
+ var _secret = 'secret';
+ this.hello = function hello() {
+ return 'Hello ' + _secret;
+ }
+ }
+
+This provides desired result, but has side effect of degrading code readability,
+especially with object-oriented programs. Another disadvantage with this pattern
+is that there is no immediate solution for inheriting access to the privates
+(illustrated by the following example):
+
+ function Derived() {
+ this.hello = function hello() {
+ return _secret;
+ }
+ this.bye = function bye() {
+ return _secret;
+ }
+ }
+ Derived.prototype = Object.create(Foo.prototype);
+
+## Facade Objects ##
+
+Alternatively constructor can returned facade objects - proxies to the
+instance's public properties:
+
+ function Foo() {
+ var foo = Object.create(Foo.prototype);
+ return {
+ bar: foo.hello.bind(foo);
+ }
+ }
+ Foo.prototype._secret = 'secret';
+ Foo.prototype.hello = function hello() {
+ return 'Hello ' + this._secret;
+ }
+
+ function Derived() {
+ var derived = Object.create(Derived.prototype);
+ return {
+ bar: derived.hello.bind(derived);
+ bye: derived.bye.bind(derived);
+ }
+ }
+ Derived.prototype = Object.create(Foo.prototype);
+ Derived.prototype.bye = function bye() {
+ return 'Bye ' + this._secret;
+ };
+
+While this solution solves given issue and provides proper encapsulation for
+both own and inherited private properties, it does not addresses following:
+
+ - Privates defined on the `prototype` can be compromised, since they are
+ accessible through the constructor (`Foo.prototype._secret`).
+ - Behavior of `instanceof` is broken, since `new Derived() instanceof Derived`
+ is going to evaluate to `false`.
+
+## Tamper Proofing with Property Descriptor Maps ##
+
+In ES5 new property descriptor maps were introduced, which can be used as a
+building blocks for defining reusable peace of functionality. To some degree
+they are similar to a `prototype` objects, and can be used so to define pieces
+of functionality that is considered to be private (In contrast to `prototype`
+they are not exposed by default).
+
+ function Foo() {
+ var foo = Object.create(Foo.prototype, FooDescriptor);
+ var facade = Object.create(Foo.prototype);
+ facade.hello = foo.hello.bind(foo);
+ return facade;
+ }
+ Foo.prototype.hello = function hello() {
+ return 'Hello ' + this._secret;
+ }
+ var FooDescriptor = {
+ _secret: { value: 'secret' };
+ }
+
+ function Derived() {
+ var derived = Object.create(Derived.prototype, DerivedDescriptor);
+ var facade = Object.create(Derived.prototype);
+ facade.hello = derived.hello.bind(derived);
+ facade.bye = derived.bye.bind(derived);
+ return facade;
+ }
+ Derived.prototype = Object.create(Foo.prototype);
+ Derived.prototype.bye = function bye() {
+ return 'Bye ' + this._secret;
+ };
+ DerivedDescriptor = {};
+
+ Object.keys(FooDescriptor).forEach(function(key) {
+ DerivedDescriptor[key] = FooDescriptor[key];
+ });
+
+## Cortex Objects ##
+
+Last approach solves all of the concerns, but adds complexity, verbosity
+and decreases code readability. Combination of `Cortex`'s and `Trait`'s
+will gracefully solve all these issues and keep code clean:
+
+ var Cortex = require('cortex').Cortex;
+ var Trait = require('light-traits').Trait;
+
+ var FooTrait = Trait({
+ _secret: 'secret',
+ hello: function hello() {
+ return 'Hello ' + this._secret;
+ }
+ });
+ function Foo() {
+ return Cortex(FooTrait.create(Foo.prototype));
+ }
+
+ var DerivedTrait = Trait.compose(FooTrait, Trait({
+ bye: function bye() {
+ return 'Bye ' + this._secret;
+ }
+ }));
+ function Derived() {
+ var derived = DerivedTrait.create(Derived.prototype);
+ return Cortex(derived);
+ }
+
+Function `Cortex` takes any object and returns a proxy for its public
+properties. By default properties are considered to be public if they don't
+start with `"_"`, but default behavior can be overridden if needed, by passing
+array of public property names as a second argument.
+
+## Gotchas ##
+
+`Cortex` is just a utility function to create a proxy object, and it does not
+solve the `prototype`-related issues highlighted earlier, but since traits make
+use of property descriptor maps instead of `prototype`s, there aren't any
+issues with using `Cortex` to wrap objects created from traits.
+
+If you want to use `Cortex` with an object that uses a `prototype` chain,
+however, you should either make sure you don't have any private properties
+in the prototype chain or pass the optional third `prototype` argument.
+
+In the latter case, the returned proxy will inherit from the given prototype,
+and the `prototype` chain of the wrapped object will be inaccessible.
+However, note that the behavior of the `instanceof` operator will vary,
+as `proxy instanceof Constructor` will return false even if the Constructor
+function's prototype is in the wrapped object's prototype chain.
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/cuddlefish.md b/tools/addon-sdk-1.7/packages/api-utils/docs/cuddlefish.md
new file mode 100644
index 0000000..27daf30
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/cuddlefish.md
@@ -0,0 +1,7 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+`cuddlefish` is the name of the SDK's module loader.
+
+This module still needs to be documented.
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/environment.md b/tools/addon-sdk-1.7/packages/api-utils/docs/environment.md
new file mode 100644
index 0000000..b5057a2
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/environment.md
@@ -0,0 +1,43 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+Module provides API to access, set and unset environment variables via exported
+`env` object.
+
+ var { env } = require('api-utils/environment');
+
+You can get the value of an environment variable, by accessing property that
+has name of desired variable:
+
+ var PATH = env.PATH;
+
+You can check existence of an environment variable by checking if property with
+such variable name exists:
+
+ console.log('PATH' in env); // true
+ console.log('FOO' in env); // false
+
+You can set value of an environment variable by setting a property:
+
+ env.FOO = 'foo';
+ env.PATH += ':/my/path/'
+
+You can unset environment variable by deleting a property:
+
+ delete env.FOO;
+
+## Limitations ##
+
+There is no way to enumerate existing environment variables, also `env`
+won't have any enumerable properties:
+
+ console.log(Object.keys(env)); // []
+
+Environment variable will be unset, show up as non-existing if it's set
+to `null`, `undefined` or `''`.
+
+ env.FOO = null;
+ console.log('FOO' in env); // false
+ env.BAR = '';
+ console.log(env.BAR); // undefined
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/errors.md b/tools/addon-sdk-1.7/packages/api-utils/docs/errors.md
new file mode 100644
index 0000000..98e94ac
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/errors.md
@@ -0,0 +1,42 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Drew Willcoxon [adw@mozilla.com] -->
+
+The `errors` module provides helpers for safely invoking user callbacks.
+
+<api name="catchAndLog">
+@function
+ Wraps a callback in a function that when invoked will catch and log any
+ exception thrown by the callback.
+@param callback {function}
+ The callback to wrap.
+@param [defaultResponse] {value}
+ This value will be returned by the wrapper if `callback` throws an exception.
+ If not given, `undefined` is used.
+@param [logException] {function}
+ When `callback` throws an exception, it will be passed to this function. If
+ not given, the exception is logged using `console.exception()`.
+@returns {function}
+ A function that will invoke `callback` when called. The return value of this
+ function is the return value of `callback` unless `callback` throws an
+ exception. In that case, `defaultResponse` is returned or `undefined` if
+ `defaultResponse` is not given.
+</api>
+
+<api name="catchAndLogProps">
+@function
+ Replaces methods of an object with wrapped versions of those methods returned
+ by `catchAndLog()`.
+@param object {object}
+ The object whose methods to replace.
+@param props {string,array}
+ The names of the methods of `object` to replace, either a string for a single
+ method or an array of strings for multiple methods.
+@param [defaultResponse] {value}
+ This value will be returned by any wrapper whose wrapped method throws an
+ exception. If not given, `undefined` is used.
+@param [logException] {function}
+ See `catchAndLog()`.
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/event/core.md b/tools/addon-sdk-1.7/packages/api-utils/docs/event/core.md
new file mode 100644
index 0000000..6ab3317
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/event/core.md
@@ -0,0 +1,51 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+Module provides core (low level) API for working with events in the SDK. This
+API is mainly for implementing higher level event APIs.
+
+Event `listener` may be registered on any (event `target`) object using
+provided `on` function:
+
+ var { on, once, off, emit } = require('api-utils/event/core');
+ var target = { name: 'target' };
+ on(target, 'message', function listener(event) {
+ console.log('hello ' + event);
+ });
+ on(target, 'data', console.log);
+
+Event of specific `type` may be emitted on any event `target` object using
+`emit` function. This will call all registered `listener`s for the given `type`
+on the given event `target` in the same order they were registered.
+
+ emit(target, 'message', 'event');
+ // info: 'hello event'
+ emit(target, 'data', { type: 'data' }, 'second arg');
+ // info: [Object object] 'second arg'
+
+Registered event listeners may be removed using `off` function:
+
+ off(target, 'message');
+ emit(target, 'message', 'bye');
+ // info: 'hello bye'
+
+Sometimes listener only cares about first event of specific `type`. To avoid
+hassles of removing such listeners there is convenient `once` function:
+
+ once(target, 'load', function() {
+ console.log('ready');
+ });
+ emit(target, 'load')
+ // info: 'ready'
+ emit(target, 'load')
+
+There are also convenient ways to remove registered listeners. All listeners of
+the specific type can be easily removed (only two argument must be passed):
+
+ off(target, 'message');
+
+Also, removing all registered listeners is possible (only one argument must be
+passed):
+
+ off(target);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/event/target.md b/tools/addon-sdk-1.7/packages/api-utils/docs/event/target.md
new file mode 100644
index 0000000..96feb79
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/event/target.md
@@ -0,0 +1,95 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+Provides an exemplar `EventTarget` object, that implements interface for
+adding removing event listeners of a specific type. `EventTarget` is a
+base of all objects in SDK on which events are emitted.
+
+### Instantiation
+
+It's easy to create event target objects, no special arguments are required.
+
+ const { EventTarget } = require('api-utils/event/target');
+ let target = EventTarget.new();
+
+For a convenience though optional `options` arguments may be used, in which
+case all the function properties with keys like: `onMessage`, `onMyEvent`...
+will be auto registered for associated `'message'`, `'myEvent'` events on
+the created instance. _All other properties of `options` will be ignored_.
+
+### Adding listeners
+
+`EventTarget` interface defines `on` method, that can be used to register
+event listeners on them for the given event type:
+
+ target.on('message', function onMessage(message) {
+ // Note: `this` pseudo variable is an event `target` unless
+ // intentionally overridden via `.bind()`.
+ console.log(message);
+ });
+
+Sometimes event listener may care only about very first event of specific
+`type`. `EventTarget` interface defines convenience method for adding one
+shot event listeners via method `once`. Such listeners are called only once
+next time event of the specified type is emitted:
+
+ target.once('ready', function onReady() {
+ // Do the thing once ready!
+ });
+
+### Removing listeners
+
+`EventTarget` interface defines API for unregistering event listeners, via
+`removeListener` method:
+
+ target.removeListener('message', onMessage);
+
+### Emitting events
+
+`EventTarget` interface intentionally does not defines an API for emitting
+events. In majority of cases party emitting events is different from party
+registering listeners. In order to emit events one needs to use `event/core`
+module instead:
+
+ let { emit } = require('api-utils/event/core');
+
+ target.on('hi', function(person) { console.log(person + 'tells hi'); });
+ emit(target, 'hi', 'Mark');
+ // info: 'Mark tells hi'
+
+For more details see **event/core** documentation.
+
+### More details
+
+Listeners registered during the event propagation (by one of the listeners)
+won't be triggered until next emit of the matching type:
+
+ let { emit } = require('api-utils/event/core');
+
+ target.on('message', function onMessage(message) {
+ console.log('listener trigerred');
+ target.on('message', function() {
+ console.log('nested listener triggered');
+ });
+ });
+
+ emit(target, 'message');
+ // info: 'listener trigerred'
+ emit(target, 'message');
+ // info: 'listener trigerred'
+ // info: 'nested listener trigerred'
+
+Exceptions in the listeners can be handled via `'error'` event listeners:
+
+ target.on('boom', function() {
+ throw Error('Boom!');
+ });
+ target.once('error', function(error) {
+ console.log('caught an error: ' + error.message);
+ });
+ emit(target, 'boom');
+ // info: caught an error: Boom!
+
+If there is no listener registered for `error` event or if it also throws
+exception then such exceptions are logged into a console.
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/events.md b/tools/addon-sdk-1.7/packages/api-utils/docs/events.md
new file mode 100644
index 0000000..76f9efd
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/events.md
@@ -0,0 +1,78 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+The `events` module provides base API for emitting events.
+
+This module is not intended to be used directly by programs. Rather, it is
+intended to be used by other modules that provide APIs to programs.
+
+<api name="EventEmitter">
+@class
+The EventEmitter is the base building block for all compositions that
+would need to broadcast data to multiple consumers.
+
+Please note that `EventEmitter` does not expose either a method for emitting
+events or a list of available event listeners as its public API. Obviously
+both are accessible but from the instance itself through the private API.
+<api name="EventEmitter">
+@constructor
+Creates an EventEmitter object.
+</api>
+
+<api name="on">
+@method
+Registers an event `listener` that will be called when events of
+specified `type` are emitted.
+
+If the `listener` is already registered for this `type`, a call to this
+method has no effect.
+
+If the event listener is being registered while an event is being processed,
+the event listener is not called during the current emit.
+
+**Example:**
+
+ // worker is instance of EventEmitter
+ worker.on('message', function (data) {
+ console.log('data received: ' + data)
+ });
+
+@param type {String}
+ The type of the event.
+@param listener {Function}
+ The listener function that processes the event.
+</api>
+
+<api name="once">
+@method
+Registers an event `listener` that will only be called once, the next time
+an event of the specified `type` is emitted.
+
+If the event listener is registered while an event of the specified `type`
+is being emitted, the event listener will not be called during the current
+emit.
+
+@param type {String}
+ The type of the event.
+@param listener {Function}
+ The listener function that processes the event.
+</api>
+
+<api name="removeListener">
+@method
+Unregisters an event `listener` for the specified event `type`.
+
+If the `listener` is not registered for this `type`, a call to this
+method has no effect.
+
+If an event listener is removed while an event is being processed, it is
+still triggered by the current emit. After it is removed, the event listener
+is never invoked again (unless registered again for future processing).
+
+@param type {String}
+ The type of the event.
+@param listener {Function}
+ The listener function that processes the event.
+</api>
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/file.md b/tools/addon-sdk-1.7/packages/api-utils/docs/file.md
new file mode 100644
index 0000000..9587353
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/file.md
@@ -0,0 +1,151 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Drew Willcoxon [adw@mozilla.com] -->
+<!-- contributed by Atul Varma [atul@mozilla.com] -->
+<!-- edited by Noelle Murata [fiveinchpixie@gmail.com] -->
+
+The `file` module provides access to the local filesystem.
+
+
+Paths
+-----
+
+Path specifications in this API are platform-specific. This means that on
+Windows paths are specified using the backslash path separator (`\`), and on
+Unix-like systems like Linux and OS X paths are specified using the forward
+slash path separator (`/`).
+
+If your add-on uses literal Windows-style path specifications with this API,
+your add-on likely won't work when users run it on Unix-like systems. Likewise,
+if your add-on uses literal Unix-style path specifications, it won't work for
+users on Windows.
+
+To ensure your add-on works for everyone, generate paths using the
+[`join`](packages/api-utils/file.html#join(...)) function. Unfortunately
+this API does not currently provide a way to obtain an absolute base path which
+you could then use with `join`. For now, you need to
+[`require("chrome")`](dev-guide/tutorials/chrome.html) and use the
+XPCOM directory service as described at
+[MDN](https://developer.mozilla.org/en/Code_snippets/File_I%2F%2FO#Getting_special_files).
+
+Note that if you do decide to hardcode Windows-style paths, be sure to escape
+backslashes in strings. For example, to specify the file at `C:\Users\Myk`, you
+need to use the string `"C:\\Users\\Myk"`, not `"C:\Users\Myk"`. You can read
+more about escaping characters in strings at
+[MDN](https://developer.mozilla.org/en/JavaScript/Guide/Values,_Variables,_and_Literals#Escaping_Characters).
+
+
+<api name="basename">
+@function
+ Returns the last component of the given path. For example,
+ `basename("/foo/bar/baz")` returns `"baz"`. If the path has no components,
+ the empty string is returned.
+@param path {string}
+ The path of a file.
+@returns {string}
+ The last component of the given path.
+</api>
+
+<api name="dirname">
+@function
+ Returns the path of the directory containing the given file. If the file is
+ at the top of the volume, the empty string is returned.
+@param path {string}
+ The path of a file.
+@returns {string}
+ The path of the directory containing the file.
+</api>
+
+<api name="exists">
+@function
+ Returns true if a file exists at the given path and false otherwise.
+@param path {string}
+ The path of a file.
+@returns {boolean}
+ True if the file exists and false otherwise.
+</api>
+
+<api name="join">
+@function
+ Takes a variable number of strings, joins them on the file system's path
+ separator, and returns the result.
+@param ... {strings}
+ A variable number of strings to join. The first string must be an absolute
+ path.
+@returns {string}
+ A single string formed by joining the strings on the file system's path
+ separator.
+</api>
+
+<api name="list">
+@function
+ Returns an array of file names in the given directory.
+@param path {string}
+ The path of the directory.
+@returns {array}
+ An array of file names. Each is a basename, not a full path.
+</api>
+
+<api name="mkpath">
+@function
+ Makes a new directory named by the given path. Any subdirectories that do not
+ exist are also created. `mkpath` can be called multiple times on the same
+ path.
+@param path {string}
+ The path to create.
+</api>
+
+<api name="open">
+@function
+ Returns a stream providing access to the contents of a file.
+@param path {string}
+ The path of the file to open.
+@param [mode] {string}
+ An optional string, each character of which describes a characteristic of the
+ returned stream. If the string contains `"r"`, the file is opened in
+ read-only mode. `"w"` opens the file in write-only mode. `"b"` opens the
+ file in binary mode. If `"b"` is not present, the file is opened in text
+ mode, and its contents are assumed to be UTF-8. If *`mode`* is not given,
+ `"r"` is assumed, and the file is opened in read-only text mode.
+@returns {stream}
+ If the file is opened in text read-only `mode`, a `TextReader` is returned,
+ and if text write-only mode, a `TextWriter` is returned. See
+ [`text-streams`](packages/api-utils/text-streams.html) for information on
+ these text stream objects. If the file is opened in binary read-only `mode`,
+ a `ByteReader` is returned, and if binary write-only mode, a `ByteWriter` is
+ returned. See
+ [`byte-streams`](packages/api-utils/byte-streams.html) for more
+ information on these byte stream objects. Opened files should always be
+ closed after use by calling `close` on the returned stream.
+</api>
+
+<api name="read">
+@function
+ Opens a file and returns a string containing its entire contents.
+@param path {string}
+ The path of the file to read.
+@param [mode] {string}
+ An optional string, each character of which describes a characteristic of the
+ returned stream. If the string contains `"b"`, the contents will be returned
+ in binary mode. If `"b"` is not present or `mode` is not given, the file
+ contents will be returned in text mode.
+@returns {string}
+ A string containing the file's entire contents.
+</api>
+
+<api name="remove">
+@function
+ Removes a file from the file system. To remove directories, use `rmdir`.
+@param path {string}
+ The path of the file to remove.
+</api>
+
+<api name="rmdir">
+@function
+ Removes a directory from the file system. If the directory is not empty, an
+ exception is thrown.
+@param path {string}
+ The path of the directory to remove.
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/frame/utils.md b/tools/addon-sdk-1.7/packages/api-utils/docs/frame/utils.md
new file mode 100644
index 0000000..c88d198
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/frame/utils.md
@@ -0,0 +1,53 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+The `frame/utils` module provides helper functions for working with platform
+internals like [frames](https://developer.mozilla.org/en/XUL/iframe) and
+[browsers](https://developer.mozilla.org/en/XUL/browser).
+
+### create
+
+Module exports `create` function that takes `nsIDOMDocument` of the
+[privileged document](https://developer.mozilla.org/en/Working_with_windows_in_chrome_code)
+and creates a `browser` element in it's `documentElement`:
+
+ let { open } = require('api-utils/window/utils');
+ let { create } = require('api-utils/frame/utils');
+ let window = open('data:text/html,Foo');
+ let frame = create(window.document);
+
+Optionally `create` can be passed set of `options` to configure created frame
+even further. Following options are supported:
+
+- `type`
+String that defines access type of the document loaded into it. Defaults to
+`'content'`. For more details and other possible values see
+[documentation on MDN](https://developer.mozilla.org/en/XUL/Attribute/browser.type)
+
+- `uri`
+URI of the document to be loaded into created frame. Defaults to `about:blank`.
+
+- `remote`
+If `true` separate process will be used for this frame, also in such case all
+the following options are ignored.
+
+- `allowAuth`
+Whether to allow auth dialogs. Defaults to `false`.
+
+- `allowJavascript`
+Whether to allow Javascript execution. Defaults to `false`.
+
+- `allowPlugins`
+Whether to allow plugin execution. Defaults to `false`.
+
+Execution of scripts may easily be enabled:
+
+ let { open } = require('api-utils/window/utils');
+ let { create } = require('api-utils/frame/utils');
+ let window = open('data:text/html,top');
+ let frame = create(window.document, {
+ uri: 'data:text/html,<script>alert("Hello")</script>',
+ allowJavascript: true
+ });
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/globals.md b/tools/addon-sdk-1.7/packages/api-utils/docs/globals.md
new file mode 100644
index 0000000..e6df8a8
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/globals.md
@@ -0,0 +1,100 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+Globals in this section are subject to change in the future and/or are likely
+to be of interest to SDK module developers, rather than add-on developers.
+
+## Components ##
+
+To access the infamous and powerful `Components` object, see the
+[Chrome Authority](dev-guide/tutorials/chrome.html) documentation.
+
+## \_\_url\_\_ ##
+
+The `__url__` global is a string identifying the URL from which the code has
+been retrieved. If the code has no identifiable URL, this value may be `null`.
+
+## packaging ##
+
+<span class="aside">
+For more information on packaging, see the [Package Specification][] appendix.
+</span>
+
+The `packaging` global contains methods and metadata related to
+the packages available in the current environment.
+
+<code>packaging.**getURLForData**(*path*)</code>
+
+Given a unix-style path relative to the calling package's `data`
+directory, returns an absolute URL to the file or directory.
+
+By "calling package", we mean the package in which the caller's source
+code resides.
+
+Thus, for example, if a package contains a resource at
+`data/mydata.dat` and a module at `lib/foo.js`, the module at
+`lib/foo.js` may make the following call to retrieve an absolute URL
+to `data/mydata.dat`:
+
+ var myDataURL = packaging.getURLForData("/mydata.dat");
+
+If the calling package has no `data` directory, an exception is
+thrown.
+
+## memory ##
+
+`memory` is an object that exposes functionality to track
+objects of interest and help diagnose and prevent memory leaks.
+
+<code>memory.**track**(*object*, [*bin*])</code>
+
+Marks *object* for being tracked, and categorizes it with the given
+bin name. If *bin* isn't specified, the memory tracker attempts to
+infer a bin name by first checking the object's
+`constructor.name`; if that fails or results in the generic
+`Object`, the stack is inspected and the name of the current
+function being executed&mdash;which is assumed to be a constructor
+function&mdash;is used. If that fails, then the object is placed in a
+bin named `generic`.
+
+<code>memory.**getObjects**([*bin*])</code>
+
+Returns an `Array` containing information about tracked objects
+that have been categorized with the given bin name. If *bin* isn't
+provided, information about all live tracked objects are returned.
+
+Each element of the array is an object with the following keys:
+
+<table>
+ <tr>
+ <td><code>weakref</code></td>
+ <td>A weak reference to the object being tracked. Call
+ <code>get()</code> on this object to retrieve its strong reference; if
+ a strong reference to the object no longer exists, <code>get()</code>
+ will return <code>null</code>.</td>
+ </tr>
+ <tr>
+ <td><code>created</code></td>
+ <td>A <code>Date</code> representing the date and time that
+ <code>memory.track()</code> was called on the object being
+ tracked.</td>
+ </tr>
+ <tr>
+ <td><code>filename</code></td>
+ <td>The name of the file that called <code>memory.track()</code> on
+ the object being tracked.</td>
+ </tr>
+ <tr>
+ <td><code>lineNo</code></td>
+ <td>The line number of the file that called
+ <code>memory.track()</code> on the object being tracked.</td>
+ </tr>
+</table>
+
+<code>memory.**getBins**()</code>
+
+Returns an `Array` containing the names of all bins that aren't
+currently empty.
+
+ [Package Specification]: dev-guide/package-spec.html \ No newline at end of file
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/hidden-frame.md b/tools/addon-sdk-1.7/packages/api-utils/docs/hidden-frame.md
new file mode 100644
index 0000000..9d16dfa
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/hidden-frame.md
@@ -0,0 +1,83 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Myk Melez [myk@mozilla.org] -->
+
+The `hidden-frame` module creates host application frames (i.e. XUL `<iframe>`
+elements) that are not displayed to the user. It is useful in the construction
+of APIs that load web content not intended to be directly seen or accessed
+by users, like `page-worker`. It is also useful in the construction of APIs
+that load web content for intermittent display, such as `panel`.
+
+This module is not intended to be used directly by programs. Rather, it is
+intended to be used by other modules that provide APIs to programs.
+
+Introduction
+------------
+
+The module exports a constructor function, `HiddenFrame`, and two other
+functions, `add` and `remove`.
+
+`HiddenFrame` constructs a new hidden frame. `add` registers a hidden frame,
+preparing it to load content. `remove` unregisters a frame, unloading any
+content that was loaded in it.
+
+Examples
+--------
+
+The following code creates a hidden frame, loads a web page into it, and then
+logs its title:
+
+ var hiddenFrames = require("hidden-frame");
+ let hiddenFrame = hiddenFrames.add(hiddenFrames.HiddenFrame({
+ onReady: function() {
+ this.element.contentWindow.location = "http://www.mozilla.org/";
+ let self = this;
+ this.element.addEventListener("DOMContentLoaded", function() {
+ console.log(self.element.contentDocument.title);
+ }, true, true);
+ }
+ }));
+
+See the `panel` module for a real-world example of usage of this module.
+
+Reference
+---------
+<api name="HiddenFrame">
+@class
+`HiddenFrame` objects represent hidden frames.
+<api name="HiddenFrame">
+@constructor
+Creates a hidden frame.
+@param options {object}
+ Options for the frame, with the following keys:
+ @prop onReady {function,array}
+ Functions to call when the frame is ready to load content. You must specify
+ an `onReady` callback and refrain from using the hidden frame until
+ the callback gets called, because hidden frames are not always ready to load
+ content the moment they are added.
+</api>
+
+<api name="add">
+@function
+Register a hidden frame, preparing it to load content.
+@param hiddenFrame {HiddenFrame} the frame to add
+</api>
+
+<api name="remove">
+@function
+Unregister a hidden frame, unloading any content that was loaded in it.
+@param hiddenFrame {HiddenFrame} the frame to remove
+</api>
+
+<api name="element">
+@property {DOMElement}
+The host application frame in which the page is loaded.
+</api>
+
+<api name="onReady">
+@property {array}
+Functions to call when the frame is ready to load content.
+</api>
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/httpd.md b/tools/addon-sdk-1.7/packages/api-utils/docs/httpd.md
new file mode 100644
index 0000000..3f131f9
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/httpd.md
@@ -0,0 +1,31 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+Provides an HTTP server written in JavaScript for the Mozilla platform, which
+can be used in unit tests.
+
+The most basic usage is:
+
+ var {startServerAsync} = require("httpd");
+ var srv = startServerAsync(port, basePath);
+ require("unload").when(function cleanup() {
+ srv.stop(function() { // you should continue execution from this point.
+ })
+ });
+
+This starts a server in background (assuming you're running this code in an
+application that has an event loop, such as Firefox). The server listens at
+http://localhost:port/ and serves files from the specified directory. You
+can serve static content or use SJS scripts, as described in documentation
+on developer.mozilla.org.
+
+You can also use `nsHttpServer` to start the server manually:
+
+ var {nsHttpServer} = require("httpd");
+ var srv = new nsHttpServer();
+ // further documentation on developer.mozilla.org
+
+See
+[HTTP server for unit tests](https://developer.mozilla.org/En/HTTP_server_for_unit_tests)
+for general information.
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/light-traits.md b/tools/addon-sdk-1.7/packages/api-utils/docs/light-traits.md
new file mode 100644
index 0000000..367a6a9
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/light-traits.md
@@ -0,0 +1,295 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+
+[Traits](http://en.wikipedia.org/wiki/Trait_%28computer_science%29) are a simple
+mechanism for structuring object-oriented programs. They represent reusable and
+composable building blocks of functionality that factor out the common
+attributes and behavior of objects.
+
+They are a more robust alternative to
+[mixins](http://en.wikipedia.org/wiki/Mixins) and
+[multiple inheritance](http://en.wikipedia.org/wiki/Multiple_inheritance),
+because name clashes must be explicitly resolved and composition is commutative
+and associative (i.e. the order of traits in a composition is irrelevant).
+
+Use traits to share functionality between similar objects without duplicating
+code or creating complex inheritance chains.
+
+## Trait Creation ##
+
+To create a trait, call the `Trait` constructor function exported by this
+module, passing it a JavaScript object that specifies the properties of the
+trait.
+
+ let Trait = require('light-traits').Trait;
+ let t = Trait({
+ foo: "foo",
+ bar: function bar() {
+ return "Hi!"
+ },
+ baz: Trait.required
+ });
+
+Traits can both provide and require properties. A *provided* property is a
+property for which the trait itself provides a value. A *required* property is a
+property that the trait needs in order to function correctly but for which
+it doesn't provide a value.
+
+Required properties must be provided by another trait or by an object with a
+trait. Creation of an object with a trait will fail if required properties are
+not provided. Specify a required property by setting the value of the property
+to `Trait.required`.
+
+## Object Creation ##
+
+Create objects with a single trait by calling the trait's `create` method. The
+method takes a single argument, the object to serve as the new object's
+prototype. If no prototype is specified, the new object's prototype will be
+`Object.prototype`.
+
+ let t = Trait({
+ foo: 'foo',
+ bar: 2
+ });
+ let foo1 = t.create();
+ let foo2 = t.create({ name: 'Super' });
+
+## Trait Composition ##
+
+Traits are designed to be composed with other traits to create objects with the
+properties of multiple traits. To compose an object with multiple traits, you
+first create a composite trait and then use it to create the object. A composite
+trait is a trait that contains all of the properties of the traits from which it
+is composed. In the following example, MagnitudeTrait is a composite trait.
+
+ let EqualityTrait = Trait({
+ equal: Trait.required,
+ notEqual: function notEqual(x) {
+ return !this.equal(x)
+ }
+ });
+
+ let ComparisonTrait = Trait({
+ less: Trait.required,
+ notEqual: Trait.required,
+ greater: function greater(x) {
+ return !this.less(x) && this.notEqual(x)
+ }
+ });
+
+ let MagnitudeTrait = Trait.compose(EqualityTrait, ComparisonTrait);
+
+<?xml version="1.0"?>
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xl="http://www.w3.org/1999/xlink" version="1.1" viewBox="-11 121 490 190" width="490px" height="190px">
+ <defs>
+ <marker orient="auto" overflow="visible" markerUnits="strokeWidth" id="SharpArrow_Marker" viewBox="-4 -4 10 8" markerWidth="10" markerHeight="8" color="black">
+ <g>
+ <path d="M 5 0 L -3 -3 L 0 0 L 0 0 L -3 3 Z" fill="currentColor" stroke="currentColor" stroke-width="1px"/>
+ </g>
+ </marker>
+ </defs>
+ <g stroke="none" stroke-opacity="1" stroke-dasharray="none" fill="none" fill-opacity="1">
+ <g>
+ <rect x="9" y="165.33334" width="141" height="14"/>
+ <rect x="9" y="165.33334" width="141" height="14" stroke="black" stroke-width="1px"/>
+ <text transform="translate(14 165.33334)" fill="black">
+ <tspan font-family="Helvetica" font-size="12" font-weight="500" x="0" y="11" textLength="47.373047">notEqual</tspan>
+ </text>
+ <rect x="9" y="151.33334" width="141" height="14"/>
+ <rect x="9" y="151.33334" width="141" height="14" stroke="black" stroke-width="1px"/>
+ <text transform="translate(14 151.33334)" fill="red">
+ <tspan font-family="Helvetica" font-size="12" font-weight="500" fill="red" x="0" y="11" textLength="29.361328">equal</tspan>
+ </text>
+ <rect x="9" y="137.33334" width="141" height="14"/>
+ <rect x="9" y="137.33334" width="141" height="14" stroke="black" stroke-width="1px"/>
+ <text transform="translate(14 137.33334)" fill="black">
+ <tspan font-family="Helvetica" font-size="12" font-weight="bold" x="38.49707" y="11" textLength="54.00586">EqualityTrait</tspan>
+ </text>
+ <rect x="9" y="273" width="141" height="14"/>
+ <rect x="9" y="273" width="141" height="14" stroke="black" stroke-width="1px"/>
+ <text transform="translate(14 273)" fill="black">
+ <tspan font-family="Helvetica" font-size="12" font-weight="500" x="0" y="11" textLength="38.021484">greater</tspan>
+ </text>
+ <rect x="9" y="259" width="141" height="14"/>
+ <rect x="9" y="259" width="141" height="14" stroke="black" stroke-width="1px"/>
+ <text transform="translate(14 259)" fill="red">
+ <tspan font-family="Helvetica" font-size="12" font-weight="500" fill="red" x="0" y="11" textLength="47.373047">notEqual</tspan>
+ </text>
+ <rect x="9" y="245" width="141" height="14"/>
+ <rect x="9" y="245" width="141" height="14" stroke="black" stroke-width="1px"/>
+ <text transform="translate(14 245)" fill="red">
+ <tspan font-family="Helvetica" font-size="12" font-weight="500" fill="red" x="0" y="11" textLength="21.339844">less</tspan>
+ </text>
+ <rect x="9" y="231" width="141" height="14"/>
+ <rect x="9" y="231" width="141" height="14" stroke="black" stroke-width="1px"/>
+ <text transform="translate(14 231)" fill="black">
+ <tspan font-family="Helvetica" font-size="12" font-weight="bold" x=".15332031" y="11" textLength="112.67578">ComparisonTrait</tspan>
+ </text>
+ <rect x="317.75" y="235.5" width="141" height="14"/>
+ <rect x="317.75" y="235.5" width="141" height="14" stroke="black" stroke-width="1px"/>
+ <text transform="translate(322.75 235.5)" fill="black">
+ <tspan font-family="Helvetica" font-size="12" font-weight="500" x="0" y="11" textLength="38.021484">greater</tspan>
+ </text>
+ <rect x="317.75" y="221.5" width="141" height="14"/>
+ <rect x="317.75" y="221.5" width="141" height="14" stroke="black" stroke-width="1px"/>
+ <text transform="translate(322.75 221.5)" fill="red">
+ <tspan font-family="Helvetica" font-size="12" font-weight="500" fill="red" x="0" y="11" textLength="21.339844">less</tspan>
+ </text>
+ <rect x="317.75" y="207.5" width="141" height="14"/>
+ <rect x="317.75" y="207.5" width="141" height="14" stroke="black" stroke-width="1px"/>
+ <text transform="translate(322.75 207.5)" fill="black">
+ <tspan font-family="Helvetica" font-size="12" font-weight="500" x="0" y="11" textLength="47.373047">notEqual</tspan>
+ </text>
+ <rect x="317.75" y="193.5" width="141" height="14"/>
+ <rect x="317.75" y="193.5" width="141" height="14" stroke="black" stroke-width="1px"/>
+ <text transform="translate(322.75 193.5)" fill="red">
+ <tspan font-family="Helvetica" font-size="12" font-weight="500" fill="red" x="0" y="11" textLength="29.361328">equal</tspan>
+ </text>
+ <rect x="317.75" y="179.5" width="141" height="14"/>
+ <rect x="317.75" y="179.5" width="141" height="14" stroke="black" stroke-width="1px"/>
+ <text transform="translate(322.75 179.5)" fill="black">
+ <tspan font-family="Helvetica" font-size="12" font-weight="bold" x="31.83789" y="11" textLength="67.32422">MagnitudeTrait</tspan>
+ </text>
+ <path d="M 150 248.83887 L 158.89999 248.83887 L 235.9 248.83887 L 235.9 224.66113 L 308.85 224.66113 L 310.85 224.66113" marker-end="url(#SharpArrow_Marker)" stroke="black" stroke-linecap="butt" stroke-linejoin="miter" stroke-width="1px"/>
+ <path d="M 150 171.15845 L 158.89999 171.15845 L 233.9 171.15845 L 233.9 201.6749 L 308.85 201.6749 L 310.85 201.6749" marker-end="url(#SharpArrow_Marker)" stroke="black" stroke-linecap="butt" stroke-linejoin="miter" stroke-width="1px"/>
+ </g>
+ </g>
+</svg>
+
+## Trait Resolution ##
+
+Composite traits have conflicts when two of the traits in the composition
+provide properties with the same name but different values (when compared using
+the `===` strict equality operator). In the following example, `TC` has a
+conflict because `T1` and `T2` both define a `foo` property:
+
+ let T1 = Trait({
+ foo: function () {
+ // do something
+ },
+ bar: 'bar',
+ t1: 1
+ });
+
+ let T2 = Trait({
+ foo: function() {
+ // do something else
+ },
+ bar: 'bar',
+ t2: 2
+ });
+
+ let TC = Trait.compose(T1, T2);
+
+Attempting to create an object from a composite trait with conflicts throws a
+`remaining conflicting property` exception. To create objects from such traits,
+you must resolve the conflict.
+
+You do so by excluding or renaming the conflicting property of one of the
+traits. Excluding a property removes it from the composition, so the composition
+only acquires the property from the other trait. Renaming a property gives it a
+new, non-conflicting name at which it can be accessed.
+
+In both cases, you call the `resolve` method on the trait whose property you
+want to exclude or rename, passing it an object. Each key in the object is the
+name of a conflicting property; each value is either `null` to exclude the
+property or a string representing the new name of the property.
+
+For example, the conflict in the previous example could be resolved by excluding
+the `foo` property of the second trait.
+
+ let TC = Trait(T1, T2.resolve({ foo: null }));
+
+It could also be resolved by renaming the `foo` property of the first trait to
+`foo2`:
+
+ let TC = Trait(T1.resolve({ foo: "foo2" }), T2);
+
+When you resolve a conflict, the same-named property of the other trait (the one
+that wasn't excluded or renamed) remains available in the composition under its
+original name.
+
+## Constructor Functions ##
+
+When your code is going to create more than one object with traits, you may want
+to define a constructor function to create them. To do so, create a composite
+trait representing the traits the created objects should have, then define a
+constructor function that creates objects with that trait and whose prototype is
+the prototype of the constructor:
+
+ let PointTrait = Trait.compose(T1, T2, T3);
+ function Point(options) {
+ let point = PointTrait.create(Point.prototype);
+ return point;
+ }
+
+## Property Descriptor Maps ##
+
+Traits are designed to work with the new object manipulation APIs defined in
+[ECMAScript-262, Edition
+5](http://www.ecma-international.org/publications/standards/Ecma-262.htm) (ES5).
+Traits are also property descriptor maps that inherit from `Trait.prototype` to
+expose methods for creating objects and resolving conflicts.
+
+The following trait definition:
+
+ let FooTrait = Trait({
+ foo: "foo",
+ bar: function bar() {
+ return "Hi!"
+ },
+ baz: Trait.required
+ });
+
+Creates the following property descriptor map:
+
+ {
+ foo: {
+ value: 'foo',
+ enumerable: true,
+ configurable: true,
+ writable: true
+ },
+
+ bar: {
+ value: function b() {
+ return 'bar'
+ },
+ enumerable: true,
+ configurable: true,
+ writable: true
+ },
+
+ baz: {
+ get baz() { throw new Error('Missing required property: `baz`') }
+ set baz() { throw new Error('Missing required property: `baz`') }
+ },
+
+ __proto__: Trait.prototype
+ }
+
+Since Traits are also property descriptor maps, they can be used with built-in
+`Object.*` methods that accept such maps:
+
+ Object.create(proto, FooTrait);
+ Object.defineProperties(myObject, FooTrait);
+
+Note that conflicting and required properties won't cause exceptions to be
+thrown when traits are used with the `Object.*` methods, since those methods are
+not aware of those constraints. However, such exceptions will be thrown when the
+property with the conflict or the required but missing property is accessed.
+
+Property descriptor maps can also be used in compositions. This may be useful
+for defining non-enumerable properties, for example:
+
+ let TC = Trait.compose(
+ Trait({ foo: 'foo' }),
+ { bar: { value: 'bar', enumerable: false } }
+ );
+
+_When using property descriptor maps in this way, make sure the map is not the
+only argument to `Trait.compose`, since in that case it will be interpreted as
+an object literal with properties to be defined._
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/list.md b/tools/addon-sdk-1.7/packages/api-utils/docs/list.md
new file mode 100644
index 0000000..fd70698
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/list.md
@@ -0,0 +1,98 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Irakli Gozalishvili [gozala@mozilla.com] -->
+
+The `"list"` module provides base building blocks for composing lists.
+
+<api name="Iterable">
+@class
+Base trait that can be used to compose traits with non-standard
+enumeration behaviors.
+
+This trait is supposed to be used as part of a composition, since it only
+provides custom enumeration behavior to a composed object.
+It defines one required `_keyValueMap` property, that is used as a hash of
+"key-values" to iterate on during enumeration.
+
+<api name="Iterable">
+@constructor
+Constructs an `Iterable` object.
+</api>
+
+<api name="_keyValueMap">
+@property {Object}
+Hash map of key-values to iterate over. _Required_ property: that is, the
+property must be supplied by objects that compose this trait.
+_Note: That this property can be a getter if you need dynamic behavior._
+</api>
+
+</api>
+
+<api name="List">
+@class
+An ordered collection (also known as a sequence) disallowing duplicate
+elements. List is composed out of `Iterable`, therefore it provides custom
+enumeration behavior that is similar to array (enumerates only on the
+elements of the list).
+
+List is a base trait and is meant to be part of a
+composition, since all of its API is private except for the `length` property.
+
+**Examples:**
+
+ var MyList = List.compose({
+ add: function add(item1, item2, /*item3...*/) {
+ Array.slice(arguments).forEach(this._add.bind(this));
+ },
+ remove: function remove(item1, item2, /*item3...*/) {
+ Array.slice(arguments).forEach(this._remove.bind(this));
+ }
+ });
+ MyList('foo', 'bar', 'baz').length == 3; // true
+ new MyList('new', 'keyword').length == 2; // true
+ MyList.apply(null, [1, 2, 3]).length == 3; // true
+ let list = MyList();
+ list.length == 0; // true
+ list.add(1, 2, 3) == 3; // true
+
+<api name="List">
+@constructor
+Constructor can takes any number of elements and creates an instance of
+`List` populated with the specified elements.
+@param [element1] {Object|String|Number}
+@param [element2] {Object|String|Number}
+@param [...] {Object|String|Number}
+</api>
+
+<api name="length">
+@property {Number}
+Number of elements in this list.
+</api>
+
+<api name="_has">
+@method
+@param element {Object|Number|String}
+Returns `true` if this list contains the specified `element`.
+</api>
+<api name="_add">
+@method
+@param element {Object|Number|String}
+Appends the specified `element` to the end of this list, if it doesn't
+contain it.
+
+_Ignores the call if `element` is already contained._
+</api>
+<api name="_remove">
+@method
+@param element {Object|Number|String}
+Removes specified `element` from this list, if it contains it.
+
+_Ignores the call if `element` is not contained._
+</api>
+<api name="_clear">
+@method
+Removes all of the elements from this list.
+</api>
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/match-pattern.md b/tools/addon-sdk-1.7/packages/api-utils/docs/match-pattern.md
new file mode 100644
index 0000000..0222e65
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/match-pattern.md
@@ -0,0 +1,246 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+The `match-pattern` module can be used to test strings containing URLs
+against simple patterns.
+
+## Specifying Patterns ##
+
+There are three ways you can specify patterns:
+
+* as an exact match string
+* using a wildcard in a string
+* using a regular expression
+
+### Exact Matches ###
+
+**A URL** matches only that URL. The URL must start with a scheme, end with a
+slash, and contain no wildcards.
+
+<table>
+
+ <colgroup>
+ <col width="30%">
+ <col width="35%">
+ <col width="35%">
+ </colgroup>
+
+ <tr>
+ <th>Example pattern</th>
+ <th>Example matching URLs</th>
+ <th>Example non-matching URLs</th>
+ </tr>
+
+ <tr>
+ <td><code>"http://example.com/"</code></td>
+ <td><code>http://example.com/</code></td>
+ <td><code>http://example.com</code><br>
+ <code>http://example.com/foo</code><br>
+ <code>https://example.com/</code><br>
+ <code>http://foo.example.com/</code></td>
+ </tr>
+
+</table>
+
+### Wildcards ###
+
+**A single asterisk** matches any URL with an `http`, `https`, or `ftp`
+scheme. For other schemes like `file`, use a scheme followed by an
+asterisk, as below.
+
+<table>
+
+ <colgroup>
+ <col width="30%">
+ <col width="35%">
+ <col width="35%">
+ </colgroup>
+
+ <tr>
+ <th>Example pattern</th>
+ <th>Example matching URLs</th>
+ <th>Example non-matching URLs</th>
+ </tr>
+
+ <tr>
+ <td><code>"*"</code></td>
+ <td><code>http://example.com/</code><br>
+ <code>https://example.com/</code><br>
+ <code>ftp://example.com/</code><br>
+ <code>http://bar.com/foo.js</code><br>
+ <code>http://foo.com/</code></td>
+ <td><code>file://example.js</code></td>
+ </tr>
+
+</table>
+
+**A domain name prefixed with an asterisk and dot** matches any URL of that
+domain or a subdomain, using any of `http`, `https`, `ftp`.
+
+<table>
+
+ <colgroup>
+ <col width="30%">
+ <col width="35%">
+ <col width="35%">
+ </colgroup>
+
+ <tr>
+ <th>Example pattern</th>
+ <th>Example matching URLs</th>
+ <th>Example non-matching URLs</th>
+ </tr>
+
+ <tr>
+ <td><code>"*.example.com"</code></td>
+ <td><code>http://example.com/</code><br>
+ <code>http://foo.example.com/</code><br>
+ <code>https://example.com/</code><br>
+ <code>http://example.com/foo</code><br>
+ <code>ftp://foo.example.com/</code></td>
+ <td><code>ldap://example.com</code><br>
+ <code>http://example.foo.com/</code></td>
+ </tr>
+
+</table>
+
+**A URL followed by an asterisk** matches that URL and any URL prefixed with
+the pattern.
+
+<table>
+
+ <colgroup>
+ <col width="30%">
+ <col width="35%">
+ <col width="35%">
+ </colgroup>
+
+ <tr>
+ <th>Example pattern</th>
+ <th>Example matching URLs</th>
+ <th>Example non-matching URLs</th>
+ </tr>
+
+ <tr>
+ <td><code>"https://foo.com/*"</code></td>
+ <td><code>https://foo.com/</code><br>
+ <code>https://foo.com/bar</code></td>
+ <td><code>http://foo.com/</code><br>
+ <code>https://foo.com</code><br>
+ <code>https://bar.foo.com/</code></td>
+ </tr>
+
+</table>
+
+**A scheme followed by an asterisk** matches all URLs with that scheme. To
+match local files, use `file://*`.
+
+<table>
+
+ <colgroup>
+ <col width="30%">
+ <col width="70%">
+ </colgroup>
+
+ <tr>
+ <th>Example pattern</th>
+ <th>Example matching URLs</th>
+ </tr>
+
+ <tr>
+ <td><code>"file://*"</code></td>
+ <td><code>file://C:/file.html</code><br>
+ <code>file:///home/file.png</code></td>
+ </tr>
+
+</table>
+
+### Regular Expressions ###
+
+You can specify patterns using a
+[regular expression](https://developer.mozilla.org/en/JavaScript/Guide/Regular_Expressions):
+
+ var { MatchPattern } = require("match-pattern");
+ var pattern = new MatchPattern(/.*example.*/);
+
+The regular expression is subject to restrictions based on those applied to the
+[HTML5 pattern attribute](http://dev.w3.org/html5/spec/common-input-element-attributes.html#attr-input-pattern). In particular:
+
+* The pattern must match the entire value, not just any subset. For example, the
+pattern `/moz.*/` will not match the URL `http://mozilla.org`.
+
+* The expression is compiled with the `global`, `ignoreCase`, and `multiline` flags
+ disabled. The `MatchPattern` constructor will throw an exception
+ if you try to set any of these flags.
+
+<table>
+
+ <colgroup>
+ <col width="30%">
+ <col width="35%">
+ <col width="35%">
+ </colgroup>
+
+ <tr>
+ <th>Example pattern</th>
+ <th>Example matching URLs</th>
+ <th>Example non-matching URLs</th>
+ </tr>
+
+ <tr>
+ <td><code>/.*moz.*/</code></td>
+ <td><code>http://foo.mozilla.org/</code><br>
+ <code>http://mozilla.org</code><br>
+ <code>https://mozilla.org</code><br>
+ <code>http://foo.com/mozilla</code><br>
+ <code>http://hemozoon.org</code><br>
+ <code>mozscheme://foo.org</code><br></td>
+ <td><code>http://foo.org</code><br>
+ </tr>
+
+ <tr>
+ <td><code>/http:\/\/moz.*/</code></td>
+ <td><code>http://mozilla.org</code><br>
+ <code>http://mozzarella.com</code></td>
+ <td><code>https://mozilla.org</code><br>
+ <code>http://foo.mozilla.org/</code><br>
+ <code>http://foo.com/moz</code></td>
+ </tr>
+
+ <tr>
+ <td><code>/http.*moz.*/</code><br></td>
+ <td><code>http://foo.mozilla.org/</code><br>
+ <code>http://mozilla.org</code><br>
+ <code>http://hemozoon.org/</code></td>
+ <td><code>ftp://http/mozilla.org</code></td>
+ </tr>
+
+</table>
+
+## Examples ##
+
+ var { MatchPattern } = require("match-pattern");
+ var pattern = new MatchPattern("http://example.com/*");
+ console.log(pattern.test("http://example.com/")); // true
+ console.log(pattern.test("http://example.com/foo")); // true
+ console.log(pattern.test("http://foo.com/")); // false!
+
+<api name="MatchPattern">
+@class
+<api name="MatchPattern">
+@constructor
+ This constructor creates match pattern objects that can be used to test URLs.
+@param pattern {string}
+ The pattern to use. See Patterns above.
+</api>
+
+<api name="test">
+@method
+ Tests a URL against the match pattern.
+@param url {string}
+ The URL to test.
+@returns {boolean}
+ True if the URL matches the pattern and false otherwise.
+</api>
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/memory.md b/tools/addon-sdk-1.7/packages/api-utils/docs/memory.md
new file mode 100644
index 0000000..04de606
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/memory.md
@@ -0,0 +1,7 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+The `memory` module provides a concrete default implementation for the SDK's
+`memory` global. For documentation on the `memory` global, see the
+[Globals](packages/api-utils/globals.html) reference.
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/message-manager.md b/tools/addon-sdk-1.7/packages/api-utils/docs/message-manager.md
new file mode 100644
index 0000000..522c613
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/message-manager.md
@@ -0,0 +1,13 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Matteo Ferretti [zer0@mozilla.com] -->
+
+Overview
+--------
+The `message-manager` module provides a minimalist implementation
+of the [Message Manager](https://developer.mozilla.org/en/The_message_manager)
+APIs, in a single process environment.
+
+It's mainly used internally for Fennec Birch support. \ No newline at end of file
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/namespace.md b/tools/addon-sdk-1.7/packages/api-utils/docs/namespace.md
new file mode 100644
index 0000000..07ec96e
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/namespace.md
@@ -0,0 +1,71 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+Provides an API for creating namespaces for any given objects, which
+effectively may be used for creating fields that are not part of objects
+public API.
+
+ let { ns } = require('api-utils/namespace');
+ let aNamespace = ns();
+
+ aNamespace(publicAPI).secret = secret;
+
+One namespace may be used with multiple objects:
+
+ let { ns } = require('api-utils/namespace');
+ let dom = ns();
+
+ function View(element) {
+ let view = Object.create(View.prototype);
+ dom(view).element = element;
+ // ....
+ }
+ View.prototype.destroy = function destroy() {
+ let { element } = dom(this);
+ element.parentNode.removeChild(element);
+ // ...
+ };
+ // ...
+ exports.View = View;
+ // ...
+
+Also, multiple namespaces can be used with one object:
+
+ // ./widget.js
+
+ let { Cu } = require('chrome');
+ let { ns } = require('api-utils/namespace');
+ let { View } = require('./view');
+
+ // Note this is completely independent from View's internal Namespace object.
+ let sandboxes = ns();
+
+ function Widget(options) {
+ let { element, contentScript } = options;
+ let widget = Object.create(Widget.prototype);
+ View.call(widget, options.element);
+ sandboxes(widget).sandbox = Cu.Sandbox(element.ownerDocument.defaultView);
+ // ...
+ }
+ Widget.prototype = Object.create(View.prototype);
+ Widget.prototype.postMessage = function postMessage(message) {
+ let { sandbox } = sandboxes(this);
+ sandbox.postMessage(JSON.stringify(JSON.parse(message)));
+ ...
+ };
+ Widget.prototype.destroy = function destroy() {
+ View.prototype.destroy.call(this);
+ // ...
+ delete sandboxes(this).sandbox;
+ };
+ exports.Widget = Widget;
+
+In addition access to the namespace can be shared with other code by just
+handing them a namespace accessor function.
+
+ let { dom } = require('./view');
+ Widget.prototype.setInnerHTML = function setInnerHTML(html) {
+ dom(this).element.innerHTML = String(html);
+ };
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/observer-service.md b/tools/addon-sdk-1.7/packages/api-utils/docs/observer-service.md
new file mode 100644
index 0000000..4d7cb58
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/observer-service.md
@@ -0,0 +1,73 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Atul Varma [atul@mozilla.com] -->
+<!-- edited by Noelle Murata [fiveinchpixie@gmail.com] -->
+
+The `observer-service` module provides access to the
+application-wide observer service singleton.
+
+For a list of common observer topics across a variety of Mozilla-based
+applications, see the MDC page on
+[Observer Notifications](https://developer.mozilla.org/en/Observer_Notifications).
+
+## Observer Callbacks ##
+
+Observer callbacks are functions of the following form:
+
+ function callback(subject, data) {
+ /* Respond to the event notification here... */
+ }
+
+In the above example, `subject` is any JavaScript object, as is
+`data`. The particulars of what the two contain are specific
+to the notification topic.
+
+<api name="add">
+@function
+ Adds an observer callback to be triggered whenever a notification matching the
+ topic is broadcast throughout the application.
+
+@param topic {string}
+ The topic to observe.
+
+@param callback {function,object}
+ Either a function or an object that implements [`nsIObserver`](http://mxr.mozilla.org/mozilla-central/source/xpcom/ds/nsIObserver.idl).
+ If a function, then it is called when the notification occurs. If an object,
+ then its `observe()` method is called when the notification occurs.
+
+@param [thisObject] {object}
+ An optional object to use as `this` when a function callback is called.
+</api>
+
+<api name="remove">
+@function
+ Unsubscribes a callback from being triggered whenever a notification
+ matching the topic is broadcast throughout the application.
+
+@param topic {string}
+ The topic being observed by the previous call to `add()`.
+
+@param callback {function,object}
+ The callback subscribed in the previous call to `add()`, either a function or
+ object.
+
+@param [thisObject] {object}
+ If `thisObject` was passed to the previous call to `add()`, it should be
+ passed to `remove()` as well.
+</api>
+
+<api name="notify">
+@function
+ Broadcasts a notification event for a topic, passing a subject and data to all
+ applicable observers in the application.
+
+@param topic {string}
+ The topic about which to broadcast a notification.
+
+@param [subject] {value}
+ Optional information about the topic. This can be any JS object or primitive.
+ If you have multiple values to pass to observers, wrap them in an object,
+ e.g., `{ foo: 1, bar: "some string", baz: myObject }`.
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/plain-text-console.md b/tools/addon-sdk-1.7/packages/api-utils/docs/plain-text-console.md
new file mode 100644
index 0000000..d139587
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/plain-text-console.md
@@ -0,0 +1,7 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+The `plain-text-console` module provides a minimalist implementation
+of the [console](dev-guide/console.html) global,
+which simply logs all messages to standard output.
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/preferences-service.md b/tools/addon-sdk-1.7/packages/api-utils/docs/preferences-service.md
new file mode 100644
index 0000000..03b4725
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/preferences-service.md
@@ -0,0 +1,116 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Myk Melez [myk@mozilla.org] -->
+<!-- contributed by Daniel Aquino [mr.danielaquino@gmail.com] -->
+<!-- contributed by Atul Varma [atul@mozilla.com] -->
+<!-- edited by Noelle Murata [fiveinchpixie@gmail.com] -->
+
+The `preferences-service` module provides access to the
+application-wide preferences service singleton.
+
+
+<api name="set">
+@function
+Sets the application preference `name` to `value`.
+@param name {string} Preference name.
+@param value {string,number,bool} Preference value.
+
+**Example:**
+
+ var name = "extensions.checkCompatibility.nightly";
+ require("preferences-service").set(name, false);
+</api>
+
+
+<api name="get">
+@function
+Gets the application preference `name`.
+@param name {string}
+@param defaultValue {string,number,bool} Preference value.
+@returns {string,number,bool} Preference value, returns a default value if no
+preference is set.
+
+**Example:**
+
+ var name = "extensions.checkCompatibility.nightly";
+ var nightlyCompatChk = require("preferences-service").get(name);
+</api>
+
+
+<api name="has">
+@function
+@param name {string} Preference name.
+@returns {bool} Returns whether or not the application preference `name` exists.
+
+**Example:**
+
+ var name = "extensions.checkCompatibility.nightly";
+ if (require("preferences-service").has(name)) {
+ // ...
+ }
+</api>
+
+
+<api name="isSet">
+@function
+@param name {string} Preference name.
+@returns {bool}
+Returns whether or not the application preference `name` both exists
+and has been set to a non-default value by the user (or a program
+acting on the user's behalf).
+
+**Example:**
+
+ var name = "extensions.checkCompatibility.nightly";
+ if (require("preferences-service").isSet(name)) {
+ // ...
+ }
+</api>
+
+
+<api name="reset">
+@function
+Clears a non-default, user-set value from the application preference
+`name`. If no user-set value is defined on `name`, the function
+does nothing. If no default value exists the preference will cease to exist.
+@param name {string} Preference name.
+
+**Example:**
+
+ var name = "extensions.checkCompatibility.nightly";
+ require("preferences-service").reset(name);
+</api>
+
+<api name="getLocalized">
+@function
+Gets the localized value for an application preference `name`.
+@param name {string}
+@param defaultValue {string} Preference value.
+@returns {string} Localized preference value, returns a default value if no
+preference is set. Some preferences refer to a properties file.
+So that `prefs.get` returns the properties file URL whereas
+`prefs.getLocalized` returns the value defined in the properties file.
+
+**Example:**
+
+ var prefs = require("preferences-service");
+ var name = "general.useragent.locale";
+ prefs.get(name); // is equal to "chrome://global/locale/intl.properties"
+ prefs.getLocalized(name) // is equal to "en-US"
+
+</api>
+
+<api name="setLocalized">
+@function
+Sets the localized application preference `name` to `value`.
+@param name {string} Preference name.
+@param value {string} Preference value, a URL to a properties file
+
+**Example:**
+
+ require("preferences-service").set("general.useragent.locale",
+ "chrome://global/locale/intl.properties");
+
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/promise.md b/tools/addon-sdk-1.7/packages/api-utils/docs/promise.md
new file mode 100644
index 0000000..d67b820
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/promise.md
@@ -0,0 +1,394 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+## Rationale
+
+Most of the JS APIs are asynchronous complementing it's non-blocking nature.
+While this has a good reason and many advantages, it comes with a price.
+Instead of structuring our programs into logical black boxes:
+
+ function blackbox(a, b) {
+ var c = assemble(a);
+ return combine(b, c);
+ }
+
+
+We're forced into continuation passing style, involving lot's of machinery:
+
+ function sphagetti(a, b, callback) {
+ assemble(a, function continueWith(error, c) {
+ if (error) callback(error);
+ else combine(b, c, callback);
+ });
+ }
+
+This style also makes doing things in sequence hard:
+
+ widget.on('click', function onClick() {
+ promptUserForTwitterHandle(function continueWith(error, handle) {
+ if (error) return ui.displayError(error);
+ twitter.getTweetsFor(handle, funtion continueWith(error, tweets) {
+ if (error) return ui.displayError(error);
+ ui.showTweets(tweets);
+ });
+ });
+ });
+
+Doing things in parallel is even harder:
+
+ var tweets, answers, checkins;
+ twitter.getTweetsFor(user, function continueWith(result) {
+ tweets = result;
+ somethingFinished();
+ });
+
+ stackOverflow.getAnswersFor(question, function continueWith(result) {
+ answers = result;
+ somethingFinished();
+ });
+
+ fourSquare.getCheckinsBy(user, function continueWith(result) {
+ checkins=result;
+ somethingFinished();
+ });
+
+ var finished = 0;
+ functions somethingFinished() {
+ if (++finished === 3)
+ ui.show(tweets, answers, checkins);
+ }
+
+This also makes error handling quite of an adventure.
+
+## Promises
+
+Consider another approach, where instead of continuation passing via `callback`,
+function returns an object, that represents eventual result, either successful
+or failed. This object is a promise, both figuratively and by name, to
+eventually resolve. We can call a function on the promise to observe
+either its fulfillment or rejection. If the promise is rejected and the
+rejection is not explicitly observed, any derived promises will be implicitly
+rejected for the same reason.
+
+In the Add-on SDK we follow
+[CommonJS Promises/A](http://wiki.commonjs.org/wiki/Promises/A) specification
+and model a promise as an object with a `then` method, which can be used to get
+the eventual return (fulfillment) value or thrown exception (rejection):
+
+ foo().then(function success(value) {
+ // ...
+ }, function failure(reason) {
+ // ...
+ });
+
+If `foo` returns a promise that gets fulfilled with the `value`, `success`
+callback (the value handler) will be called with that `value`. However,
+if the returned promise gets rejected, the `failure` callback (the error
+handler) will be called with the `reason` of an error.
+
+## Propagation
+
+The `then` method of a promise returns a new promise that is resolved with the
+return value of either handler. Since function can either return value or throw
+an exception, only one handler will be ever called.
+
+
+ var bar = foo().then(function success(value) {
+ // compute something from a value...
+ }, function failure(reason) {
+ // handle an error...
+ });
+
+In this example `bar` is a promise and it's fulfilled by one of two handlers
+that are responsible for:
+
+ - If handler returns a value, `bar` will be resolved with it.
+ - If handler throws an exception, `bar` will be rejected with it.
+ - If handler returns a **promise**, `bar` will "become" that promise. To be
+ more precise it will be resolved with a resolution value of the returned
+ promise, which will appear and feel as if it was that returned promise.
+
+If the `foo()` promise gets rejected and you omit the error handler, the
+**error** will propagate to `bar` (`bar` will be rejected with that error):
+
+ var bar = foo().then(function success(value) {
+ // compute something out of the value...
+ });
+
+If the `foo()` promise gets fulfilled and you omit the value handler, the
+**value** will propagate to `bar` (`bar` will be fulfilled with that value):
+
+ var bar = foo().then(null, function failure(error) {
+ // handle error...
+ });
+
+
+## Chaining
+
+There are two ways to chain promise operations. You can chain them using either
+inside or outside handlers.
+
+### Flat chaining
+
+You can use `then` for chaining intermediate operations on promises
+(`var data = readAsync().then(parse).then(extract)`). You can chain multiple
+`then` functions, because `then` returns a promise resolved to a return value
+of an operation and errors propagate through the promise chains. In general
+good rule of thumb is to prefer `then` based flat chaining. It makes code
+easier to read and make changes later:
+
+ var data = readAsync(url). // read content of url asynchronously
+ then(parse). // parse content from the url
+ then(extractQuery). // extract SQL query
+ then(readDBAsync); // exectue extracted query against DB
+
+### Nested chaining
+
+Flat chaining is not always an option though, as in some cases you may want to
+capture an intermediate values of the chain:
+
+ var result = readAsync(url).then(function(source) {
+ var json = parse(source)
+ return readDBAsync(extractQuery(json)).then(function(data) {
+ return writeAsync(json.url, data);
+ });
+ });
+
+In general, nesting is useful for computing values from more then one promise:
+
+ function eventualAdd(a, b) {
+ return a.then(function (a) {
+ return b.then(function (b) {
+ return a + b;
+ });
+ });
+ }
+
+ var c = eventualAdd(aAsync(), bAsync());
+
+## Error handling
+
+One sometimes-unintuitive aspect of promises is that if you throw an exception
+in the value handler, it will not be be caught by the error handler.
+
+ readAsync(url).then(function (value) {
+ throw new Error("Can't bar.");
+ }, function (error) {
+ // We only get here if `readAsync` fails.
+ });
+
+To see why this is, consider the parallel between promises and `try`/`catch`.
+We are `try`-ing to execute `readAsync()`: the error handler represents a
+`catch` for `readAsync()`, while the value handler represents code that happens
+*after* the `try`/`catch` block. That code then needs its own `try`/`catch`
+block to handle errors there.
+
+In terms of promises, this means chaining your error handler:
+
+ readAsync(url).
+ then(parse).
+ then(null, function handleParseError(error) {
+ // handle here both `readAsync` and `parse` errors.
+ });
+
+
+# Consuming promises
+
+In general, whole purpose of promises is to avoid a callback spaghetti in the
+code. As a matter of fact it would be great if we could convert any synchronous
+functions to asynchronous by making it aware of promises. Module exports
+`promised` function to do exactly that:
+
+ const { promised } = require('api-utils/promise');
+ function sum(x, y) { return x + y }
+ var sumAsync = promised(sum);
+
+ var c = sum(a, b);
+ var cAsync = asyncSum(aAsync(), bAsinc());
+
+`promised` takes normal function and composes new promise aware version of it
+that may take both normal values and promises as arguments and returns promise
+that will resolve to value that would have being returned by an original
+function if it was called with fulfillment values of given arguments.
+
+This technique is so powerful that it can replace most of the promise utility
+functions provided by other promise libraries. For example grouping promises
+to observe single resolution of all of them is as simple as this:
+
+ var group = promised(Array);
+ var abc = group(aAsync, bAsync, cAsync).then(function(items) {
+ return items[0] + items[1] + items[2];
+ });
+
+# Making promises
+
+Everything above assumes you get a promise from somewhere else. This
+is the common case, but every once in a while, you will need to create a
+promise from scratch. Add-on SDK's `promise` module provides API for doing
+that.
+
+## defer
+
+Module exports `defer` function, which is where all promises ultimately
+come from. Lets see implementation of `readAsync` that we used in lot's
+of examples above:
+
+ const { defer } = require('api-utils/promise');
+ function readAsync(url) {
+ var deferred = defer();
+
+ let xhr = new XMLHttpRequest();
+ xhr.open("GET", url, true);
+ xhr.onload = function() {
+ deferred.resolve(xhr.responseText);
+ }
+ xhr.onerror = function(event) {
+ deferred.reject(event);
+ }
+ xhr.send();
+
+ return deferred.promise;
+ }
+
+So `defer` returns an object that contains `promise` and two `resolve`, `reject`
+functions that can be used to resolve / reject that `promise`. **Note:** that
+promise can be rejected or resolved and only once. All subsequent attempts will be
+ignored.
+
+Another simple example may be `delay` function that returns promise which
+is fulfilled with a given `value` in a given `ms`, kind of promise based
+alternative to `setTimeout`:
+
+ function delay(ms, value) {
+ let { promise, resolve } = defer();
+ setTimeout(resolve, ms, value);
+ return promise;
+ }
+
+ delay(10, 'Hello world').then(console.log);
+ // After 10ms => 'Helo world'
+
+# Advanced usage
+
+If general `defer` and `promised` should be enough to doing almost anything
+you may think of with promises, but once you start using promises extensively
+you may discover some missing pieces and this section of documentation may
+help you to discover them.
+
+## Doing things concurrently
+
+So far we have being playing with promises that do things sequentially, but
+there are bunch of cases where one would need to do things concurrently. In the
+following example we implement functions that takes multiple promises and
+returns one that resolves to first on being fulfilled:
+
+ function race() {
+ let { promise, resolve } = defer();
+ Array.slice(arguments).forEach(function(promise) {
+ promise.then(resolve);
+ });
+ return promise;
+ }
+
+ var asyncAorB = race(readAsync(urlA), readAsync(urlB));
+
+*Note: that this implementation forgives failures and would fail if all
+promises fail to resolve.*
+
+There are cases when promise may or may not be fulfilled in a reasonable time.
+In such cases it's useful to put a timer on such tasks:
+
+ function timeout(promise, ms) {
+ let deferred = defer();
+ promise.then(deferred.resolve, deferred.reject);
+ delay(ms, 'timeout').then(deferred.reject);
+ return deferred.promise;
+ }
+
+ var tweets = readAsync(url);
+ timeout(tweets, 20).then(function(data) {
+ ui.display(data);
+ }, function() {
+ alert('Network is being too slow, try again later');
+ });
+
+## Alternative promise APIs
+
+There may be a cases where you will want to provide more than just `then`
+method on your promises. In fact some other promise frameworks do that.
+Such use cases are also supported. Earlier described `defer` may be passed
+optional `prototype` argument, in order to make returned promise and all
+the subsequent promises decedents of that `prototype`:
+
+ let { promise, resolve } = defer({
+ get: function get(name) {
+ return this.then(function(value) {
+ return value[name];
+ })
+ }
+ });
+
+ promise.get('foo').get('bar').then(console.log);
+ resolve({ foo: { bar: 'taram !!' } });
+
+ // => 'taram !!'
+
+Also `promised` function maybe passed second optional `prototype` argument to
+achieve same effect.
+
+## Treat all values as promises
+
+Module provides a simple function for wrapping values into promises:
+
+ const { resolve } = require('api-utils/promise');
+
+ var a = resolve(5).then(function(value) {
+ return value + 2
+ });
+ a.then(console.log); // => 7
+
+Also `resolve` not only takes values, but also promises. If you pass it
+a promise it will return new identical one:
+
+ const { resolve } = require('api-utils/promise');
+
+ resolve(resolve(resolve(3))).then(console.log); // => 3
+
+If this construct may look strange at first, but it becomes quite handy
+when writing functions that deal with both promises and values. In such
+cases it's usually easier to wrap value into promise than branch on value
+type:
+
+ function or(a, b) {
+ var second = resolve(b).then(function(bValue) { return !!bValue });
+ return resolve(a).then(function(aValue) {
+ return !!aValue || second;
+ }, function() {
+ return second;
+ })
+ }
+
+*Note: We could not use `promised` function here, as they reject returned
+promise if any of the given arguments is rejected.*
+
+If you need to customize your promises even further you may pass `resolve` a
+second optional `prototype` argument that will have same effect as with `defer`.
+
+## Treat errors as promises
+
+Now that we can create all kinds of eventual values, it's useful to have a
+way to create eventual errors. Module exports `reject` exactly for that.
+It takes anything as an argument and returns a promise that is rejected with
+it.
+
+ const { reject } = require('api-utils/promise');
+
+ var boom = reject(Error('boom!'));
+
+ future(function() {
+ return Math.random() < 0.5 ? boom : value
+ })
+
+As with rest of the APIs error may be given second optional `prototype`
+argument to customize resulting promise to your needs.
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/querystring.md b/tools/addon-sdk-1.7/packages/api-utils/docs/querystring.md
new file mode 100644
index 0000000..30f4117
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/querystring.md
@@ -0,0 +1,37 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+Module exports utility functions for working with query strings.
+
+### stringify
+
+Object may be serialize to a query string via exported `stringify` function:
+
+ querystring.stringify({ foo: 'bar', baz: 4 }); // => 'foo=bar&baz=4'
+
+Optionally `separator` and `assignment` arguments may be passed to
+override default `'&'` and`'='` characters:
+
+ querystring.stringify({ foo: 'bar', baz: 4 }, ';', ':'); // => 'foo:bar;baz:4'
+
+### parse
+
+Query string may be deserialized to an object via exported `parse`
+function:
+
+ querystring.parse('foo=bar&baz=bla') // => { foo: 'bar', baz: 'bla' }
+
+Optionally `separator` and `assignment` arguments may be passed to
+override default `'&'` and `'='` characters:
+
+ querystring.parse('foo:bar|baz:bla', '|', ':') // => { foo: 'bar', baz: 'bla' }
+
+### escape
+
+The escape function used by `stringify` to encodes a string safely
+matching RFC 3986 for `application/x-www-form-urlencoded`.
+
+### unescape
+
+The unescape function used by `parse` to decode a string safely.
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/runtime.md b/tools/addon-sdk-1.7/packages/api-utils/docs/runtime.md
new file mode 100644
index 0000000..c8d8ed3
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/runtime.md
@@ -0,0 +1,75 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Wes Kocher [kwierso@gmail.com] -->
+
+The `runtime` module provides access to information about Firefox's
+runtime environment. All properties exposed are read-only.
+
+For more information, see [nsIXULRuntime][nsIXULRuntime].
+[nsIXULRuntime]: https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIXULRuntime
+
+<api name="inSafeMode">
+@property {boolean}
+ This value is `true` if Firefox was started in safe mode,
+ otherwise `false`.
+</api>
+
+<api name="OS">
+@property {string}
+ A string identifying the current operating system. For example, .
+ `"WINNT"`, `"Darwin"`, or `"Linux"`. See [OS_TARGET][OS_TARGET]
+ for a more complete list of possible values.
+
+[OS_TARGET]: https://developer.mozilla.org/en/OS_TARGET
+</api>
+
+<api name="processType">
+@property {long}
+ The type of the caller's process, which will be one of these constants\:
+<table>
+ <tr>
+ <th>Constant</th>
+ <th>Value</th>
+ <th>Description</th>
+ </tr>
+
+ <tr>
+ <td>PROCESS_TYPE_DEFAULT</td>
+ <td>0</td>
+ <td>The default (chrome) process.</td>
+ </tr>
+
+ <tr>
+ <td>PROCESS_TYPE_PLUGIN</td>
+ <td>1</td>
+ <td>A plugin subprocess.</td>
+ </tr>
+
+ <tr>
+ <td>PROCESS_TYPE_CONTENT</td>
+ <td>2</td>
+ <td>A content subprocess.</td>
+ </tr>
+
+ <tr>
+ <td>PROCESS_TYPE_IPDLUNITTEST</td>
+ <td>3</td>
+ <td>An IPDL unit testing subprocess.</td>
+ </tr>
+</table>
+</api>
+
+<api name="widgetToolkit">
+@property {string}
+ A string identifying the target widget toolkit in use.
+</api>
+
+<api name="XPCOMABI">
+@property {string}
+ A string identifying the [ABI][ABI] of the current processor and compiler vtable.
+ This string takes the form \<`processor`\>-\<`compilerABI`\>,
+ for example\: "`x86-msvc`" or "`ppc-gcc3`".
+[ABI]: https://developer.mozilla.org/en/XPCOM_ABI
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/sandbox.md b/tools/addon-sdk-1.7/packages/api-utils/docs/sandbox.md
new file mode 100644
index 0000000..026b569
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/sandbox.md
@@ -0,0 +1,51 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+Provides an API for creating javascript sandboxes and for executing scripts
+in them.
+
+### Create a sandbox ###
+
+For the starting point you need to create a sandbox:
+
+ const { sandbox, evaluate, load } = require("api-utils/sandbox");
+ let scope = sandbox('http://example.com');
+
+Argument passed to the sandbox defines it's privileges. Argument may be an URL
+string, in which case sandbox will get exact same privileges as a scripts
+loaded from that URL. Argument also could be a DOM window object, to inherit
+privileges from the window being passed. Finally if argument is omitted or is
+`null` sandbox will have a chrome privileges giving it access to all the XPCOM
+components. Optionally `sandbox` function can be passed a second optional
+argument (See [sandbox documentation on MDN](https://developer.mozilla.org/en/Components.utils.Sandbox#Optional_parameter)
+for details).
+
+### Evaluate code ###
+
+Module provides `evaluate` function that allows executing code in the given
+sandbox:
+
+ evaluate(scope, 'var a = 5;');
+ evaluate(scope, 'a + 2;'); //=> 7
+
+More details about evaluated script may be passed via optional arguments that
+may improve an exception reporting:
+
+ // Evaluate code as if it was loaded from 'http://foo.com/bar.js' and
+ // start from 2nd line.
+ evaluate(scope, 'a ++', 'http://foo.com/bar.js', 2);
+
+Version of JavaScript can be also specified via optional argument:
+
+ evaluate(scope, 'let b = 2;', 'bar.js', 1, '1.5');
+ // throws cause `let` is not defined in JS 1.5.
+
+### Loading scripts ###
+
+API provides limited API for loading scripts right form the local URLs,
+but data: URLs are supported.
+
+ load(scope, 'resource://path/to/my/script.js');
+ load(scope, 'file:///path/to/script.js');
+ load(scope, 'data:,var a = 5;'); \ No newline at end of file
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/tab-browser.md b/tools/addon-sdk-1.7/packages/api-utils/docs/tab-browser.md
new file mode 100644
index 0000000..295fcc7
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/tab-browser.md
@@ -0,0 +1,140 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Dietrich Ayala [dietrich@mozilla.com] -->
+
+The `tab-browser` module is a low-level API that provides privileged
+access to browser tab events and actions.
+
+Introduction
+------------
+
+The `tab-browser` module contains helpers for tracking tabbrowser elements
+and tabs, as well as a few utilities for actions such as opening a new
+tab, and catching all tab content loads.
+
+This is a low-level API that has full privileges, and is intended to be used
+by SDK internal modules. If you just need easy access to tab events for your
+add-on, use the Tabs module (JEP 110).
+
+<api name="activeTab">
+@property {element}
+The XUL tab element of the currently active tab.
+</api>
+
+<api name="addTab">
+@function
+Adds a new tab.
+
+**Example**
+
+ var tabBrowser = require("tab-browser");
+ tabBrowser.addTab("http://google.com");
+
+ var tabBrowser = require("tab-browser");
+ tabBrowser.addTab("http://google.com", {
+ inBackground: true
+ });
+
+ var tabBrowser = require("tab-browser");
+ tabBrowser.addTab("http://google.com", {
+ inNewWindow: true,
+ onLoad: function(tab) {
+ console.log("tab is open.");
+ }
+ });
+
+@returns {element}
+The XUL tab element of the newly created tab.
+
+@param URL {string}
+The URL to be opened in the new tab.
+
+@param options {object}
+Options for how and where to open the new tab.
+
+@prop [inNewWindow] {boolean}
+An optional parameter whose key can be set in `options`.
+If true, the tab is opened in a new window. Default is false.
+
+@prop [inBackground] {boolean}
+An optional parameter whose key can be set in `options`.
+If true, the tab is opened adjacent to the active tab, but not
+switched to. Default is false.
+
+@prop [onLoad] {function}
+An optional parameter whose key can be set in `options`.
+A callback function that is called once the tab has loaded.
+The XUL element for the tab is passed as a parameter to
+this function.
+</api>
+
+<api name="Tracker">
+@function
+Register a delegate object to be notified when tabbrowsers are created
+and destroyed.
+
+The onTrack method will be called once per pre-existing tabbrowser, upon
+tracker registration.
+
+**Example**
+
+ var tabBrowser = require("tab-browser");
+ let tracker = {
+ onTrack: function(tabbrowser) {
+ console.log("A new tabbrowser is being tracked.");
+ },
+ onUntrack: function(tabbrowser) {
+ console.log("A tabbrowser is no longer being tracked.");
+ }
+ };
+ tabBrowser.Tracker(tracker);
+
+@param delegate {object}
+Delegate object to be notified each time a tabbrowser is created or destroyed.
+The object should contain the following methods:
+
+@prop [onTrack] {function}
+Method of delegate that is called when a new tabbrowser starts to be tracked.
+The tabbrowser element is passed as a parameter to this method.
+
+@prop [onUntrack] {function}
+Method of delegate that is called when a tabbrowser stops being tracked.
+The tabbrowser element is passed as a parameter to this method.
+</api>
+
+<api name="TabTracker">
+@function
+Register a delegate object to be notified when tabs are opened and closed.
+
+
+The onTrack method will be called once per pre-existing tab, upon
+tracker registration.
+
+**Example**
+
+ var tabBrowser = require("tab-browser");
+ let tracker = {
+ onTrack: function(tab) {
+ console.log("A new tab is being tracked.");
+ },
+ onUntrack: function(tab) {
+ console.log("A tab is no longer being tracked.");
+ }
+ };
+ tabBrowser.TabTracker(tracker);
+
+@param delegate {object}
+Delegate object to be notified each time a tab is opened or closed.
+The object should contain the following methods:
+
+@prop [onTrack] {function}
+Method of delegate that is called when a new tab starts to be tracked.
+The tab element is passed as a parameter to this method.
+
+@prop [onUntrack] {function}
+Method of delegate that is called when a tab stops being tracked.
+The tab element is passed as a parameter to this method.
+</api>
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/text-streams.md b/tools/addon-sdk-1.7/packages/api-utils/docs/text-streams.md
new file mode 100644
index 0000000..55f177c
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/text-streams.md
@@ -0,0 +1,102 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Drew Willcoxon [adw@mozilla.com] -->
+<!-- edited by Noelle Murata [fiveinchpixie@gmail.com] -->
+
+The `text-streams` module provides streams for reading and writing text using
+particular character encodings.
+
+<api name="TextReader">
+@class
+<api name="TextReader">
+@constructor
+ Creates a buffered input stream that reads text from a backing stream using a
+ given text encoding.
+@param inputStream {stream}
+ The backing stream, an [`nsIInputStream`](http://mxr.mozilla.org/mozilla-central/source/xpcom/io/nsIInputStream.idl).
+ It must already be opened.
+@param [charset] {string}
+ `inputStream` is expected to be in the character encoding named by this value.
+ If not specified, "UTF-8" is assumed. See [`nsICharsetConverterManager.idl`](http://mxr.mozilla.org/mozilla-central/source/intl/uconv/idl/nsICharsetConverterManager.idl)
+ for documentation on how to determine other valid values for this.
+</api>
+
+<api name="closed">
+@property {boolean}
+ True if the stream is closed.
+</api>
+
+<api name="close">
+@method
+ Closes both the stream and its backing stream.
+</api>
+
+<api name="read">
+@method
+ Reads and returns a string from the stream. If the stream is closed, an
+ exception is thrown.
+@param [numChars] {number}
+ The number of characters to read. If not given, the remainder of the stream
+ is read.
+@returns {string}
+ The string read. If the stream is at the end, the empty string is returned.
+</api>
+
+</api>
+
+
+<api name="TextWriter">
+@class
+<api name="TextWriter">
+@constructor
+ Creates a buffered output stream that writes text to a backing stream using a
+ given text encoding.
+@param outputStream {stream}
+ The backing stream, an [`nsIOutputStream`](http://mxr.mozilla.org/mozilla-central/source/xpcom/io/nsIOutputStream.idl).
+ It must already be opened.
+@param [charset] {string}
+ Text will be written to `outputStream` using the character encoding named by
+ this value. If not specified, "UTF-8" is assumed. See [`nsICharsetConverterManager.idl`](http://mxr.mozilla.org/mozilla-central/source/intl/uconv/idl/nsICharsetConverterManager.idl)
+ for documentation on how to determine other valid values for this.
+</api>
+
+<api name="closed">
+@property {boolean}
+ True if the stream is closed.
+</api>
+
+<api name="close">
+@method
+ Flushes the backing stream's buffer and closes both the stream and the backing
+ stream. If the stream is already closed, an exception is thrown.
+</api>
+
+<api name="flush">
+@method
+ Flushes the backing stream's buffer.
+</api>
+
+<api name="write">
+@method
+ Writes a string to the stream. If the stream is closed, an exception is
+ thrown.
+@param str {string}
+ The string to write.
+</api>
+
+<api name="writeAsync">
+@method
+ Writes a string on a background thread. After the write completes, the
+ backing stream's buffer is flushed, and both the stream and the backing stream
+ are closed, also on the background thread. If the stream is already closed,
+ an exception is thrown immediately.
+@param str {string}
+ The string to write.
+@param [callback] {callback}
+ *`callback`*, if given, must be a function. It's called as `callback(error)`
+ when the write completes. `error` is an `Error` object or undefined if there
+ was no error. Inside *`callback`*, `this` is the `TextWriter` object.
+</api>
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/traceback.md b/tools/addon-sdk-1.7/packages/api-utils/docs/traceback.md
new file mode 100644
index 0000000..b52c183
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/traceback.md
@@ -0,0 +1,66 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Atul Varma [atul@mozilla.com] -->
+<!-- edited by Noelle Murata [fiveinchpixie@gmail.com] -->
+
+
+The `traceback` module contains functionality similar to
+Python's [traceback](http://docs.python.org/library/traceback.html) module.
+
+## JSON Traceback Objects ##
+
+Tracebacks are stored in JSON format. The stack is represented as an
+array in which the most recent stack frame is the last element; each
+element thus represents a stack frame and has the following keys:
+
+<table>
+ <tr>
+ <td><code>filename</code></td>
+ <td>The name of the file that the stack frame takes place in.</td>
+ </tr>
+ <tr>
+ <td><code>lineNo</code></td>
+ <td>The line number is being executed at the stack frame.</td>
+ </tr>
+ <tr>
+ <td><code>funcName</code></td>
+ <td>The name of the function being executed at the stack frame, or
+ <code>null</code> if the function is anonymous or the stack frame is
+ being executed in a top-level script or module.</td>
+ </tr>
+</table>
+
+<api name="fromException">
+@function
+ Attempts to extract the traceback from *`exception`*.
+
+@returns {traceback}
+ JSON representation of the traceback or `null` if not found.
+
+@param exception {exception}
+ exception where exception is an `nsIException`.
+</api>
+
+See [nsIException](https://developer.mozilla.org/en/NsIException) for more
+information.
+
+<api name="get">
+@function
+
+@returns {JSON}
+ Returns the JSON representation of the stack at the point that this
+ function is called.
+</api>
+
+<api name="format">
+@function
+Given a JSON representation of the stack or an exception instance,
+returns a formatted plain text representation of it, similar to
+Python's formatted stack tracebacks. If no argument is provided, the
+stack at the point this function is called is used.
+
+@param [tbOrException] {object}
+</api>
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/traits.md b/tools/addon-sdk-1.7/packages/api-utils/docs/traits.md
new file mode 100644
index 0000000..910cd9a
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/traits.md
@@ -0,0 +1,244 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Irakli Gozalishvil [gozala@mozilla.com] -->
+
+The `traits` module provides base building blocks for secure object
+composition. It exports base trait / constructor function that
+constructs an instance of `Trait`.
+
+[Traits](http://en.wikipedia.org/wiki/Trait_%28computer_science%29) are a
+simple composition mechanism for structuring object-oriented programs. Traits
+are similar to
+[interfaces](http://en.wikipedia.org/wiki/Interface_%28object-oriented_programming%29),
+except that they often define only a part of an object's data and behavior and
+are intended to be used in conjunction with other traits to completely define
+the object.
+
+Traits are also considered to be a more robust alternative to
+[mixins](http://en.wikipedia.org/wiki/Mixins) because, name conflicts have to
+be resolved explicitly by composer & because trait composition is
+order-independent (hence more declarative).
+
+
+There are some other implementations of traits in JavaScript & some ideas /
+APIs are borrowed from them:
+
+- [traitsjs](http://www.traitsjs.org/)
+- [joose](http://code.google.com/p/joose-js/)
+
+Object-capability security model
+--------------------------------
+
+Implementation uses an
+[object-capability security model](http://en.wikipedia.org/wiki/Object-capability_model)
+to allow protection of private APIs. At the same private APIs can be shared
+between among trait composition parties. To put it simply: All the properties
+whose names start with `"_"` are considered to be **private**, and are
+unaccessible from anywhere except other **public** methods / accessors of the
+instance that had been defined during composition.
+
+<api name="Trait">
+@class
+<api name="Trait">
+@constructor
+Creates an instance of Trait and returns it if it has no `constructor` method
+defined. If instance has `constructor` method, then it is called with all the
+arguments passed to this function and returned value is returned instead,
+unless it's `undefined`. In that case instance is returned.
+
+`Trait` function represents a base trait. As with any other trait it represents
+a constructor function for creating instances of its own & a placeholder
+for a trait compositions functions.
+</api>
+
+<api name="compose">
+@method
+Composes new trait out of itself and traits / property maps passed as an
+arguments. If two or more traits / property maps have properties with the same
+name, the new trait will contain a "conflict" property for that name (see
+examples in Examples section to find out more about "conflict" properties).
+This is a commutative and associative operation, and the order of its
+arguments is not significant.
+
+**Examples:**
+
+Let's say we want to define a reusable piece of code for a lists of elements.
+
+ var { Trait } = require('traits');
+ var List = Trait.compose({
+ // private API:
+ _list: null,
+ // public API
+ constructor: function List() {
+ this._list = [];
+ },
+ get length() this._list.length,
+ add: function add(item) this._list.push(item),
+ remove: function remove(item) {
+ let list = this._list;
+ let index = list.indexOf(item);
+ if (0 <= index) list.splice(index, 1);
+ }
+ });
+
+Instances of `List` can be created by calling `List` function with or without
+`new` keyword.
+
+ let l1 = List();
+ l1 instanceof List; // true
+ let l2 = new List();
+ l2 instanceof List; // true
+
+As you can see `add` and `remove` functions are capable of accessing private
+`_list` property, but thats about it, there's nothing else that will be able
+to access this property:
+
+ '_list' in l1; // false
+ '_list' in l2; // false
+ '_list' in List.protoype; // false
+ l1.has = function(name) name in this
+ l1.has('_list'); // false
+ l1.length; // 0
+ l1.add('test')
+ l1.length // 1
+
+@param trait1 {Object|Function}
+ Trait or property map to compose new trait from.
+@param trait2 {Object|Function}
+ Trait or property map to compose new trait from.
+@param ... {Object|Function}
+ Traits or property maps to compose new trait from.
+
+@returns {Function}
+ New trait containing the combined properties of all the traits.
+</api>
+
+<api name="required">
+@property {Object}
+Singleton, used during trait composition to define "required" properties.
+
+**Example:**
+
+ var Enumerable = Trait.compose({
+ list: Trait.required,
+ forEach: function forEach(consumer) {
+ return this.list.forEach(consumer);
+ }
+ });
+
+ let c1 = Enumerable(); // Error: Missing required property: list
+
+ var EnumerableList = List.compose({
+ get list() this._list.slice(0)
+ }, Enumerable);
+
+ let c2 = EnumerableList();
+ c2.add('test')
+ c2.length // 1
+ c2.list[0] // 'test'
+ c2.forEach(console.log) // > info: 'test 0 test'
+
+</api>
+
+
+<api name="resolve">
+@method
+Composes a new trait that has all the same properties
+as the trait on which it is called, except that each property listed
+in the `resolutions` argument will be renamed from the name
+of the property in the `resolutions` argument to its value.
+And if its value is `null`, the property will become required.
+
+**Example:**
+
+ var Range = List.resolve({
+ constructor: null,
+ add: '_add',
+ }).compose({
+ min: null,
+ max: null,
+ get list() this._list.slice(0),
+ constructor: function Range(min, max) {
+ this.min = min;
+ this.max = max;
+ this._list = [];
+ },
+ add: function(item) {
+ if (item <= this.max && item >= this.min)
+ this._add(item)
+ }
+ });
+
+
+ let r = Range(0, 10);
+ r.min; // 0
+ r.max; // 10
+ r.length; // 0;
+ r.add(5);
+ r.length; // 1
+ r.add(12);
+ r.length; // 1 (12 was not in a range)
+
+@param resolutions {Object}
+@returns {Function}
+ New resolved trait.
+</api>
+
+<api name="override">
+@method
+Composes a new trait with all of the combined properties of `this` and the
+argument traits. In contrast to `compose`, `override` immediately resolves
+all conflicts resulting from this composition by overriding the properties of
+later traits. Trait priority is from left to right. I.e. the properties of
+the leftmost trait are never overridden.
+
+**Example:**
+
+ // will compose trait with conflict property 'constructor'
+ var ConstructableList = List.compose({
+ constructor: function List() this._list = Array.slice(arguments)
+ });
+ // throws error with message 'Remaining conflicting property: constructor'
+ ConstructableList(1, 2, 3);
+
+ var ConstructableList = List.override({
+ constructor: function List() this._list = Array.slice(arguments)
+ });
+ ConstructableList(1, 2, 3).length // 3
+
+@param trait1 {Object|Function}
+ Trait or property map to compose new trait from.
+@param trait2 {Object|Function}
+ Trait or property map to compose new trait from.
+@param ... {Object|Function}
+ Traits or property maps to compose new trait from.
+
+@returns {Function}
+ New trait containing the combined properties of all the traits.
+</api>
+
+<api name="_public">
+@property {Object}
+Internal property of instance representing public API that is exposed to the
+consumers of an instance.
+</api>
+
+<api name='toString'>
+@method
+Textual representation of an object. All the traits will return:
+`'[object Trait]'` string, unless they have `constructor` property, in that
+case string `'Trait'` is replaced with the name of `constructor` property.
+
+**Example:**
+
+ var MyTrait = Trait.compose({
+ constructor: function MyTrait() {
+ // do your initialization here
+ }
+ });
+ MyTrait().toString(); // [object MyTrait]
+
+</api>
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/unit-test.md b/tools/addon-sdk-1.7/packages/api-utils/docs/unit-test.md
new file mode 100644
index 0000000..6962c41
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/unit-test.md
@@ -0,0 +1,393 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Atul Varma [atul@mozilla.com] -->
+<!-- edited by Noelle Murata [fiveinchpixie@gmail.com] -->
+<!-- edited by Shane Tomlinson[stomlinson@mozilla.com] -->
+
+The `unit-test` module makes it easy to find and run unit tests.
+
+<api name="test">
+@class
+Each function which represents a test case is passed a single argument
+`test`, which represents the test runner.
+
+<api name="pass">
+@method
+ Marks a test as passing, with the given optional message.
+
+@param [message] {string}
+ Optional passing message.
+</api>
+
+
+<api name="fail">
+@method
+ Marks a test as failing, with the given optional message.
+
+@param [message] {string}
+ Optional failure message.
+</api>
+
+<api name="expectFail">
+@method
+ *experimental* Expect the test enclosed within `func` to fail.
+
+@param func {function}
+ A function that should contain a test that is expected to fail.
+</api>
+
+<api name="exception">
+@method
+ Marks a test as failing due to the given exception having been thrown.
+ This can be put in a `catch` clause.
+
+@param e {exception}
+ An exception.
+</api>
+
+<api name="assert">
+@method
+ Ensures that `a` has a truthy value.
+
+@param a {value}
+ Value to verify.
+@param [message] {string}
+ The test is marked as passing or failing depending on the result, logging
+ *message* with it.
+</api>
+
+
+<api name="assertEqual">
+@method
+ Ensures that `a == b` without recursing into `a` or `b`.
+
+@param a {value}
+ A value.
+
+@param b {value}
+ Another value.
+
+@param [message] {string}
+ The test is marked as passing or failing depending on the result, logging
+ *message* with it.
+</api>
+
+<api name="assertNotEqual">
+@method
+ Ensures that `a != b` without recursing into `a` or `b`.
+
+@param a {value}
+ A value.
+
+@param b {value}
+ Another value.
+
+@param [message] {string}
+ The test is marked as passing or failing depending on the result, logging
+ *message* with it.
+</api>
+
+<api name="assertStrictEqual">
+@method
+ Ensures that `a === b` without recursing into `a` or `b`.
+
+@param a {value}
+ A value.
+
+@param b {value}
+ Another value.
+
+@param [message] {string}
+ The test is marked as passing or failing depending on the result, logging
+ *message* with it.
+</api>
+
+
+<api name="assertNotStrictEqual">
+@method
+ Ensures that `a !== b` without recursing into `a` or `b`.
+
+@param a {value}
+ A value.
+
+@param b {value}
+ Another value.
+
+@param [message] {string}
+ The test is marked as passing or failing depending on the result, logging
+ *message* with it.
+</api>
+
+<api name="assertMatches">
+@method
+ Ensures that the given string matches the given regular expression.
+ If it does, marks a test as passing, otherwise marks a test as
+ failing.
+
+@param string {string}
+ The string to test.
+
+@param regexp {regexp}
+ The string should match this regular expression.
+
+@param [message] {string}
+ The test is marked as passing or failing depending on the result, logging
+ *message* with it.
+</api>
+
+
+<api name="assertRaises">
+@method
+ Calls the function `func` with no arguments, expecting an exception
+ to be raised. If nothing is raised, marks the test as failing. If an
+ exception is raised, the exception's `message` property is
+ compared with `predicate`: if `predicate` is a string, then a
+ simple equality comparison is done with `message`. Otherwise,
+ if `predicate` is a regular expression, `message` is tested
+ against it.
+
+@param func {function}
+ A function that should raise an exception when called.
+
+@param predicate {string,regexp}
+ A string or regular expression to compare to the exception's message.
+
+@param [message] {string}
+ Depending on the outcome, a test is marked as passing or failing, and
+ *message* is logged.
+</api>
+
+
+<api name="assertFunction">
+@method
+ Ensures that `a` is a function.
+
+@param a {value}
+ A value.
+
+@param [message] {string}
+ The test is marked as passing or failing depending on the result, logging
+ *message* with it.
+
+</api>
+
+
+<api name="assertUndefined">
+@method
+ Ensures that `a` is `undefined`. `null`, `0`, and `false` will all fail.
+
+@param a {value}
+ A value.
+
+@param [message] {string}
+ The test is marked as passing or failing depending on the result, logging
+ *message* with it.
+
+</api>
+
+
+<api name="assertNotUndefined">
+@method
+ Ensures that `a` is not `undefined`. `null`, `0`, and `false` will all pass.
+
+@param a {value}
+ A value.
+
+@param [message] {string}
+ The test is marked as passing or failing depending on the result, logging
+ *message* with it.
+
+</api>
+
+
+<api name="assertNull">
+@method
+ Ensures that `a` is `null`. `undefined`, `0`, and `false` will all fail.
+
+@param a {value}
+ A value.
+
+@param [message] {string}
+ The test is marked as passing or failing depending on the result, logging
+ *message* with it.
+
+</api>
+
+
+<api name="assertNotNull">
+@method
+ Ensures that `a` is not `null`. `undefined`, `0`, and `false` will all pass.
+
+@param a {value}
+ A value.
+
+@param [message] {string}
+ The test is marked as passing or failing depending on the result, logging
+ *message* with it.
+
+</api>
+
+
+<api name="assertObject">
+@method
+ Ensures that `a` is an object. A function, string, or number will fail.
+
+@param a {value}
+ A value.
+
+@param [message] {string}
+ The test is marked as passing or failing depending on the result, logging
+ *message* with it.
+
+</api>
+
+
+<api name="assertString">
+@method
+ Ensures that `a` is a string.
+
+@param a {value}
+ A value.
+
+@param [message] {string}
+ The test is marked as passing or failing depending on the result, logging
+ *message* with it.
+
+</api>
+
+
+<api name="assertArray">
+@method
+ Ensures that `a` is an array.
+
+@param a {value}
+ A value.
+
+@param [message] {string}
+ The test is marked as passing or failing depending on the result, logging
+ *message* with it.
+
+</api>
+
+
+<api name="assertNumber">
+@method
+ Ensures that `a` is a number.
+
+@param a {value}
+ A value.
+
+@param [message] {string}
+ The test is marked as passing or failing depending on the result, logging
+ *message* with it.
+
+</api>
+
+
+<api name="waitUntilDone">
+@method
+ Puts the test runner into asynchronous testing mode, waiting up to
+ *timeout* milliseconds for `test.done()` to be called. This
+ is intended for use in situations where a test suite schedules a
+ callback, calls `test.waitUntilDone()`, and then calls
+ `test.done()` in the callback.
+
+@param [timeout] {integer}
+ If this number of milliseconds elapses and `test.done()` has not yet been
+ called, the test is marked as failing.
+</api>
+
+
+<api name="done">
+@method
+ Marks a test as being complete. Assumes a previous call to
+ `test.waitUntilDone()`.
+</api>
+
+</api>
+
+
+<api name="waitUntil">
+@method
+ Ensures that `a` returns a truthy value within a reasonable amount of time.
+
+@param a {function}
+ Function that returns the value to verify.
+@param [message] {string}
+ The test is marked as passing or failing depending on the result, logging
+ *message* with it.
+</api>
+
+
+<api name="waitUntilEqual">
+@method
+ Ensures that `a == b` returned values or values without without recursing
+ into `a` or `b`.
+
+@param a {Function}
+ A value, or a function that returns a value.
+
+@param b {value}
+ Another value, or a function that returns value.
+
+@param [message] {string}
+ The test is marked as passing or failing depending on the result, logging
+ *message* with it.
+</api>
+
+<api name="waitUntilNotEqual">
+@method
+ Ensures that `a != b` without recursing into `a` or `b`.
+
+@param a {Function}
+ A value, or a function that returns a value.
+
+@param b {value}
+ Another value, or a function that returns another value.
+
+@param [message] {string}
+ The test is marked as passing or failing depending on the result, logging
+ *message* with it.
+</api>
+
+
+<api name="waitUntilMatches">
+@method
+ Ensures that the given string matches the given regular expression.
+ If it does, marks the test as passing, otherwise marks the test as
+ failing.
+
+@param string {Function}
+ A function that returns the string to test.
+
+@param regexp {regexp}
+ The string should match this regular expression.
+
+@param [message] {string}
+ The test is marked as passing or failing depending on the result, logging
+ *message* with it.
+</api>
+
+
+
+<api name="findAndRunTests">
+@function
+ The list of directories is searched for SecurableModules that start
+ with the prefix `test-`. Each module matching this criteria is
+ expected to export functions that are test cases or a suite of test
+ cases; each is called with a single argument, which is a Test Runner
+ Object.
+
+@param options {object}
+ An object with the following properties:
+ @prop dirs {string}
+ A list of absolute paths representing directories to search
+ for tests in. It's assumed that all of these directories are also
+ in the module search path, i.e. any JS files found in them are
+ SecurableModules that can be loaded via a call to
+ `require()`.
+ @prop onDone {function}
+ A function to call when testing is complete.
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/unload.md b/tools/addon-sdk-1.7/packages/api-utils/docs/unload.md
new file mode 100644
index 0000000..8a76b3f
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/unload.md
@@ -0,0 +1,61 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Atul Varma [atul@mozilla.com] -->
+<!-- contributed by Drew Willcoxon [adw@mozilla.com] -->
+<!-- edited by Noelle Murata [fiveinchpixie@gmail.com] -->
+
+The `unload` module allows modules to register callbacks that are called
+when they are unloaded. It is similar to the CommonJS module of the same
+name in the [Narwhal][] platform.
+
+[Narwhal]: http://narwhaljs.org/
+
+<api name="ensure">
+@function
+ Calling `ensure()` on an object does two things:
+
+ 1. It replaces a destructor method with a wrapper method that will never call
+ the destructor more than once.
+ 2. It ensures that this wrapper method is called when `send()` is
+ called.
+
+ Therefore, when you register an object with `ensure()`, you can call its
+ destructor method yourself, you can let it happen for you, or you can do both.
+
+ The destructor will be called with a single argument describing the reason
+ for the unload; see `when()`. If `object` does not have the expected
+ destructor method, then an exception is thrown when `ensure()` is called.
+
+@param object {object}
+ An object that defines a destructor method.
+@param [name] {string}
+ Optional name of the destructor method. Default is `unload`.
+</api>
+
+<api name="when">
+@function
+ Registers a function to be called when `send()` is called.
+
+@param callback {function}
+ A function that will be called when `send()` is called. It is called with a
+ single argument, one of the following strings describing the reason for
+ unload: `"uninstall"`, `"disable"`, `"shutdown"`, `"upgrade"`, or
+ `"downgrade"`. (On Gecko 1.9.2-based applications such as Firefox 3.6,
+ `"upgrade"` and `"downgrade"` are not available, and `"shutdown"` will be sent
+ in their place.) If a reason could not be determined, `undefined` will be
+ passed instead. Note that if an add-on is unloaded with reason `"disable"`,
+ it will not be notified about `"uninstall"` while it is disabled. A solution
+ to this issue is being investigated; see bug 571049.
+</api>
+
+<api name="send">
+@function
+ Sends an "unload signal", thereby triggering all callbacks registered via
+ `when()`. In general, this function need not be manually called; it is
+ automatically triggered by the embedder.
+
+@param [reason] {string}
+ An optional string describing the reason for unload; see `unload.when()`.
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/url.md b/tools/addon-sdk-1.7/packages/api-utils/docs/url.md
new file mode 100644
index 0000000..2974797
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/url.md
@@ -0,0 +1,85 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Atul Varma [atul@mozilla.com] -->
+<!-- edited by Noelle Murata [fiveinchpixie@gmail.com] -->
+
+
+The `url` module provides functionality for the parsing and retrieving of URLs.
+
+<api name="URL">
+@class
+<api name="URL">
+@constructor
+ The URL constructor creates an object that represents a URL, verifying that
+ the provided string is a valid URL in the process. Any API in the SDK which
+ has a URL parameter will accept `URL` objects, not raw strings, unless
+ otherwise noted.
+
+@param source {string}
+ A string to be converted into a URL. If `source` is not a valid URI, this
+ constructor will throw an exception.
+
+@param [base] {string}
+ An optional string used to resolve relative `source` URLs into absolute ones.
+</api>
+
+<api name="scheme">
+@property {string}
+ The name of the protocol in the URL.
+</api>
+
+<api name="userPass">
+@property {string}
+ The username:password part of the URL, `null` if not present.
+</api>
+
+<api name="host">
+@property {string}
+ The host of the URL, `null` if not present.
+</api>
+
+<api name="port">
+@property {integer}
+ The port number of the URL, `null` if none was specified.
+</api>
+
+<api name="path">
+@property {string}
+ The path component of the URL.
+</api>
+
+<api name="toString">
+@method
+ Returns a string representation of the URL.
+@returns {string}
+ The URL as a string.
+</api>
+</api>
+
+<api name="toFilename">
+@function
+ Attempts to convert the given URL to a native file path. This function will
+ automatically attempt to resolve non-file protocols, such as the `resource:`
+ protocol, to their place on the file system. An exception is raised if the URL
+ can't be converted; otherwise, the native file path is returned as a string.
+
+@param url {string}
+ The URL, as a string, to be converted.
+
+@returns {string}
+ The converted native file path as a string.
+</api>
+
+<api name="fromFilename">
+@function
+ Converts the given native file path to a `file:` URL.
+
+@param path {string}
+ The native file path, as a string, to be converted.
+
+@returns {string}
+ The converted URL as a string.
+</api>
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/uuid.md b/tools/addon-sdk-1.7/packages/api-utils/docs/uuid.md
new file mode 100644
index 0000000..429e3a0
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/uuid.md
@@ -0,0 +1,27 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+Module `uuid` provides low level API for generating / parsing UUID, that may
+be necessary when hacking on internals of the platform.
+
+
+## Generate UUID
+
+Module exports `uuid` function. When called without arguments it will uses
+platform-specific methods to obtain a `nsID` that can be considered to be
+globally unique.
+
+ let uuid = require('api-utils/uuid').uuid()
+
+## Parsing UUID
+
+Sometimes one might need to create `nsID` from an existing UUID string. Same
+`uuid` function may be used to parse such UUID strings into an `nsID`:
+
+ let { uuid } = require('api-utils/uuid');
+ let firefoxUUID = uuid('{ec8030f7-c20a-464f-9b0e-13a3a9e97384}');
+
+For more details about UUID representations and what they are used for by the
+platform see MDN documentation for
+[JSID](https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIJSID)
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/window-utils.md b/tools/addon-sdk-1.7/packages/api-utils/docs/window-utils.md
new file mode 100644
index 0000000..1435fd2
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/window-utils.md
@@ -0,0 +1,88 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Drew Willcoxon [adw@mozilla.com] -->
+<!-- edited by Erik Vold [erikvvold@gmail.com] -->
+
+The `window-utils` module provides helpers for accessing and tracking
+application windows. These windows implement the [`nsIDOMWindow`][nsIDOMWindow]
+interface.
+
+[nsIDOMWindow]: http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/base/nsIDOMWindow.idl
+
+<api name="WindowTracker">
+@class
+`WindowTracker` objects make it easy to "monkeypatch" windows when a program is
+loaded and "un-monkeypatch" those windows when the program is unloaded. For
+example, if a Firefox add-on needs to add a status bar icon to all browser
+windows, it can use a single `WindowTracker` object to gain access to windows
+when they are opened and closed and also when the add-on is loaded and unloaded.
+
+When a window is opened or closed, a `WindowTracker` notifies its delegate
+object, which is passed to the constructor. The delegate is also notified of
+all windows that are open at the time that the `WindowTracker` is created and
+all windows that are open at the time that the `WindowTracker` is unloaded. The
+caller can therefore use the same code to act on all windows, regardless of
+whether they are currently open or are opened in the future, or whether they are
+closed while the parent program is loaded or remain open when the program is
+unloaded.
+
+When a window is opened or when a window is open at the time that the
+`WindowTracker` is created, the delegate's `onTrack()` method is called and
+passed the window.
+
+When a window is closed or when a window is open at the time that the
+`WindowTracker` is unloaded, the delegate's `onUntrack()` method is called and
+passed the window. (The `WindowTracker` is unloaded when its its `unload()`
+method is called, or when its parent program is unloaded, disabled, or
+uninstalled, whichever comes first.)
+
+**Example**
+
+ var delegate = {
+ onTrack: function (window) {
+ console.log("Tracking a window: " + window.location);
+ // Modify the window!
+ },
+ onUntrack: function (window) {
+ console.log("Untracking a window: " + window.location);
+ // Undo your modifications!
+ }
+ };
+ var winUtils = require("window-utils");
+ var tracker = new winUtils.WindowTracker(delegate);
+
+<api name="WindowTracker">
+@constructor
+ A `WindowTracker` object listens for openings and closings of application
+ windows.
+@param delegate {object}
+ An object that implements `onTrack()` and `onUntrack()` methods.
+@prop onTrack {function}
+ A function to be called when a window is open or loads, with the window as the
+ first and only argument.
+@prop [onUntrack] {function}
+ A function to be called when a window unloads, with the window as the first
+ and only argument.
+</api>
+</api>
+
+<api name="windowIterator">
+@function
+ An iterator for windows currently open in the application.
+
+**Example**
+
+ var winUtils = require("window-utils");
+ for (window in winUtils.windowIterator())
+ console.log("An open window! " + window.location);
+
+</api>
+
+<api name="closeOnUnload">
+@function
+ Marks an application window to be closed when the program is unloaded.
+@param window {window}
+ The window to close.
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/window/utils.md b/tools/addon-sdk-1.7/packages/api-utils/docs/window/utils.md
new file mode 100644
index 0000000..276a17a
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/window/utils.md
@@ -0,0 +1,90 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+The `window/utils` module provides helper functions for working with
+application windows.
+
+### getInnerId
+
+Returns the ID of the given window's current inner window.
+
+### getOuterId
+
+Returns the ID of the given window's outer window.
+
+### getXULWindow
+
+Module provides `getXULWindow` function that can be used get access
+[nsIXULWindow](https://developer.mozilla.org/en/nsIDOMWindow) for the given
+[nsIDOMWindow](https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIXULWindow):
+
+ let { Ci } = require('chrome');
+ let utils = require('api-utils/window-utils');
+ let active = utils.activeBrowserWindow;
+ active instanceof Ci.nsIXULWindow // => false
+ utils.getXULWindow(active) instanceof Ci.nsIXULWindow // => true
+
+### getBaseWindow
+
+Module provides `getBaseWindow` function that can be used get access
+[nsIBaseWindow](http://mxr.mozilla.org/mozilla-central/source/widget/nsIBaseWindow.idl)
+for the given [nsIDOMWindow](https://developer.mozilla.org/en/nsIDOMWindow):
+
+ let { Ci } = require('chrome');
+ let utils = require('api-utils/window-utils');
+ let active = utils.activeBrowserWindow;
+ active instanceof Ci.nsIBaseWindow // => false
+ utils.getBaseWindow(active) instanceof Ci.nsIBaseWindow // => true
+
+### open
+
+Module exports `open` function that may be used to open top level
+(application) windows. Function takes `uri` of the window document as a first
+argument and optional hash of `options` as second argument.
+
+ let { open } = require('api-utils/window-utils');
+ let window = open('data:text/html,Hello Window');
+
+Following options may be provided to configure created window behavior:
+
+- `parent`
+If provided must be `nsIDOMWindow` and will be used as parent for the created
+window.
+
+- `name`
+Optional name that will be assigned to the window.
+
+- `features`
+Hash of options that will be serialized to features string. See
+[features documentation](https://developer.mozilla.org/en/DOM/window.open#Position_and_size_features)
+for more details.
+
+ let { open } = require('api-utils/window/utils');
+ let window = open('data:text/html,Hello Window', {
+ name: 'jetpack window',
+ features: {
+ width: 200,
+ height: 50,
+ popup: true
+ }
+ });
+
+### backgroundify
+
+Module exports `backgroundify` function that takes `nsIDOMWindow` and
+removes it from the application's window registry, so that they won't appear
+in the OS specific window lists for the application.
+
+ let { backgroundify, open } = require('api-utils/window/utils');
+ let bgwin = backgroundify(open('data:text/html,Hello backgroundy'));
+
+Optionally more configuration options via second `options` argument. If
+`options.close` is `false` unregistered window won't automatically
+be closed on application quit, preventing application from quitting. While this
+is possible you should make sure to close all such windows manually:
+
+ let { backgroundify, open } = require('api-utils/window-utils');
+ let bgwin = backgroundify(open('data:text/html,Foo'), {
+ close: false
+ });
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/xhr.md b/tools/addon-sdk-1.7/packages/api-utils/docs/xhr.md
new file mode 100644
index 0000000..d0381c0
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/xhr.md
@@ -0,0 +1,95 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Atul Varma [atul@mozilla.com] -->
+<!-- edited by Noelle Murata [fiveinchpixie@gmail.com] -->
+
+The `xhr` module provides access to `XMLHttpRequest` functionality, also known
+as AJAX.
+
+## Limitations ##
+
+The `XMLHttpRequest` object is currently fairly limited, and does not
+yet implement the `addEventListener()` or `removeEventListener()`
+methods. It also doesn't yet implement the `upload` property.
+
+Furthermore, the `XMLHttpRequest` object does not currently support
+the `mozBackgroundRequest` property. All security UI, such as
+username/password prompts, are automatically suppressed, so if
+required authentication information isn't passed to the `open()`
+method, the request will fail.
+
+## Resource Use ##
+
+Whenever this module is unloaded, all in-progress requests are immediately
+aborted.
+
+## Security Concerns ##
+
+By default, the `XMLHttpRequest` object grants full access to any
+protocol scheme, which means that it can be used to read from (but not
+write to) the host system's entire filesystem. It also has unfettered
+access to any local area networks, VPNs, and the internet.
+
+### Threat Model ###
+
+The `XMLHttpRequest` object can be used by an add-on to "phone
+home" and transmit potentially sensitive user data to third
+parties.
+
+If access to the filesystem isn't prevented, it could easily be used
+to access sensitive user data, though this may be inconsequential if
+the client can't access the network.
+
+If access to local area networks isn't prevented, malicious code could access
+sensitive data.
+
+If transmission of cookies isn't prevented, malicious code could access
+sensitive data.
+
+Attenuating access based on a regular expression may be ineffective if
+it's easy to write a regular expression that *looks* safe but contains
+a special character or two that makes it far less secure than it seems
+at first glance.
+
+### Possible Attenuations ###
+
+<span class="aside">
+We may also want to consider attenuating further based on domain name
+and possibly even restricting the protocol to `https:` only, to reduce
+risk.
+</span>
+
+Before being exposed to unprivileged code, this object needs
+to be attenuated in such a way that, at the very least, it can't
+access the user's filesystem. This can probably be done most securely
+by white-listing the protocols that can be used in the URL passed to
+the `open()` method, and limiting them to `http:`, `https:`, and
+possibly a special scheme that can be used to access the add-on's
+packaged, read-only resources.
+
+Finally, we need to also consider attenuating http/https requests such
+that they're "sandboxed" and don't communicate potentially sensitive
+cookie information.
+
+<api name="XMLHttpRequest">
+@class
+
+<api name="XMLHttpRequest">
+@constructor
+ Creates an `XMLHttpRequest`. This is a constructor, so its use should always
+ be preceded by the `new` operator. For more information about
+ `XMLHttpRequest` objects, see the MDC page on
+ [Using XMLHttpRequest](https://developer.mozilla.org/En/Using_XMLHttpRequest)
+ and the Limitations section in this page.
+</api>
+</api>
+
+<api name="getRequestCount">
+@function
+ Returns the number of `XMLHttpRequest` objects that are alive (i.e., currently
+ active or about to be).
+@returns {integer}
+ The number of live `XMLHttpRequest` objects.
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/xpcom.md b/tools/addon-sdk-1.7/packages/api-utils/docs/xpcom.md
new file mode 100644
index 0000000..6d96650
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/xpcom.md
@@ -0,0 +1,216 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+Module `xpcom` provides low level API for implementing and registering /
+unregistering various XCOM interfaces.
+
+## Implementing XPCOM interfaces
+
+Module exports `Unknow` exemplar object, that may be extended to implement
+specific XCOM interface(s). For example [nsIObserver]
+(https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIObserver) may be
+implemented as follows:
+
+ const { Unknown } = require('api-utils/xpcom');
+ const { Cc, Ci } = require('chrome')
+ const observerService = Cc["@mozilla.org/observer-service;1"].
+ getService(Ci.nsIObserverService);
+
+ // Create my observer exemplar
+ const SleepObserver = Unknown.extend({
+ interfaces: [ 'nsIObserver' ], // Interfaces component implements
+ topic: 'sleep_notification',
+ initialize: function(fn) { this.fn = fn },
+ register: function register() {
+ observerService.addObserver(this, this.topic, false);
+ },
+ unregister: function() {
+ addObserver.removeObserver(this, this.topic, false);
+ },
+ observe: function observe(subject, topic, data) {
+ this.fn({
+ subject: subject,
+ type: topic,
+ data: data
+ });
+ }
+ });
+
+ // create instances of observers
+ let observer = SleepObserver.new(function(event) {
+ console.log('Going to sleep!')
+ });
+ // register observer
+ observer.register();
+
+## Implementing XCOM factories
+
+Module exports `Factory` exemplar, object that may be used to create objects
+implementing
+[nsIFactory](https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIFactory)
+interface:
+
+ const { Factory } = require('api-utils/xpcom');
+ let Request = Unknown.extend({
+ interfaces: [ 'nsIRequest' ],
+ initialize: function initialize() {
+ this.pending = false;
+ // Do some initialization
+ },
+ isPending: function() { return this.pending },
+ resume: function() { /* Implementation */ },
+ suspend: function() { /* Implementation */ },
+ cancel: function() { /* Implementation */ },
+ initiate: function() {
+ this.pending = true;
+ /* Implementation */
+ }
+ });
+
+ let requestFactory = Factory.new({ component: Request });
+
+Factories registered into a runtime may be accessed from the rest of the
+application via standard XPCOM API using factory's auto generated `id`
+(optionally you could specify specific `id` by passing it as an option):
+
+ let request = Components.classesByID[requestFactory.id].
+ createInstance(Ci.nsIRequest);
+ request.isPending() // => false
+
+Be aware that traditional XPCOM API will always return a wrapped JS objects
+exposing only properties defined by a given interface (`nsIRequest`) in our
+case:
+
+ request.initiate() // TypeError: request.initiate is not a function
+
+You still can expose unwrapped JS object, by a special `wrappedJSObject`
+property of the component:
+
+ let Request = Unknown.extend({
+ get wrappedJSObject() this,
+ interfaces: [ 'nsIRequest' ],
+ initialize: function initialize() {
+ this.pending = false;
+ // Do some initialization
+ },
+ isPending: function() { return this.pending },
+ resume: function() { /* Implementation */ },
+ suspend: function() { /* Implementation */ },
+ cancel: function() { /* Implementation */ },
+ initiate: function() {
+ this.pending = true;
+ /* Implementation */
+ }
+ });
+
+ let requestFactory = Factory.new({ component: Request });
+ let request = Components.classesByID[requestFactory.id].
+ createInstance(Ci.nsIRequest);
+ request.isPending(); // => false
+ request.wrappedJSObject.initiate();
+ request.isPending(); // => true
+
+Optionally `Factory.new` may be passed globally unique string in a format of:
+`'@domain.com/unique/identifier;1'` as a `contract` option in order to
+associate it with it:
+
+ let namedFactory = Factory.new({
+ contract: '@examples.com/request/factory;1',
+ component: Request
+ });
+
+Such factories when registered can be accessed form rest of the application by
+human readable `contract` strings:
+
+ let request = Components.classes['@examples.com/request/factory;1'].
+ createInstance(Components.interfaces.nsIRequest);
+
+In addition factories associated with a given `contract` may be replaced at
+runtime:
+
+ let renewedFactory = Factory.new({
+ contract: '@examples.com/request/factory;1',
+ component: Unknown.extend({ /* Implementation */ })
+ })
+
+Unfortunately commonly used `Components.classes` won't get updated at runtime
+but there is an alternative, more verbose way to access last registered factory
+for a given `contract`:
+
+ let id = Components.manager.QueryInterface(Ci.nsIComponentRegistrar).
+ contractIDToCID('@examples.com/request/factory;1');
+ Components.classesByID[requestFactory.id].
+ createInstance(Ci.nsISupports);
+
+Module also exports `factoryByContract` function to simplify this:
+
+ factoryByContract('@examples.com/request/factory;1').
+ createInstance(Ci.nsISupports);
+
+It's also recommended to construct factories with an optional `description`
+property, providing human readable description of it:
+
+ let factory = Factory.new({
+ contract: '@examples.com/request/factory;1',
+ description: 'Super duper request factory',
+ component: Request
+ });
+
+## Registering / Unregistering factories
+
+All factories created using `Factory.new` get automatically registered into
+runtime unless explicitly specified otherwise by setting `register` option to
+`false`:
+
+ var factoryToRegister = Factory.new({
+ register: false,
+ component: Unknown.extend({ /* Implementation */ })
+ });
+
+Such factories still may be registered manually using exported `register`
+function:
+
+ const { register } = require('api-utils/xpcom');
+ register(factoryToRegister);
+
+All factories created using `Factory.new` also get unregistered automatically
+when add-on is unloaded. This also can be disabled by setting `unregister`
+option to `false`.
+
+ var factoryToUnregister = Service.new({
+ unregister: false,
+ component: Unknown.extend({ /* Implementation */ })
+ });
+
+All registered services may be unregistered at any time using exported
+`unregister` function:
+
+ unregister(factoryToUnregister);
+
+## Implementing XCOM services
+
+Module exports `Service` exemplar object, that has exact same API as `Factory`
+and can be used to register services:
+
+ const { Service } = require('api-utils/xpcom');
+ let service = Service.new({
+ contract: '@examples/demo/service;1',
+ description: 'My demo service',
+ component: Unknown.extend({
+ // Implementation
+ get wrappedJSObject() this
+ })
+ });
+
+Registered services can be accessed through the rest of the application via
+standard XPCOM API:
+
+ let s = Components.classes['@examples/demo/service;1'].
+ getService(Components.interfaces.nsISupports);
+
+In contrast to factories, services do not create instances of enclosed
+components, they expose component itself. Also please note that idiomatic way
+to work with a service is via `getService` method:
+
+ s.wrappedJSObject === service.component // => true
diff --git a/tools/addon-sdk-1.7/packages/api-utils/docs/xul-app.md b/tools/addon-sdk-1.7/packages/api-utils/docs/xul-app.md
new file mode 100644
index 0000000..597af56
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/docs/xul-app.md
@@ -0,0 +1,76 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!-- contributed by Drew Willcoxon [adw@mozilla.com] -->
+
+The `xul-app` module provides facilities for introspecting the application on
+which your program is running.
+
+With the exception of `ids`, each of these properties exposes the attribute of
+the same name on the [`nsIXULAppInfo`][nsIXULAppInfo] interface. For more
+information, see the [MDC documentation][].
+
+[nsIXULAppInfo]: http://mxr.mozilla.org/mozilla-central/source/xpcom/system/nsIXULAppInfo.idl
+[MDC documentation]: https://developer.mozilla.org/en/nsIXULAppInfo
+
+<api name="ID">
+@property {string}
+ The GUID of the host application. For example, for Firefox this value is
+ `"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"`.
+</api>
+
+<api name="name">
+@property {string}
+ The host application name. For example, `"Firefox"`.
+</api>
+
+<api name="version">
+@property {string}
+ The host application version.
+</api>
+
+<api name="platformVersion">
+@property {string}
+ The Gecko/XULRunner platform version.
+</api>
+
+<api name="ids">
+@property {object}
+ A mapping of application names to their IDs. For example,
+ `ids["Firefox"] == "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"`.
+</api>
+
+<api name="is">
+@function
+ Checks whether the host application is the given application.
+@param name {string}
+ A host application name.
+@returns {boolean}
+ True if the host application is `name` and false otherwise.
+</api>
+
+<api name="isOneOf">
+@function
+ Checks whether the host application is one of the given applications.
+@param names {array}
+ An array of host application names.
+@returns {boolean}
+ True if the host application is one of the `names` and false otherwise.
+</api>
+
+<api name="versionInRange">
+@function
+ Compares a given version to a version range. See the [MDC documentation](https://developer.mozilla.org/en/Toolkit_version_format#Comparing_versions)
+ for details on version comparisons.
+@param version {string}
+ The version to compare.
+@param lowInclusive {string}
+ The lower bound of the version range to compare. The range includes this
+ bound.
+@param highExclusive {string}
+ The upper bound of the version range to compare. The range does not include
+ this bound.
+@returns {boolean}
+ True if `version` falls in the given range and false otherwise.
+</api>
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/api-utils.js b/tools/addon-sdk-1.7/packages/api-utils/lib/api-utils.js
new file mode 100644
index 0000000..94d13b7
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/api-utils.js
@@ -0,0 +1,153 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const memory = require("api-utils/memory");
+// The possible return values of getTypeOf.
+const VALID_TYPES = [
+ "array",
+ "boolean",
+ "function",
+ "null",
+ "number",
+ "object",
+ "string",
+ "undefined",
+];
+
+/**
+ * Returns a function C that creates instances of privateCtor. C may be called
+ * with or without the new keyword. The prototype of each instance returned
+ * from C is C.prototype, and C.prototype is an object whose prototype is
+ * privateCtor.prototype. Instances returned from C will therefore be instances
+ * of both C and privateCtor. Additionally, the constructor of each instance
+ * returned from C is C.
+ *
+ * @param privateCtor
+ * A constructor.
+ * @return A function that makes new instances of privateCtor.
+ */
+exports.publicConstructor = function publicConstructor(privateCtor) {
+ function PublicCtor() {
+ let obj = { constructor: PublicCtor, __proto__: PublicCtor.prototype };
+ memory.track(obj, privateCtor.name);
+ privateCtor.apply(obj, arguments);
+ return obj;
+ }
+ PublicCtor.prototype = { __proto__: privateCtor.prototype };
+ return PublicCtor;
+};
+
+/**
+ * Returns a validated options dictionary given some requirements. If any of
+ * the requirements are not met, an exception is thrown.
+ *
+ * @param options
+ * An object, the options dictionary to validate. It's not modified.
+ * If it's null or otherwise falsey, an empty object is assumed.
+ * @param requirements
+ * An object whose keys are the expected keys in options. Any key in
+ * options that is not present in requirements is ignored. Each value
+ * in requirements is itself an object describing the requirements of
+ * its key. There are four optional keys in this object:
+ * map: A function that's passed the value of the key in options.
+ * map's return value is taken as the key's value in the final
+ * validated options, is, and ok. If map throws an exception
+ * it's caught and discarded, and the key's value is its value in
+ * options.
+ * is: An array containing any number of the typeof type names. If
+ * the key's value is none of these types, it fails validation.
+ * Arrays and null are identified by the special type names
+ * "array" and "null"; "object" will not match either. No type
+ * coercion is done.
+ * ok: A function that's passed the key's value. If it returns
+ * false, the value fails validation.
+ * msg: If the key's value fails validation, an exception is thrown.
+ * This string will be used as its message. If undefined, a
+ * generic message is used, unless is is defined, in which case
+ * the message will state that the value needs to be one of the
+ * given types.
+ * @return An object whose keys are those keys in requirements that are also in
+ * options and whose values are the corresponding return values of map
+ * or the corresponding values in options. Note that any keys not
+ * shared by both requirements and options are not in the returned
+ * object.
+ */
+exports.validateOptions = function validateOptions(options, requirements) {
+ options = options || {};
+ let validatedOptions = {};
+ let mapThrew = false;
+
+ for (let [key, req] in Iterator(requirements)) {
+ let [optsVal, keyInOpts] = (key in options) ?
+ [options[key], true] :
+ [undefined, false];
+ if (req.map) {
+ try {
+ optsVal = req.map(optsVal);
+ }
+ catch (err) {
+ mapThrew = true;
+ }
+ }
+ if (req.is) {
+ // Sanity check the caller's type names.
+ req.is.forEach(function (typ) {
+ if (VALID_TYPES.indexOf(typ) < 0) {
+ let msg = 'Internal error: invalid requirement type "' + typ + '".';
+ throw new Error(msg);
+ }
+ });
+ if (req.is.indexOf(getTypeOf(optsVal)) < 0)
+ throw requirementError(key, req);
+ }
+ if (req.ok && !req.ok(optsVal))
+ throw requirementError(key, req);
+
+ if (keyInOpts || (req.map && !mapThrew))
+ validatedOptions[key] = optsVal;
+ }
+
+ return validatedOptions;
+};
+
+exports.addIterator = function addIterator(obj, keysValsGenerator) {
+ obj.__iterator__ = function(keysOnly, keysVals) {
+ let keysValsIterator = keysValsGenerator.call(this);
+
+ // "for (.. in ..)" gets only keys, "for each (.. in ..)" gets values,
+ // and "for (.. in Iterator(..))" gets [key, value] pairs.
+ let index = keysOnly ? 0 : 1;
+ while (true)
+ yield keysVals ? keysValsIterator.next() : keysValsIterator.next()[index];
+ };
+};
+
+// Similar to typeof, except arrays and null are identified by "array" and
+// "null", not "object".
+let getTypeOf = exports.getTypeOf = function getTypeOf(val) {
+ let typ = typeof(val);
+ if (typ === "object") {
+ if (!val)
+ return "null";
+ if (Array.isArray(val))
+ return "array";
+ }
+ return typ;
+}
+
+// Returns a new Error with a nice message.
+function requirementError(key, requirement) {
+ let msg = requirement.msg;
+ if (!msg) {
+ msg = 'The option "' + key + '" ';
+ msg += requirement.is ?
+ "must be one of the following types: " + requirement.is.join(", ") :
+ "is invalid.";
+ }
+ return new Error(msg);
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/app-strings.js b/tools/addon-sdk-1.7/packages/api-utils/lib/app-strings.js
new file mode 100644
index 0000000..c03ae7c
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/app-strings.js
@@ -0,0 +1,63 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {Cc,Ci} = require("chrome");
+const apiUtils = require("./api-utils");
+
+/**
+ * A bundle of strings.
+ *
+ * @param url {String}
+ * the URL of the string bundle
+ */
+exports.StringBundle = apiUtils.publicConstructor(function StringBundle(url) {
+
+ let stringBundle = Cc["@mozilla.org/intl/stringbundle;1"].
+ getService(Ci.nsIStringBundleService).
+ createBundle(url);
+
+ this.__defineGetter__("url", function () url);
+
+ /**
+ * Get a string from the bundle.
+ *
+ * @param name {String}
+ * the name of the string to get
+ * @param args {array} [optional]
+ * an array of arguments that replace occurrences of %S in the string
+ *
+ * @returns {String} the value of the string
+ */
+ this.get = function strings_get(name, args) {
+ try {
+ if (args)
+ return stringBundle.formatStringFromName(name, args, args.length);
+ else
+ return stringBundle.GetStringFromName(name);
+ }
+ catch(ex) {
+ // f.e. "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)
+ // [nsIStringBundle.GetStringFromName]"
+ throw new Error("String '" + name + "' could not be retrieved from the " +
+ "bundle due to an unknown error (it doesn't exist?).");
+ }
+ },
+
+ /**
+ * Iterate the strings in the bundle.
+ *
+ */
+ apiUtils.addIterator(
+ this,
+ function keysValsGen() {
+ let enumerator = stringBundle.getSimpleEnumeration();
+ while (enumerator.hasMoreElements()) {
+ let elem = enumerator.getNext().QueryInterface(Ci.nsIPropertyElement);
+ yield [elem.key, elem.value];
+ }
+ }
+ );
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/array.js b/tools/addon-sdk-1.7/packages/api-utils/lib/array.js
new file mode 100644
index 0000000..dadcfa6
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/array.js
@@ -0,0 +1,69 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+/**
+ * Returns `true` if given `array` contain given `element` or `false`
+ * otherwise.
+ * @param {Array} array
+ * Target array.
+ * @param {Object|String|Number|Boolean} element
+ * Element being looked up.
+ * @returns {Boolean}
+ */
+var has = exports.has = function has(array, element) {
+ // shorter and faster equivalent of `array.indexOf(element) >= 0`
+ return !!~array.indexOf(element);
+};
+
+/**
+ * Adds given `element` to the given `array` if it does not contain it yet.
+ * `true` is returned if element was added otherwise `false` is returned.
+ * @param {Array} array
+ * Target array.
+ * @param {Object|String|Number|Boolean} element
+ * Element to be added.
+ * @returns {Boolean}
+ */
+var add = exports.add = function add(array, element) {
+ var result;
+ if ((result = !has(array, element)))
+ array.push(element);
+
+ return result;
+};
+
+/**
+ * Removes first occurrence of the given `element` from the given `array`. If
+ * `array` does not contain given `element` `false` is returned otherwise
+ * `true` is returned.
+ * @param {Array} array
+ * Target array.
+ * @param {Object|String|Number|Boolean} element
+ * Element to be removed.
+ * @returns {Boolean}
+ */
+exports.remove = function remove(array, element) {
+ var result;
+ if ((result = has(array, element)))
+ array.splice(array.indexOf(element), 1);
+
+ return result;
+};
+
+/**
+ * Produces a duplicate-free version of the given `array`.
+ * @param {Array} array
+ * Source array.
+ * @returns {Array}
+ */
+exports.unique = function unique(array) {
+ var value = [];
+ return array.forEach(function(element) {
+ add(value, element);
+ });
+ return value;
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/base.js b/tools/addon-sdk-1.7/packages/api-utils/lib/base.js
new file mode 100644
index 0000000..63acabc
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/base.js
@@ -0,0 +1,177 @@
+/* vim:set ts=2 sw=2 sts=2 expandtab */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+// Instead of inheriting from `Object.prototype` we copy all interesting
+// properties from it and then freeze. This way we can guarantee integrity
+// of components build on top.
+exports.Base = Object.freeze(Object.create(null, {
+ toString: { value: Object.prototype.toString },
+ toLocaleString: { value: Object.prototype.toLocaleString },
+ toSource: { value: Object.prototype.toSource },
+ valueOf: { value: Object.prototype.valueOf },
+ isPrototypeOf: { value: Object.prototype.isPrototypeOf },
+ /**
+ * Creates an object that inherits from `this` object (Analog of
+ * `new Object()`).
+ * @examples
+ *
+ * var Dog = Base.extend({
+ * bark: function bark() {
+ * return 'Ruff! Ruff!'
+ * }
+ * });
+ * var dog = Dog.new();
+ */
+ new: { value: function create() {
+ var object = Object.create(this);
+ object.initialize.apply(object, arguments);
+ return object;
+ }},
+ /**
+ * When new instance of the this prototype is created it's `initialize`
+ * method is called with all the arguments passed to the `new`. You can
+ * override `initialize` to set up an instance.
+ */
+ initialize: { value: function initialize() {
+ }},
+ /**
+ * Merges all the properties of the passed objects into `this` instance (This
+ * method can be used on instances only as prototype objects are frozen).
+ *
+ * If two or more argument objects have own properties with the same name,
+ * the property is overridden, with precedence from right to left, implying,
+ * that properties of the object on the left are overridden by a same named
+ * property of the object on the right.
+ *
+ * @examples
+ *
+ * var Pet = Dog.extend({
+ * initialize: function initialize(options) {
+ * // this.name = options.name -> would have thrown (frozen prototype)
+ * this.merge(options) // will override all properties.
+ * },
+ * call: function(name) {
+ * return this.name === name ? this.bark() : ''
+ * },
+ * name: null
+ * })
+ * var pet = Pet.new({ name: 'Benzy', breed: 'Labrador' })
+ * pet.call('Benzy') // 'Ruff! Ruff!'
+ */
+ merge: { value: function merge() {
+ var descriptor = {};
+ Array.prototype.forEach.call(arguments, function (properties) {
+ Object.getOwnPropertyNames(properties).forEach(function(name) {
+ descriptor[name] = Object.getOwnPropertyDescriptor(properties, name);
+ });
+ });
+ Object.defineProperties(this, descriptor);
+ return this;
+ }},
+ /**
+ * Takes any number of argument objects and returns frozen, composite object
+ * that inherits from `this` object and combines all of the own properties of
+ * the argument objects. (Objects returned by this function are frozen as
+ * they are intended to be used as types).
+ *
+ * If two or more argument objects have own properties with the same name,
+ * the property is overridden, with precedence from right to left, implying,
+ * that properties of the object on the left are overridden by a same named
+ * property of the object on the right.
+ * @examples
+ *
+ * // ## Object composition ##
+ *
+ * var HEX = Base.extend({
+ * hex: function hex() {
+ * return '#' + this.color;
+ * }
+ * })
+ *
+ * var RGB = Base.extend({
+ * red: function red() {
+ * return parseInt(this.color.substr(0, 2), 16);
+ * },
+ * green: function green() {
+ * return parseInt(this.color.substr(2, 2), 16);
+ * },
+ * blue: function blue() {
+ * return parseInt(this.color.substr(4, 2), 16);
+ * }
+ * })
+ *
+ * var CMYK = Base.extend(RGB, {
+ * black: function black() {
+ * var color = Math.max(Math.max(this.red(), this.green()), this.blue());
+ * return (1 - color / 255).toFixed(4);
+ * },
+ * cyan: function cyan() {
+ * var K = this.black();
+ * return (((1 - this.red() / 255).toFixed(4) - K) / (1 - K)).toFixed(4);
+ * },
+ * magenta: function magenta() {
+ * var K = this.black();
+ * return (((1 - this.green() / 255).toFixed(4) - K) / (1 - K)).toFixed(4);
+ * },
+ * yellow: function yellow() {
+ * var K = this.black();
+ * return (((1 - this.blue() / 255).toFixed(4) - K) / (1 - K)).toFixed(4);
+ * }
+ * })
+ *
+ * var Color = Base.extend(HEX, RGB, CMYK, {
+ * initialize: function Color(color) {
+ * this.color = color;
+ * }
+ * });
+ *
+ * // ## Prototypal inheritance ##
+ *
+ * var Pixel = Color.extend({
+ * initialize: function Pixel(x, y, hex) {
+ * Color.initialize.call(this, hex);
+ * this.x = x;
+ * this.y = y;
+ * },
+ * toString: function toString() {
+ * return this.x + ':' + this.y + '@' + this.hex();
+ * }
+ * });
+ *
+ * var pixel = Pixel.new(11, 23, 'CC3399')
+ * pixel.toString(); // 11:23@#CC3399
+ *
+ * pixel.red(); // 204
+ * pixel.green(); // 51
+ * pixel.blue(); // 153
+ *
+ * pixel.cyan(); // 0.0000
+ * pixel.magenta(); // 0.7500
+ * pixel.yellow(); // 0.2500
+ *
+ */
+ extend: { value: function extend() {
+ return Object.freeze(this.merge.apply(Object.create(this), arguments));
+ }}
+}));
+
+/**
+ * Function takes prototype object that implements `initialize` method, and
+ * returns `constructor` function (with correct prototype property), that can
+ * be used for simulating classes for given prototypes.
+ */
+exports.Class = Object.freeze(function Class(prototype) {
+ function constructor() {
+ var instance = Object.create(prototype);
+ prototype.initialize.apply(instance, arguments);
+ return instance;
+ }
+ return Object.freeze(Object.defineProperties(constructor, {
+ prototype: { value: prototype },
+ new: { value: constructor }
+ }));
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/byte-streams.js b/tools/addon-sdk-1.7/packages/api-utils/lib/byte-streams.js
new file mode 100644
index 0000000..edc8407
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/byte-streams.js
@@ -0,0 +1,102 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim:set ts=2 sw=2 sts=2 et filetype=javascript
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+exports.ByteReader = ByteReader;
+exports.ByteWriter = ByteWriter;
+
+const {Cc, Ci} = require("chrome");
+
+// This just controls the maximum number of bytes we read in at one time.
+const BUFFER_BYTE_LEN = 0x8000;
+
+function ByteReader(inputStream) {
+ const self = this;
+
+ let stream = Cc["@mozilla.org/binaryinputstream;1"].
+ createInstance(Ci.nsIBinaryInputStream);
+ stream.setInputStream(inputStream);
+
+ let manager = new StreamManager(this, stream);
+
+ this.read = function ByteReader_read(numBytes) {
+ manager.ensureOpened();
+ if (typeof(numBytes) !== "number")
+ numBytes = Infinity;
+
+ let data = "";
+ let read = 0;
+ try {
+ while (true) {
+ let avail = stream.available();
+ let toRead = Math.min(numBytes - read, avail, BUFFER_BYTE_LEN);
+ if (toRead <= 0)
+ break;
+ data += stream.readBytes(toRead);
+ read += toRead;
+ }
+ }
+ catch (err) {
+ throw new Error("Error reading from stream: " + err);
+ }
+
+ return data;
+ };
+}
+
+function ByteWriter(outputStream) {
+ const self = this;
+
+ let stream = Cc["@mozilla.org/binaryoutputstream;1"].
+ createInstance(Ci.nsIBinaryOutputStream);
+ stream.setOutputStream(outputStream);
+
+ let manager = new StreamManager(this, stream);
+
+ this.write = function ByteWriter_write(str) {
+ manager.ensureOpened();
+ try {
+ stream.writeBytes(str, str.length);
+ }
+ catch (err) {
+ throw new Error("Error writing to stream: " + err);
+ }
+ };
+}
+
+
+// This manages the lifetime of stream, a ByteReader or ByteWriter. It defines
+// closed and close() on stream and registers an unload listener that closes
+// rawStream if it's still opened. It also provides ensureOpened(), which
+// throws an exception if the stream is closed.
+function StreamManager(stream, rawStream) {
+ const self = this;
+ this.rawStream = rawStream;
+ this.opened = true;
+
+ stream.__defineGetter__("closed", function stream_closed() {
+ return !self.opened;
+ });
+
+ stream.close = function stream_close() {
+ self.ensureOpened();
+ self.unload();
+ };
+
+ require("./unload").ensure(this);
+}
+
+StreamManager.prototype = {
+ ensureOpened: function StreamManager_ensureOpened() {
+ if (!this.opened)
+ throw new Error("The stream is closed and cannot be used.");
+ },
+ unload: function StreamManager_unload() {
+ this.rawStream.close();
+ this.opened = false;
+ }
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/channel.js b/tools/addon-sdk-1.7/packages/api-utils/lib/channel.js
new file mode 100644
index 0000000..a888af8
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/channel.js
@@ -0,0 +1,46 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const { jetpackID } = require('@packaging');
+const { when } = require('./unload');
+
+// TODO: Create a bug report and remove this workaround once it's fixed.
+// Only function needs defined in the context of the message manager window
+// can be registered via `addMessageListener`.
+function listener(callee) {
+ return function listener() { return callee.apply(this, arguments); };
+}
+function messageListener(scope, callee) {
+ return scope ? scope.eval('(' + listener + ')')(callee) : callee
+}
+
+exports.channel = function channel(scope, messageManager, address, raw) {
+ address = jetpackID + ':' + address
+ return {
+ input: function input(next, stop) {
+ let listener = messageListener(scope, function onMessage(message) {
+ if (false === next(raw ? message : message.json) && listener) {
+ messageManager.removeMessageListener(address, listener);
+ listener = null;
+ }
+ });
+ messageManager.addMessageListener(address, listener);
+
+ // Bug 724433: do not leak `listener` on addon disabling
+ when(function () {
+ if (listener) {
+ messageManager.removeMessageListener(address, listener);
+ listener = null;
+ }
+ });
+ },
+ output: function output(data) {
+ messageManager.sendAsyncMessage(address, data);
+ },
+ sync: !messageManager.sendSyncMessage ? null : function sync(data) {
+ messageManager.sendSyncMessage(address, data);
+ }
+ };
+};
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/collection.js b/tools/addon-sdk-1.7/packages/api-utils/lib/collection.js
new file mode 100644
index 0000000..b9dd352
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/collection.js
@@ -0,0 +1,108 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+exports.Collection = Collection;
+
+/**
+ * Adds a collection property to the given object. Setting the property to a
+ * scalar value empties the collection and adds the value. Setting it to an
+ * array empties the collection and adds all the items in the array.
+ *
+ * @param obj
+ * The property will be defined on this object.
+ * @param propName
+ * The name of the property.
+ * @param array
+ * If given, this will be used as the collection's backing array.
+ */
+exports.addCollectionProperty = function addCollProperty(obj, propName, array) {
+ array = array || [];
+ let publicIface = new Collection(array);
+
+ obj.__defineSetter__(propName, function (itemOrItems) {
+ array.splice(0, array.length);
+ publicIface.add(itemOrItems);
+ });
+
+ obj.__defineGetter__(propName, function () {
+ return publicIface;
+ });
+};
+
+/**
+ * A collection is ordered, like an array, but its items are unique, like a set.
+ *
+ * @param array
+ * The collection is backed by an array. If this is given, it will be
+ * used as the backing array. This way the caller can fully control the
+ * collection. Otherwise a new empty array will be used, and no one but
+ * the collection will have access to it.
+ */
+function Collection(array) {
+ array = array || [];
+
+ /**
+ * Provides iteration over the collection. Items are yielded in the order
+ * they were added.
+ */
+ this.__iterator__ = function Collection___iterator__() {
+ let items = array.slice();
+ for (let i = 0; i < items.length; i++)
+ yield items[i];
+ };
+
+ /**
+ * The number of items in the collection.
+ */
+ this.__defineGetter__("length", function Collection_get_length() {
+ return array.length;
+ });
+
+ /**
+ * Adds a single item or an array of items to the collection. Any items
+ * already contained in the collection are ignored.
+ *
+ * @param itemOrItems
+ * An item or array of items.
+ * @return The collection.
+ */
+ this.add = function Collection_add(itemOrItems) {
+ let items = toArray(itemOrItems);
+ for (let i = 0; i < items.length; i++) {
+ let item = items[i];
+ if (array.indexOf(item) < 0)
+ array.push(item);
+ }
+ return this;
+ };
+
+ /**
+ * Removes a single item or an array of items from the collection. Any items
+ * not contained in the collection are ignored.
+ *
+ * @param itemOrItems
+ * An item or array of items.
+ * @return The collection.
+ */
+ this.remove = function Collection_remove(itemOrItems) {
+ let items = toArray(itemOrItems);
+ for (let i = 0; i < items.length; i++) {
+ let idx = array.indexOf(items[i]);
+ if (idx >= 0)
+ array.splice(idx, 1);
+ }
+ return this;
+ };
+};
+
+function toArray(itemOrItems) {
+ let isArr = itemOrItems &&
+ itemOrItems.constructor &&
+ itemOrItems.constructor.name === "Array";
+ return isArr ? itemOrItems : [itemOrItems];
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/content.js b/tools/addon-sdk-1.7/packages/api-utils/lib/content.js
new file mode 100644
index 0000000..a4acb94
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/content.js
@@ -0,0 +1,11 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+exports.Loader = require('./content/loader').Loader;
+exports.Symbiont = require('./content/symbiont').Symbiont;
+exports.Worker = require('./content/worker').Worker;
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/content/loader.js b/tools/addon-sdk-1.7/packages/api-utils/lib/content/loader.js
new file mode 100644
index 0000000..62c3ad0
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/content/loader.js
@@ -0,0 +1,179 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { EventEmitter } = require('../events');
+const { validateOptions } = require('../api-utils');
+const { URL } = require('../url');
+const file = require('../file');
+
+const LOCAL_URI_SCHEMES = ['resource', 'data'];
+
+// Returns `null` if `value` is `null` or `undefined`, otherwise `value`.
+function ensureNull(value) {
+ return value == null ? null : value;
+}
+
+// map of property validations
+const valid = {
+ contentURL: {
+ ok: function (value) {
+ try {
+ URL(value);
+ }
+ catch(e) {
+ return false;
+ }
+ return true;
+ },
+ msg: 'The `contentURL` option must be a valid URL.'
+ },
+ contentScriptFile: {
+ is: ['undefined', 'null', 'string', 'array'],
+ map: ensureNull,
+ ok: function(value) {
+ if (value === null)
+ return true;
+
+ value = [].concat(value);
+
+ // Make sure every item is a local file URL.
+ return value.every(function (item) {
+ try {
+ return ~LOCAL_URI_SCHEMES.indexOf(URL(item).scheme);
+ }
+ catch(e) {
+ return false;
+ }
+ });
+
+ },
+ msg: 'The `contentScriptFile` option must be a local URL or an array of URLs.'
+ },
+ contentScript: {
+ is: ['undefined', 'null', 'string', 'array'],
+ map: ensureNull,
+ ok: function(value) {
+ return !Array.isArray(value) || value.every(
+ function(item) { return typeof item === 'string' }
+ );
+ },
+ msg: 'The `contentScript` option must be a string or an array of strings.'
+ },
+ contentScriptWhen: {
+ is: ['string'],
+ ok: function(value) { return ~['start', 'ready', 'end'].indexOf(value) },
+ map: function(value) {
+ return value || 'end';
+ },
+ msg: 'The `contentScriptWhen` option must be either "start", "ready" or "end".'
+ }
+};
+exports.validationAttributes = valid;
+
+/**
+ * Shortcut function to validate property with validation.
+ * @param {Object|Number|String} suspect
+ * value to validate
+ * @param {Object} validation
+ * validation rule passed to `api-utils`
+ */
+function validate(suspect, validation) validateOptions(
+ { $: suspect },
+ { $: validation }
+).$
+
+function Allow(script) ({
+ get script() script,
+ set script(value) script = !!value
+})
+
+/**
+ * Trait is intended to be used in some composition. It provides set of core
+ * properties and bounded validations to them. Trait is useful for all the
+ * compositions providing high level APIs for interaction with content.
+ * Property changes emit `"propertyChange"` events on instances.
+ */
+const Loader = EventEmitter.compose({
+ /**
+ * Permissions for the content, with the following keys:
+ * @property {Object} [allow = { script: true }]
+ * @property {Boolean} [allow.script = true]
+ * Whether or not to execute script in the content. Defaults to true.
+ */
+ get allow() this._allow || (this._allow = Allow(true)),
+ set allow(value) this.allow.script = value && value.script,
+ _allow: null,
+ /**
+ * The content to load. Either a string of HTML or a URL.
+ * @type {String}
+ */
+ get contentURL() this._contentURL,
+ set contentURL(value) {
+ value = validate(value, valid.contentURL);
+ if (this._contentURL != value) {
+ this._emit('propertyChange', {
+ contentURL: this._contentURL = value
+ });
+ }
+ },
+ _contentURL: null,
+ /**
+ * When to load the content scripts.
+ * Possible values are "end" (default), which loads them once all page
+ * contents have been loaded, "ready", which loads them once DOM nodes are
+ * ready (ie like DOMContentLoaded event), and "start", which loads them once
+ * the `window` object for the page has been created, but before any scripts
+ * specified by the page have been loaded.
+ * Property change emits `propertyChange` event on instance with this key
+ * and new value.
+ * @type {'start'|'ready'|'end'}
+ */
+ get contentScriptWhen() this._contentScriptWhen,
+ set contentScriptWhen(value) {
+ value = validate(value, valid.contentScriptWhen);
+ if (value !== this._contentScriptWhen) {
+ this._emit('propertyChange', {
+ contentScriptWhen: this._contentScriptWhen = value
+ });
+ }
+ },
+ _contentScriptWhen: 'end',
+ /**
+ * The URLs of content scripts.
+ * Property change emits `propertyChange` event on instance with this key
+ * and new value.
+ * @type {String[]}
+ */
+ get contentScriptFile() this._contentScriptFile,
+ set contentScriptFile(value) {
+ value = validate(value, valid.contentScriptFile);
+ if (value != this._contentScriptFile) {
+ this._emit('propertyChange', {
+ contentScriptFile: this._contentScriptFile = value
+ });
+ }
+ },
+ _contentScriptFile: null,
+ /**
+ * The texts of content script.
+ * Property change emits `propertyChange` event on instance with this key
+ * and new value.
+ * @type {String|undefined}
+ */
+ get contentScript() this._contentScript,
+ set contentScript(value) {
+ value = validate(value, valid.contentScript);
+ if (value != this._contentScript) {
+ this._emit('propertyChange', {
+ contentScript: this._contentScript = value
+ });
+ }
+ },
+ _contentScript: null
+});
+exports.Loader = Loader;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/content/symbiont.js b/tools/addon-sdk-1.7/packages/api-utils/lib/content/symbiont.js
new file mode 100644
index 0000000..e7c959c
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/content/symbiont.js
@@ -0,0 +1,183 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const { Worker } = require('./worker');
+const { Loader } = require('./loader');
+const hiddenFrames = require('../hidden-frame');
+const observers = require('../observer-service');
+const unload = require('../unload');
+
+/**
+ * This trait is layered on top of `Worker` and in contrast to symbiont
+ * Worker constructor requires `content` option that represents content
+ * that will be loaded in the provided frame, if frame is not provided
+ * Worker will create hidden one.
+ */
+const Symbiont = Worker.resolve({
+ constructor: '_initWorker',
+ destroy: '_workerDestroy'
+ }).compose(Loader, {
+
+ /**
+ * The constructor requires all the options that are required by
+ * `require('content').Worker` with the difference that the `frame` option
+ * is optional. If `frame` is not provided, `contentURL` is expected.
+ * @param {Object} options
+ * @param {String} options.contentURL
+ * URL of a content to load into `this._frame` and create worker for.
+ * @param {Element} [options.frame]
+ * iframe element that is used to load `options.contentURL` into.
+ * if frame is not provided hidden iframe will be created.
+ */
+ constructor: function Symbiont(options) {
+ options = options || {};
+
+ if ('contentURL' in options)
+ this.contentURL = options.contentURL;
+ if ('contentScriptWhen' in options)
+ this.contentScriptWhen = options.contentScriptWhen;
+ if ('contentScriptFile' in options)
+ this.contentScriptFile = options.contentScriptFile;
+ if ('contentScript' in options)
+ this.contentScript = options.contentScript;
+ if ('allow' in options)
+ this.allow = options.allow;
+ if ('onError' in options)
+ this.on('error', options.onError);
+ if ('onMessage' in options)
+ this.on('message', options.onMessage);
+ if ('frame' in options) {
+ this._initFrame(options.frame);
+ }
+ else {
+ let self = this;
+ this._hiddenFrame = hiddenFrames.HiddenFrame({
+ onReady: function onFrame() {
+ self._initFrame(this.element);
+ }
+ });
+ hiddenFrames.add(this._hiddenFrame);
+ }
+
+ unload.ensure(this._public, "destroy");
+ },
+
+ destroy: function destroy() {
+ this._workerDestroy();
+ this._unregisterListener();
+ this._frame = null;
+ if (this._hiddenFrame) {
+ hiddenFrames.remove(this._hiddenFrame);
+ this._hiddenFrame = null;
+ }
+ },
+
+ /**
+ * XUL iframe or browser elements with attribute `type` being `content`.
+ * Used to create `ContentSymbiont` from.
+ * @type {nsIFrame|nsIBrowser}
+ */
+ _frame: null,
+
+ /**
+ * Listener to the `'frameReady"` event (emitted when `iframe` is ready).
+ * Removes listener, sets right permissions to the frame and loads content.
+ */
+ _initFrame: function _initFrame(frame) {
+ if (this._loadListener)
+ this._unregisterListener();
+
+ this._frame = frame;
+ frame.docShell.allowJavascript = this.allow.script;
+ frame.setAttribute("src", this._contentURL);
+
+ // Inject `addon` object in document if we load a document from
+ // one of our addon folder and if no content script are defined. bug 612726
+ let isDataResource =
+ typeof this._contentURL == "string" &&
+ this._contentURL.indexOf(require("@packaging").uriPrefix) == 0;
+ let hasContentScript =
+ (Array.isArray(this.contentScript) ? this.contentScript.length > 0
+ : !!this.contentScript) ||
+ (Array.isArray(this.contentScriptFile) ? this.contentScriptFile.length > 0
+ : !!this.contentScriptFile);
+ // If we have to inject `addon` we have to do it before document
+ // script execution, so during `start`:
+ this._injectInDocument = isDataResource && !hasContentScript;
+ if (this._injectInDocument)
+ this.contentScriptWhen = "start";
+
+ if ((frame.contentDocument.readyState == "complete" ||
+ (frame.contentDocument.readyState == "interactive" &&
+ this.contentScriptWhen != 'end' )) &&
+ frame.contentDocument.location == this._contentURL) {
+ // In some cases src doesn't change and document is already ready
+ // (for ex: when the user moves a widget while customizing toolbars.)
+ this._onInit();
+ return;
+ }
+
+ let self = this;
+
+ if ('start' == this.contentScriptWhen) {
+ this._loadEvent = 'start';
+ observers.add('document-element-inserted',
+ this._loadListener = function onStart(doc) {
+
+ let window = doc.defaultView;
+ if (window && window == frame.contentWindow) {
+ self._unregisterListener();
+ self._onInit();
+ }
+
+ });
+ return;
+ }
+
+ let eventName = 'end' == this.contentScriptWhen ? 'load' : 'DOMContentLoaded';
+ let self = this;
+ this._loadEvent = eventName;
+ frame.addEventListener(eventName,
+ this._loadListener = function _onReady(event) {
+
+ if (event.target != frame.contentDocument)
+ return;
+ self._unregisterListener();
+
+ self._onInit();
+
+ }, true);
+
+ },
+
+ /**
+ * Unregister listener that watchs for document being ready to be injected.
+ * This listener is registered in `Symbiont._initFrame`.
+ */
+ _unregisterListener: function _unregisterListener() {
+ if (!this._loadListener)
+ return;
+ if (this._loadEvent == "start") {
+ observers.remove('document-element-inserted', this._loadListener);
+ }
+ else {
+ this._frame.removeEventListener(this._loadEvent, this._loadListener,
+ true);
+ }
+ this._loadListener = null;
+ },
+
+ /**
+ * Called by Symbiont itself when the frame is ready to load
+ * content scripts according to contentScriptWhen. Overloaded by Panel.
+ */
+ _onInit: function () {
+ this._initWorker({ window: this._frame.contentWindow });
+ }
+
+});
+exports.Symbiont = Symbiont;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/content/worker.js b/tools/addon-sdk-1.7/packages/api-utils/lib/content/worker.js
new file mode 100644
index 0000000..c6f35d9
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/content/worker.js
@@ -0,0 +1,491 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const { Trait } = require('../traits');
+const { EventEmitter, EventEmitterTrait } = require('../events');
+const { Ci, Cu, Cc } = require('chrome');
+const timer = require('../timer');
+const { URL } = require('../url');
+const unload = require('../unload');
+const observers = require('../observer-service');
+const { Cortex } = require('../cortex');
+const self = require("self");
+const { sandbox, evaluate, load } = require("../sandbox");
+const { merge } = require('../utils/object');
+
+const CONTENT_PROXY_URL = self.data.url("content-proxy.js");
+const CONTENT_WORKER_URL = self.data.url("worker.js");
+
+const JS_VERSION = '1.8';
+
+const ERR_DESTROYED =
+ "The page has been destroyed and can no longer be used.";
+
+/**
+ * This key is not exported and should only be used for proxy tests.
+ * The following `PRIVATE_KEY` is used in addon module scope in order to tell
+ * Worker API to expose `UNWRAP_ACCESS_KEY` in content script.
+ * This key allows test-content-proxy.js to unwrap proxy with valueOf:
+ * let xpcWrapper = proxyWrapper.valueOf(UNWRAP_ACCESS_KEY);
+ */
+const PRIVATE_KEY = {};
+
+
+const WorkerSandbox = EventEmitter.compose({
+
+ /**
+ * Emit a message to the worker content sandbox
+ */
+ emit: function emit() {
+ // First ensure having a regular array
+ // (otherwise, `arguments` would be mapped to an object by `stringify`)
+ let array = Array.slice(arguments);
+ // JSON.stringify is buggy with cross-sandbox values,
+ // it may return "{}" on functions. Use a replacer to match them correctly.
+ function replacer(k, v) {
+ return typeof v === "function" ? undefined : v;
+ }
+ // Ensure having an asynchronous behavior
+ let self = this;
+ timer.setTimeout(function () {
+ self._emitToContent(JSON.stringify(array, replacer));
+ }, 0);
+ },
+
+ /**
+ * Synchronous version of `emit`.
+ * /!\ Should only be used when it is strictly mandatory /!\
+ * Doesn't ensure passing only JSON values.
+ * Mainly used by context-menu in order to avoid breaking it.
+ */
+ emitSync: function emitSync() {
+ return this._emitToContent(Array.slice(arguments));
+ },
+
+ /**
+ * Tells if content script has at least one listener registered for one event,
+ * through `self.on('xxx', ...)`.
+ * /!\ Shouldn't be used. Implemented to avoid breaking context-menu API.
+ */
+ hasListenerFor: function hasListenerFor(name) {
+ return this._hasListenerFor(name);
+ },
+
+ /**
+ * Method called by the worker sandbox when it needs to send a message
+ */
+ _onContentEvent: function onContentEvent(args) {
+ // As `emit`, we ensure having an asynchronous behavior
+ let self = this;
+ timer.setTimeout(function () {
+ // We emit event to chrome/addon listeners
+ self._emit.apply(self, JSON.parse(args));
+ }, 0);
+ },
+
+ /**
+ * Configures sandbox and loads content scripts into it.
+ * @param {Worker} worker
+ * content worker
+ */
+ constructor: function WorkerSandbox(worker) {
+ this._addonWorker = worker;
+
+ // Ensure that `emit` has always the right `this`
+ this.emit = this.emit.bind(this);
+ this.emitSync = this.emitSync.bind(this);
+
+ // We receive a wrapped window, that may be an xraywrapper if it's content
+ let window = worker._window;
+ let proto = window;
+
+ // Instantiate trusted code in another Sandbox in order to prevent content
+ // script from messing with standard classes used by proxy and API code.
+ let apiSanbox = sandbox(window, { wantXrays: true });
+
+ // Build content proxies only if the document has a non-system principal
+ if (window.wrappedJSObject) {
+ apiSanbox.console = console;
+ // Execute the proxy code
+ load(apiSanbox, CONTENT_PROXY_URL);
+ // Get a reference of the window's proxy
+ proto = apiSanbox.create(window);
+ }
+
+ // Create the sandbox and bind it to window in order for content scripts to
+ // have access to all standard globals (window, document, ...)
+ let content = this._sandbox = sandbox(window, {
+ sandboxPrototype: proto,
+ wantXrays: true
+ });
+ merge(content, {
+ // We need "this === window === top" to be true in toplevel scope:
+ get window() content,
+ get top() content,
+ // Use the Greasemonkey naming convention to provide access to the
+ // unwrapped window object so the content script can access document
+ // JavaScript values.
+ // NOTE: this functionality is experimental and may change or go away
+ // at any time!
+ get unsafeWindow() window.wrappedJSObject
+ });
+
+ // Load trusted code that will inject content script API.
+ // We need to expose JS objects defined in same principal in order to
+ // avoid having any kind of wrapper.
+ load(apiSanbox, CONTENT_WORKER_URL);
+
+ // Then call `inject` method and communicate with this script
+ // by trading two methods that allow to send events to the other side:
+ // - `onEvent` called by content script
+ // - `result.emitToContent` called by addon script
+ let chromeAPI = {
+ timers: {
+ setTimeout: timer.setTimeout,
+ setInterval: timer.setInterval,
+ clearTimeout: timer.clearTimeout,
+ clearInterval: timer.clearInterval
+ }
+ };
+ let onEvent = this._onContentEvent.bind(this);
+ // `ContentWorker` is defined in CONTENT_WORKER_URL file
+ let result = apiSanbox.ContentWorker.inject(content, chromeAPI, onEvent);
+ this._emitToContent = result.emitToContent;
+ this._hasListenerFor = result.hasListenerFor;
+
+ // Handle messages send by this script:
+ let self = this;
+ // console.xxx calls
+ this.on("console", function consoleListener(kind) {
+ console[kind].apply(console, Array.slice(arguments, 1));
+ });
+
+ // self.postMessage calls
+ this.on("message", function postMessage(data) {
+ self._addonWorker._emit('message', data);
+ });
+
+ // self.port.emit calls
+ this.on("event", function portEmit(name, args) {
+ self._addonWorker._onContentScriptEvent.apply(self._addonWorker, arguments);
+ });
+
+ // Internal feature that is only used by SDK tests:
+ // Expose unlock key to content script context.
+ // See `PRIVATE_KEY` definition for more information.
+ if (apiSanbox && worker._expose_key)
+ content.UNWRAP_ACCESS_KEY = apiSanbox.UNWRAP_ACCESS_KEY;
+
+ // Inject `addon` global into target document if document is trusted,
+ // `addon` in document is equivalent to `self` in content script.
+ if (worker._injectInDocument) {
+ let win = window.wrappedJSObject ? window.wrappedJSObject : window;
+ Object.defineProperty(win, "addon", {
+ value: content.self
+ }
+ );
+ }
+
+ // The order of `contentScriptFile` and `contentScript` evaluation is
+ // intentional, so programs can load libraries like jQuery from script URLs
+ // and use them in scripts.
+ let contentScriptFile = ('contentScriptFile' in worker) ? worker.contentScriptFile
+ : null,
+ contentScript = ('contentScript' in worker) ? worker.contentScript : null;
+
+ if (contentScriptFile) {
+ if (Array.isArray(contentScriptFile))
+ this._importScripts.apply(this, contentScriptFile);
+ else
+ this._importScripts(contentScriptFile);
+ }
+ if (contentScript) {
+ this._evaluate(
+ Array.isArray(contentScript) ? contentScript.join(';\n') : contentScript
+ );
+ }
+ },
+ destroy: function destroy() {
+ this.emitSync("destroy");
+ this._sandbox = null;
+ this._addonWorker = null;
+ },
+
+ /**
+ * JavaScript sandbox where all the content scripts are evaluated.
+ * {Sandbox}
+ */
+ _sandbox: null,
+
+ /**
+ * Reference to the addon side of the worker.
+ * @type {Worker}
+ */
+ _addonWorker: null,
+
+ /**
+ * Evaluates code in the sandbox.
+ * @param {String} code
+ * JavaScript source to evaluate.
+ * @param {String} [filename='javascript:' + code]
+ * Name of the file
+ */
+ _evaluate: function(code, filename) {
+ try {
+ evaluate(this._sandbox, code, filename || 'javascript:' + code);
+ }
+ catch(e) {
+ this._addonWorker._emit('error', e);
+ }
+ },
+ /**
+ * Imports scripts to the sandbox by reading files under urls and
+ * evaluating its source. If exception occurs during evaluation
+ * `"error"` event is emitted on the worker.
+ * This is actually an analog to the `importScript` method in web
+ * workers but in our case it's not exposed even though content
+ * scripts may be able to do it synchronously since IO operation
+ * takes place in the UI process.
+ */
+ _importScripts: function _importScripts(url) {
+ let urls = Array.slice(arguments, 0);
+ for each (let contentScriptFile in urls) {
+ try {
+ let uri = URL(contentScriptFile);
+ if (uri.scheme === 'resource')
+ load(this._sandbox, String(uri));
+ else
+ throw Error("Unsupported `contentScriptFile` url: " + String(uri));
+ }
+ catch(e) {
+ this._addonWorker._emit('error', e);
+ }
+ }
+ }
+});
+
+/**
+ * Message-passing facility for communication between code running
+ * in the content and add-on process.
+ * @see https://jetpack.mozillalabs.com/sdk/latest/docs/#module/api-utils/content/worker
+ */
+const Worker = EventEmitter.compose({
+ on: Trait.required,
+ _removeAllListeners: Trait.required,
+
+ /**
+ * Sends a message to the worker's global scope. Method takes single
+ * argument, which represents data to be sent to the worker. The data may
+ * be any primitive type value or `JSON`. Call of this method asynchronously
+ * emits `message` event with data value in the global scope of this
+ * symbiont.
+ *
+ * `message` event listeners can be set either by calling
+ * `self.on` with a first argument string `"message"` or by
+ * implementing `onMessage` function in the global scope of this worker.
+ * @param {Number|String|JSON} data
+ */
+ postMessage: function postMessage(data) {
+ if (!this._contentWorker)
+ throw new Error(ERR_DESTROYED);
+ this._contentWorker.emit("message", data);
+ },
+
+ /**
+ * EventEmitter, that behaves (calls listeners) asynchronously.
+ * A way to send customized messages to / from the worker.
+ * Events from in the worker can be observed / emitted via
+ * worker.on / worker.emit.
+ */
+ get port() {
+ // We generate dynamically this attribute as it needs to be accessible
+ // before Worker.constructor gets called. (For ex: Panel)
+
+ // create an event emitter that receive and send events from/to the worker
+ let self = this;
+ this._port = EventEmitterTrait.create({
+ emit: function () self._emitEventToContent(Array.slice(arguments))
+ });
+
+ // expose wrapped port, that exposes only public properties:
+ // We need to destroy this getter in order to be able to set the
+ // final value. We need to update only public port attribute as we never
+ // try to access port attribute from private API.
+ delete this._public.port;
+ this._public.port = Cortex(this._port);
+ // Replicate public port to the private object
+ delete this.port;
+ this.port = this._public.port;
+
+ return this._port;
+ },
+
+ /**
+ * Same object than this.port but private API.
+ * Allow access to _emit, in order to send event to port.
+ */
+ _port: null,
+
+ /**
+ * Emit a custom event to the content script,
+ * i.e. emit this event on `self.port`
+ */
+ _emitEventToContent: function _emitEventToContent(args) {
+ // We need to save events that are emitted before the worker is
+ // initialized
+ if (!this._inited) {
+ this._earlyEvents.push(args);
+ return;
+ }
+
+ // We throw exception when the worker has been destroyed
+ if (!this._contentWorker) {
+ throw new Error(ERR_DESTROYED);
+ }
+
+ // Forward the event to the WorkerSandbox object
+ this._contentWorker.emit.apply(null, ["event"].concat(args));
+ },
+
+ // Is worker connected to the content worker sandbox ?
+ _inited: false,
+
+ // List of custom events fired before worker is initialized
+ get _earlyEvents() {
+ delete this._earlyEvents;
+ this._earlyEvents = [];
+ return this._earlyEvents;
+ },
+
+ constructor: function Worker(options) {
+ options = options || {};
+
+ if ('window' in options)
+ this._window = options.window;
+ if ('contentScriptFile' in options)
+ this.contentScriptFile = options.contentScriptFile;
+ if ('contentScript' in options)
+ this.contentScript = options.contentScript;
+ if ('onError' in options)
+ this.on('error', options.onError);
+ if ('onMessage' in options)
+ this.on('message', options.onMessage);
+ if ('onDetach' in options)
+ this.on('detach', options.onDetach);
+
+ // Internal feature that is only used by SDK unit tests.
+ // See `PRIVATE_KEY` definition for more information.
+ if ('exposeUnlockKey' in options && options.exposeUnlockKey === PRIVATE_KEY)
+ this._expose_key = true;
+
+ // Track document unload to destroy this worker.
+ // We can't watch for unload event on page's window object as it
+ // prevents bfcache from working:
+ // https://developer.mozilla.org/En/Working_with_BFCache
+ this._windowID = this._window.
+ QueryInterface(Ci.nsIInterfaceRequestor).
+ getInterface(Ci.nsIDOMWindowUtils).
+ currentInnerWindowID;
+ observers.add("inner-window-destroyed",
+ this._documentUnload = this._documentUnload.bind(this));
+
+ unload.ensure(this._public, "destroy");
+
+ // Ensure that worker._port is initialized for contentWorker to be able
+ // to send use event during WorkerSandbox(this)
+ this.port;
+
+ // will set this._contentWorker pointing to the private API:
+ this._contentWorker = WorkerSandbox(this);
+
+ // Mainly enable worker.port.emit to send event to the content worker
+ this._inited = true;
+
+ // Flush all events that have been fired before the worker is initialized.
+ this._earlyEvents.forEach((function (args) this._emitEventToContent(args)).
+ bind(this));
+ },
+
+ _documentUnload: function _documentUnload(subject, topic, data) {
+ let innerWinID = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
+ if (innerWinID != this._windowID) return false;
+ this._workerCleanup();
+ return true;
+ },
+
+ get url() {
+ // this._window will be null after detach
+ return this._window ? this._window.document.location.href : null;
+ },
+
+ get tab() {
+ if (this._window) {
+ let tab = require("../tabs/tab");
+ // this._window will be null after detach
+ return tab.getTabForWindow(this._window);
+ }
+ return null;
+ },
+
+ /**
+ * Tells content worker to unload itself and
+ * removes all the references from itself.
+ */
+ destroy: function destroy() {
+ this._workerCleanup();
+ this._removeAllListeners();
+ },
+
+ /**
+ * Remove all internal references to the attached document
+ * Tells _port to unload itself and removes all the references from itself.
+ */
+ _workerCleanup: function _workerCleanup() {
+ // maybe unloaded before content side is created
+ // As Symbiont call worker.constructor on document load
+ if (this._contentWorker)
+ this._contentWorker.destroy();
+ this._contentWorker = null;
+ this._window = null;
+ // This method may be called multiple times,
+ // avoid dispatching `detach` event more than once
+ if (this._windowID) {
+ this._windowID = null;
+ observers.remove("inner-window-destroyed", this._documentUnload);
+ this._earlyEvents.slice(0, this._earlyEvents.length);
+ this._emit("detach");
+ }
+ },
+
+ /**
+ * Receive an event from the content script that need to be sent to
+ * worker.port. Provide a way for composed object to catch all events.
+ */
+ _onContentScriptEvent: function _onContentScriptEvent() {
+ this._port._emit.apply(this._port, arguments);
+ },
+
+ /**
+ * Reference to the content side of the worker.
+ * @type {WorkerGlobalScope}
+ */
+ _contentWorker: null,
+
+ /**
+ * Reference to the window that is accessible from
+ * the content scripts.
+ * @type {Object}
+ */
+ _window: null,
+
+ /**
+ * Flag to enable `addon` object injection in document. (bug 612726)
+ * @type {Boolean}
+ */
+ _injectInDocument: false
+});
+exports.Worker = Worker;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/cortex.js b/tools/addon-sdk-1.7/packages/api-utils/lib/cortex.js
new file mode 100644
index 0000000..1c3a1b3
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/cortex.js
@@ -0,0 +1,109 @@
+/* vim:set ts=2 sw=2 sts=2
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+// `var` is being used in the module in order to make it reusable in
+// environments in which `let` and `const` is not yet supported.
+
+// Returns `object`'s property value, where `name` is a name of the property.
+function get(object, name) {
+ return object[name];
+}
+
+// Assigns `value` to the `object`'s property, where `name` is the name of the
+// property.
+function set(object, name, value) {
+ return object[name] = value;
+}
+
+/**
+ * Given an `object` containing a property with the given `name`, create
+ * a property descriptor that can be used to define alias/proxy properties
+ * on other objects. A change in the value of an alias will propagate
+ * to the aliased property and vice versa.
+ */
+function createAliasProperty(object, name) {
+ // Getting own property descriptor of an `object` for the given `name` as
+ // we are going to create proxy analog.
+ var property = Object.getOwnPropertyDescriptor(object, name);
+ var descriptor = {
+ configurable: property.configurable,
+ enumerable: property.enumerable,
+ alias: true
+ };
+
+ // If the original property has a getter and/or setter, bind a
+ // corresponding getter/setter in the alias descriptor to the original
+ // object, so the `this` object in the getter/setter is the original object
+ // rather than the alias.
+ if ("get" in property && property.get)
+ descriptor.get = property.get.bind(object);
+ if ("set" in property && property.set)
+ descriptor.set = property.set.bind(object);
+
+ // If original property was a value property.
+ if ("value" in property) {
+ // If original property is a method using it's `object` bounded copy.
+ if (typeof property.value === "function") {
+ descriptor.value = property.value.bind(object);
+ // Also preserving writability of the original property.
+ descriptor.writable = property.writable;
+ }
+
+ // If the original property was just a data property, we create proxy
+ // accessors using our custom get/set functions to propagate changes to the
+ // original `object` and vice versa.
+ else {
+ descriptor.get = get.bind(null, object, name);
+ descriptor.set = set.bind(null, object, name);
+ }
+ }
+ return descriptor;
+}
+
+// Defines property on `object` object with a name `alias` if given if not
+// defaults to `name` that represents an alias of `source[name]`. If aliased
+// property was an assessor or a method `this` pseudo-variable will be `source`
+// when invoked. If aliased property was a data property changes on any of the
+// aliases will propagate to the `source[name]` and also other way round.
+function defineAlias(source, target, name, alias) {
+ return Object.defineProperty(target, alias || name,
+ createAliasProperty(source, name));
+}
+
+/**
+ * Function takes any `object` and returns a proxy for its own public
+ * properties. By default properties are considered to be public if they don't
+ * start with `"_"`, but default behavior can be overridden if needed, by
+ * passing array of public property `names` as a second argument. By default
+ * returned object will be direct decedent of the given `object`'s prototype,
+ * but this can be overridden by passing third optional argument, that will be
+ * used as `prototype` instead.
+ * @param {Object} object
+ * Object to create cortex for.
+ * @param {String[]} [names]
+ * Optional array of public property names.
+ * @param {Object} [prototype]
+ * Optional argument that will be used as `prototype` of the returned object,
+ * if not provided `Object.getPrototypeOf(object)` is used instead.
+ */
+exports.Cortex = function Cortex(object, names, prototype) {
+ // Creating a cortex object from the given `prototype`, if one was not
+ // provided then `prototype` of a given `object` is used. This allows
+ // consumer to define expected behavior `instanceof`. In common case
+ // `prototype` argument can be omitted to preserve same behavior of
+ // `instanceof` as on original `object`.
+ var cortex = Object.create(prototype || Object.getPrototypeOf(object));
+ // Creating alias properties on the `cortex` object for all the own
+ // properties of the original `object` that are contained in `names` array.
+ // If `names` array is not provided then all the properties that don't
+ // start with `"_"` are aliased.
+ Object.getOwnPropertyNames(object).forEach(function (name) {
+ if ((!names && "_" !== name.charAt(0)) || (names && ~names.indexOf(name)))
+ defineAlias(object, cortex, name);
+ });
+ return cortex;
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/cuddlefish.js b/tools/addon-sdk-1.7/packages/api-utils/lib/cuddlefish.js
new file mode 100644
index 0000000..ac01aee
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/cuddlefish.js
@@ -0,0 +1,302 @@
+/* vim:set ts=2 sw=2 sts=2 expandtab */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+var EXPORTED_SYMBOLS = [ 'Loader' ];
+
+!function(exports) {
+
+"use strict";
+
+const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu,
+ results: Cr, manager: Cm } = Components;
+const systemPrincipal = CC('@mozilla.org/systemprincipal;1', 'nsIPrincipal')();
+const scriptLoader = Cc['@mozilla.org/moz/jssubscript-loader;1'].
+ getService(Ci.mozIJSSubScriptLoader);
+
+const Sandbox = {
+ new: function ({ principal, prototype, name, existingSandbox }) {
+ let options = { sandboxPrototype: prototype || Sandbox.prototype,
+ wantXrays: Sandbox.wantXrays };
+ if (name)
+ options.sandboxName = name;
+ if (existingSandbox)
+ options.sameGroupAs = existingSandbox.sandbox;
+ let sandbox = Object.create(Sandbox, {
+ sandbox: { value: Cu.Sandbox(principal || Sandbox.principal, options) }
+ });
+ // There are few properties (dump, Iterator) that by default appear in
+ // sandboxes shadowing properties provided by a prototype. To workaround
+ // this we override all such properties by copying them directly to the
+ // sandbox.
+ Object.keys(prototype).forEach(function onEach(key) {
+ if (sandbox.sandbox[key] !== prototype[key])
+ sandbox.sandbox[key] = prototype[key];
+ });
+ return sandbox;
+ },
+ evaluate: function evaluate(source, uri, lineNumber) {
+ return Cu.evalInSandbox(
+ source,
+ this.sandbox,
+ this.version,
+ uri,
+ lineNumber || this.lineNumber
+ );
+ },
+ load: function load(uri) {
+ scriptLoader.loadSubScript(uri, this.sandbox, 'UTF-8');
+ },
+ merge: function merge(properties) {
+ Object.getOwnPropertyNames(properties).forEach(function(name) {
+ Object.defineProperty(this.sandbox, name,
+ Object.getOwnPropertyDescriptor(properties, name));
+ }, this);
+ },
+ principal: systemPrincipal,
+ version: '1.8',
+ lineNumber: 1,
+ wantXrays: false,
+ prototype: {}
+};
+
+// the Module object made available to CommonJS modules when they are
+// evaluated, along with 'exports' and 'uri'
+const Module = {
+ new: function(id, path, uri) {
+ let module = Object.create(this);
+
+ module.id = id;
+ module.path = path;
+ module.uri = uri;
+ module.exports = {};
+
+ return module;
+ },
+ // TODO: I'd like to remove this, it's not used adds complexity and does
+ // not has much adoption in commonjs either.
+ setExports: function setExports(exports) {
+ this.exports = exports;
+ }
+};
+
+const Loader = {
+ new: function (options) {
+ let loader = Object.create(Loader, {
+ // Manifest generated by a linker, containing map of module url's mapped
+ // to it's requirements, comes from harness-options.json
+ manifest: { value: options.manifest || {} },
+
+ // Following property may be passed in (usually for mocking purposes) in
+ // order to override default modules cache.
+ modules: { value: options.modules || Object.create(Loader.modules) },
+ globals: { value: options.globals || {} },
+
+ uriPrefix: { value: options.uriPrefix },
+
+ sandboxes: { value: {} }
+ });
+ loader.require = this.require.bind(loader, options.loader);
+
+ // some 'magic' modules, that have no corresponding .js file
+ loader.modules['@packaging'] = Object.freeze({
+ id: '@packaging',
+ exports: JSON.parse(JSON.stringify(options))
+ });
+ loader.modules['@loader'] = Object.freeze({
+ exports: Object.freeze({ Loader: Loader }),
+ id: '@loader'
+ });
+
+ // This special module defines globals which will be added to every
+ // module this loader creates
+ let globals = loader.require('api-utils/globals!');
+ Object.getOwnPropertyNames(globals).forEach(function(name) {
+ Object.defineProperty(loader.globals, name,
+ Object.getOwnPropertyDescriptor(globals, name));
+ });
+ // Freeze globals so that modules won't have a chance to mutate scope of
+ // other modules.
+ Object.freeze(globals);
+
+ // Override global `dump` so that it behaves same as in any other module (
+ // currently we override dump to write to a file instead of `stdout` so that
+ // python can read it on windows).
+ dump = globals.dump;
+
+ return Object.freeze(loader);
+ },
+ modules: {
+ 'chrome': Object.freeze({
+ exports: Object.freeze({
+ Cc: Cc,
+ CC: CC,
+ Ci: Ci,
+ Cu: Cu,
+ Cr: Cr,
+ Cm: Cm,
+ components: Components,
+ messageManager: 'addMessageListener' in exports ? exports : null
+ }),
+ id: 'chrome'
+ }),
+ 'self': function self(loader, requirer) {
+ return loader.require('api-utils/self!').create(requirer.path);
+ },
+ },
+
+ // populate a Module by evaluating the CommonJS module code in the sandbox
+ load: function load(module) {
+ let require = Loader.require.bind(this, module.path);
+ require.main = this.main;
+
+ // Get an existing module sandbox, if any, so we can reuse its compartment
+ // when creating the new one to reduce memory consumption.
+ let existingSandbox = [this.sandboxes[p] for (p in this.sandboxes)][0];
+
+ // XXX Always set "principal" to work around bug 705795, which generates
+ // 'reference to undefined property "principal"' warnings when the argument
+ // is deconstructed in the "new" function's parameter list.
+ // FIXME: stop setting "principal" once bug 705795 is fixed.
+ let sandbox = this.sandboxes[module.path] =
+ Sandbox.new({ principal: null,
+ prototype: this.globals,
+ name: module.uri,
+ existingSandbox: existingSandbox });
+ sandbox.merge({
+ require: require,
+ module: module,
+ exports: module.exports
+ });
+
+ sandbox.load(module.uri);
+
+ // Workaround for bug 674195. Freezing objects from other sandboxes fail,
+ // so we create descendant and freeze it instead.
+ if (typeof(module.exports) === 'object') {
+ module.exports = Object.prototype.isPrototypeOf(module.exports) ?
+ Object.freeze(module.exports) :
+ Object.freeze(Object.create(module.exports));
+ }
+ },
+
+ // this require() is the main entry point for regular CommonJS modules. The
+ // bind() in load (above) causes those modules to get a very restricted
+ // form of this require(): one which can only ever reference this one
+ // loader, and which always uses their URI as a "base" (so they're limited
+ // to their own manifest entries, and can't import anything off the
+ // manifest).
+ require: function require(base, id) {
+ let module, manifest = this.manifest[base], requirer = this.modules[base];
+
+ if (!id)
+ throw Error("you must provide a module name when calling require() from "
+ + (requirer && requirer.id), base, id);
+
+ // If we have a manifest for requirer, then all it's requirements have been
+ // registered by linker and we should have a `path` to the required module.
+ // Even pseudo-modules like 'chrome', 'self', '@packaging', and '@loader'
+ // have pseudo-paths: exactly those same names.
+ // details see: Bug-697422.
+ let requirement = manifest && manifest.requirements[id];
+ if (!requirement)
+ throw Error("Module: " + (requirer && requirer.id) + ' located at ' +
+ base + " has no authority to load: " + id);
+ let path = requirement.path;
+
+ if (path in this.modules) {
+ module = this.modules[path];
+ }
+ else {
+ let uri = this.uriPrefix + path;
+ module = this.modules[path] = Module.new(id, path, uri);
+ this.load(module);
+ Object.freeze(module);
+ }
+
+ // "magic" modules which have contents that depend upon who imports them
+ // (like "self") are expressed in the Loader's pre-populated 'modules'
+ // table as callable functions, which are given the reference to this
+ // Loader and a copy of the importer's URI
+ //
+ // TODO: Find a better way to implement `self`.
+ // Maybe something like require('self!path/to/data')
+ if (typeof(module) === 'function')
+ module = module(this, requirer);
+
+ return module.exports;
+ },
+
+ // process.process() will eventually cause a call to main() to be evaluated
+ // in the addon's context. This function loads and executes the addon's
+ // entry point module.
+ main: function main(id, path) {
+ try {
+ let uri = this.uriPrefix + path;
+ let module = this.modules[path] = Module.new(id, path, uri);
+ this.load(module); // this is where the addon's main.js finally runs
+ let program = Object.freeze(module).exports;
+
+ if (typeof(program.onUnload) === 'function')
+ this.require('api-utils/unload').when(program.onUnload);
+
+ if (program.main) {
+ let { exit, staticArgs } = this.require('api-utils/system');
+ let { loadReason } = this.require('@packaging');
+ program.main({ loadReason: loadReason, staticArgs: staticArgs },
+ { print: function($) dump($ + '\n'), quit: exit });
+ }
+ } catch (error) {
+ Cu.reportError(error);
+ if (this.globals.console) this.globals.console.exception(error);
+ throw error;
+ }
+ },
+
+ // This is the main entry-point: bootstrap.js calls this when the add-on is
+ // installed. The order of calls is a bit confusing, but here's what
+ // happens (in temporal order):
+ // * process.spawn creates a new XUL 'browser' element which will house the
+ // main addon code. When e10s is active, this uses a real separate OS
+ // process. When e10s is disabled, this element lives in the one original
+ // process. Either way, its API is the same.
+ // * Grab the channel named "require!" and attach a handler which will load
+ // modules (in the chrome process) when requested to by the addon
+ // process. This handler uses Loader.require to import the module, then
+ // calls the module's .initialize() function to connect a new channel.
+ // The remote caller winds up with a channel reference, which they can
+ // use to send messages to the newly loaded module. This is for e10s.
+ // * After the channel handler is attached, process.process() (invoked by
+ // process.spawn()) will use loadScript() to evaluate code in the
+ // 'browser' element (which is where the main addon code starts running),
+ // to do the following:
+ // * create a Loader, initialized with the same manifest and
+ // harness-options.json that we've got
+ // * invoke it's main() method, with the name and path of the addon's
+ // entry module (which comes from linker via harness-options.js, and is
+ // usually main.js). That executes main(), above.
+ // * main() loads the addon's main.js, which executes all top-level
+ // forms. If the module defines an "exports.main=" function, we invoke
+ // that too. This is where the addon finally gets to run.
+ spawn: function spawn(id, path) {
+ let loader = this;
+ let process = this.require('api-utils/process');
+ process.spawn(id, path)(function(addon) {
+ // Listen to `require!` channel's input messages from the add-on process
+ // and load modules being required.
+ addon.channel('require!').input(function({ requirer: { path }, id }) {
+ try {
+ Loader.require.call(loader, path, id).initialize(addon.channel(id));
+ } catch (error) {
+ this.globals.console.exception(error);
+ }
+ });
+ });
+ },
+ unload: function unload(reason, callback) {
+ this.require('api-utils/unload').send(reason, callback);
+ }
+};
+exports.Loader = Loader;
+
+}(this);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/dom/events.js b/tools/addon-sdk-1.7/packages/api-utils/lib/dom/events.js
new file mode 100644
index 0000000..2168f42
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/dom/events.js
@@ -0,0 +1,136 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+// Utility function that returns copy of the given `text` with last character
+// removed if it is `"s"`.
+function singularify(text) {
+ return text[text.length - 1] === "s" ? text.substr(0, text.length - 1) : text;
+}
+
+// Utility function that takes event type, argument is passed to
+// `document.createEvent` and returns name of the initializer method of the
+// given event. Please note that there are some event types whose initializer
+// methods can't be guessed by this function. For more details see following
+// link: https://developer.mozilla.org/En/DOM/Document.createEvent
+function getInitializerName(category) {
+ return "init" + singularify(category);
+}
+
+/**
+ * Registers an event `listener` on a given `element`, that will be called
+ * when events of specified `type` is dispatched on the `element`.
+ * @param {Element} element
+ * Dom element to register listener on.
+ * @param {String} type
+ * A string representing the
+ * [event type](https://developer.mozilla.org/en/DOM/event.type) to
+ * listen for.
+ * @param {Function} listener
+ * Function that is called whenever an event of the specified `type`
+ * occurs.
+ * @param {Boolean} capture
+ * If true, indicates that the user wishes to initiate capture. After
+ * initiating capture, all events of the specified type will be dispatched
+ * to the registered listener before being dispatched to any `EventTarget`s
+ * beneath it in the DOM tree. Events which are bubbling upward through
+ * the tree will not trigger a listener designated to use capture.
+ * See [DOM Level 3 Events](http://www.w3.org/TR/DOM-Level-3-Events/#event-flow)
+ * for a detailed explanation.
+ */
+function on(element, type, listener, capture) {
+ // `capture` defaults to `false`.
+ capture = capture || false;
+ element.addEventListener(type, listener, capture);
+}
+exports.on = on;
+
+/**
+ * Registers an event `listener` on a given `element`, that will be called
+ * only once, next time event of specified `type` is dispatched on the
+ * `element`.
+ * @param {Element} element
+ * Dom element to register listener on.
+ * @param {String} type
+ * A string representing the
+ * [event type](https://developer.mozilla.org/en/DOM/event.type) to
+ * listen for.
+ * @param {Function} listener
+ * Function that is called whenever an event of the specified `type`
+ * occurs.
+ * @param {Boolean} capture
+ * If true, indicates that the user wishes to initiate capture. After
+ * initiating capture, all events of the specified type will be dispatched
+ * to the registered listener before being dispatched to any `EventTarget`s
+ * beneath it in the DOM tree. Events which are bubbling upward through
+ * the tree will not trigger a listener designated to use capture.
+ * See [DOM Level 3 Events](http://www.w3.org/TR/DOM-Level-3-Events/#event-flow)
+ * for a detailed explanation.
+ */
+function once(element, type, listener, capture) {
+ on(element, type, function selfRemovableListener(event) {
+ removeListener(element, type, selfRemovableListener, capture);
+ listener.apply(this, arguments);
+ }, capture);
+}
+exports.once = once;
+
+/**
+ * Unregisters an event `listener` on a given `element` for the events of the
+ * specified `type`.
+ *
+ * @param {Element} element
+ * Dom element to unregister listener from.
+ * @param {String} type
+ * A string representing the
+ * [event type](https://developer.mozilla.org/en/DOM/event.type) to
+ * listen for.
+ * @param {Function} listener
+ * Function that is called whenever an event of the specified `type`
+ * occurs.
+ * @param {Boolean} capture
+ * If true, indicates that the user wishes to initiate capture. After
+ * initiating capture, all events of the specified type will be dispatched
+ * to the registered listener before being dispatched to any `EventTarget`s
+ * beneath it in the DOM tree. Events which are bubbling upward through
+ * the tree will not trigger a listener designated to use capture.
+ * See [DOM Level 3 Events](http://www.w3.org/TR/DOM-Level-3-Events/#event-flow)
+ * for a detailed explanation.
+ */
+function removeListener(element, type, listener, capture) {
+ element.removeEventListener(type, listener, capture);
+}
+exports.removeListener = removeListener;
+
+/**
+ * Emits event of the specified `type` and `category` on the given `element`.
+ * Specified `settings` are used to initialize event before dispatching it.
+ * @param {Element} element
+ * Dom element to dispatch event on.
+ * @param {String} type
+ * A string representing the
+ * [event type](https://developer.mozilla.org/en/DOM/event.type).
+ * @param {Object} options
+ * Options object containing following properties:
+ * - `category`: String passed to the `document.createEvent`. Option is
+ * optional and defaults to "UIEvents".
+ * - `initializer`: If passed it will be used as name of the method used
+ * to initialize event. If omitted name will be generated from the
+ * `category` field by prefixing it with `"init"` and removing last
+ * character if it matches `"s"`.
+ * - `settings`: Array of settings that are forwarded to the event
+ * initializer after firs `type` argument.
+ * @see https://developer.mozilla.org/En/DOM/Document.createEvent
+ */
+function emit(element, type, { category, initializer, settings }) {
+ category = category || "UIEvents";
+ initializer = initializer || getInitializerName(category);
+ let document = element.ownerDocument;
+ let event = document.createEvent(category);
+ event[initializer].apply(event, [type].concat(settings));
+ element.dispatchEvent(event);
+};
+exports.emit = emit;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/dom/events/keys.js b/tools/addon-sdk-1.7/packages/api-utils/lib/dom/events/keys.js
new file mode 100644
index 0000000..53107ae
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/dom/events/keys.js
@@ -0,0 +1,60 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { emit } = require("../events");
+const { getCodeForKey, toJSON } = require("../../keyboard/utils");
+const { has } = require("../../array");
+const { isString } = require("../../type");
+
+const INITIALIZER = "initKeyEvent";
+const CATEGORY = "KeyboardEvent";
+
+function Options(options) {
+ if (!isString(options))
+ return options;
+
+ var { key, modifiers } = toJSON(options);
+ return {
+ key: key,
+ control: has(modifiers, "control"),
+ alt: has(modifiers, "alt"),
+ shift: has(modifiers, "shift"),
+ meta: has(modifiers, "meta")
+ };
+}
+
+var keyEvent = exports.keyEvent = function keyEvent(element, type, options) {
+
+ emit(element, type, {
+ initializer: INITIALIZER,
+ category: CATEGORY,
+ settings: [
+ !("bubbles" in options) || options.bubbles !== false,
+ !("cancelable" in options) || options.cancelable !== false,
+ "window" in options && options.window ? options.window : null,
+ "control" in options && !!options.control,
+ "alt" in options && !!options.alt,
+ "shift" in options && !!options.shift,
+ "meta" in options && !!options.meta,
+ getCodeForKey(options.key) || 0,
+ options.key.length === 1 ? options.key.charCodeAt(0) : 0
+ ]
+ });
+}
+
+exports.keyDown = function keyDown(element, options) {
+ keyEvent(element, "keydown", Options(options));
+};
+
+exports.keyUp = function keyUp(element, options) {
+ keyEvent(element, "keyup", Options(options));
+};
+
+exports.keyPress = function keyPress(element, options) {
+ keyEvent(element, "keypress", Options(options));
+};
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/env!.js b/tools/addon-sdk-1.7/packages/api-utils/lib/env!.js
new file mode 100644
index 0000000..f7144ad
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/env!.js
@@ -0,0 +1,20 @@
+/* vim:set ts=2 sw=2 sts=2 expandtab */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const { messageManager } = require("chrome");
+const { channel } = require("./channel");
+
+module.exports = function load(module) {
+ return {
+ require: function require(id) {
+ // Load required module on the chrome process.
+ channel(messageManager, messageManager, 'require!').sync({
+ requirer: module,
+ id: id
+ });
+ return channel(messageManager, messageManager, id);
+ }
+ };
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/environment.js b/tools/addon-sdk-1.7/packages/api-utils/lib/environment.js
new file mode 100644
index 0000000..fd95c67
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/environment.js
@@ -0,0 +1,54 @@
+/* vim:set ts=2 sw=2 sts=2 expandtab */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+const { Cc, Ci } = require('chrome');
+const { get, set, exists } = Cc['@mozilla.org/process/environment;1'].
+ getService(Ci.nsIEnvironment);
+
+exports.env = Proxy.create({
+ // XPCOM does not provides a way to enumerate environment variables, so we
+ // just don't support enumeration.
+ getPropertyNames: function() [],
+ getOwnPropertyNames: function() [],
+ enumerate: function() [],
+ keys: function() [],
+ // We do not support freezing, cause it would make it impossible to set new
+ // environment variables.
+ fix: function() undefined,
+ // We present all environment variables as own properties of this object,
+ // so we just delegate this call to `getOwnPropertyDescriptor`.
+ getPropertyDescriptor: function(name) this.getOwnPropertyDescriptor(name),
+ // If environment variable with this name is defined, we generate proprety
+ // descriptor for it, otherwise fall back to `undefined` so that for consumer
+ // this property does not exists.
+ getOwnPropertyDescriptor: function(name) {
+ return !exists(name) ? undefined : {
+ value: get(name),
+ enumerable: false, // Non-enumerable as we don't support enumeration.
+ configurable: true, // Configurable as it may be deleted.
+ writable: true // Writable as we do support set.
+ }
+ },
+
+ // New environment variables can be defined just by defining properties
+ // on this object.
+ defineProperty: function(name, { value }) set(name, value),
+ delete: function(name) set(name, null),
+
+ // We present all properties as own, there for we just delegate to `hasOwn`.
+ has: function(name) this.hasOwn(name),
+ // We do support checks for existence of an environment variable, via `in`
+ // operator on this object.
+ hasOwn: function(name) exists(name),
+
+ // On property get / set we do read / write appropriate environment variables,
+ // please note though, that variables with names of standard object properties
+ // intentionally (so that this behaves as normal object) can not be
+ // read / set.
+ get: function(proxy, name) Object.prototype[name] || get(name) || undefined,
+ set: function(proxy, name, value) Object.prototype[name] || set(name, value)
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/errors.js b/tools/addon-sdk-1.7/packages/api-utils/lib/errors.js
new file mode 100644
index 0000000..7029158
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/errors.js
@@ -0,0 +1,60 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+function logToConsole(e) {
+ console.exception(e);
+}
+
+var catchAndLog = exports.catchAndLog = function(callback,
+ defaultResponse,
+ logException) {
+ if (!logException)
+ logException = logToConsole;
+
+ return function() {
+ try {
+ return callback.apply(this, arguments);
+ } catch (e) {
+ logException(e);
+ return defaultResponse;
+ }
+ };
+};
+
+exports.catchAndLogProps = function catchAndLogProps(object,
+ props,
+ defaultResponse,
+ logException) {
+ if (typeof(props) == "string")
+ props = [props];
+ props.forEach(
+ function(property) {
+ object[property] = catchAndLog(object[property],
+ defaultResponse,
+ logException);
+ });
+};
+
+/**
+ * Catch and return an exception while calling the callback. If the callback
+ * doesn't throw, return the return value of the callback in a way that makes it
+ * possible to distinguish between a return value and an exception.
+ *
+ * This function is useful when you need to pass the result of a call across
+ * a process boundary (across which exceptions don't propagate). It probably
+ * doesn't need to be factored out into this module, since it is only used by
+ * a single caller, but putting it here works around bug 625560.
+ */
+exports.catchAndReturn = function(callback) {
+ return function() {
+ try {
+ return { returnValue: callback.apply(this, arguments) };
+ }
+ catch (exception) {
+ return { exception: exception };
+ }
+ };
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/event/core.js b/tools/addon-sdk-1.7/packages/api-utils/lib/event/core.js
new file mode 100644
index 0000000..ed2a0d4
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/event/core.js
@@ -0,0 +1,147 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const UNCAUGHT_ERROR = 'An error event was emitted for which there was no listener.';
+const BAD_LISTENER = 'The event listener must be a function.';
+
+const { ns } = require('../namespace');
+
+const event = ns();
+
+// Utility function to access given event `target` object's event listeners for
+// the specific event `type`. If listeners for this type does not exists they
+// will be created.
+const observers = function observers(target, type) {
+ let listeners = event(target);
+ return type in listeners ? listeners[type] : listeners[type] = [];
+};
+
+/**
+ * Registers an event `listener` that is called every time events of
+ * specified `type` is emitted on the given event `target`.
+ * @param {Object} target
+ * Event target object.
+ * @param {String} type
+ * The type of event.
+ * @param {Function} listener
+ * The listener function that processes the event.
+ */
+function on(target, type, listener) {
+ if (typeof(listener) !== 'function')
+ throw new Error(BAD_LISTENER);
+
+ let listeners = observers(target, type);
+ if (!~listeners.indexOf(listener))
+ listeners.push(listener);
+}
+exports.on = on;
+
+/**
+ * Registers an event `listener` that is called only the next time an event
+ * of the specified `type` is emitted on the given event `target`.
+ * @param {Object} target
+ * Event target object.
+ * @param {String} type
+ * The type of the event.
+ * @param {Function} listener
+ * The listener function that processes the event.
+ */
+function once(target, type, listener) {
+ on(target, type, function observer() {
+ off(target, type, observer);
+ listener.apply(target, arguments);
+ });
+}
+exports.once = once;
+
+/**
+ * Execute each of the listeners in order with the supplied arguments.
+ * All the exceptions that are thrown by listeners during the emit
+ * are caught and can be handled by listeners of 'error' event. Thrown
+ * exceptions are passed as an argument to an 'error' event listener.
+ * If no 'error' listener is registered exception will be logged into an
+ * error console.
+ * @param {Object} target
+ * Event target object.
+ * @param {String} type
+ * The type of event.
+ * @params {Object|Number|String|Boolean} message
+ * First argument that will be passed to listeners.
+ * @params {Object|Number|String|Boolean} ...
+ * More arguments that will be passed to listeners.
+ */
+function emit(target, type, message /*, ...*/) {
+ for each (let item in emit.lazy.apply(emit.lazy, arguments))
+ item;
+}
+
+/**
+ * This is very experimental feature that you should not use unless absolutely
+ * need it. Also it may be removed at any point without any further notice.
+ *
+ * Creates lazy iterator of return values of listeners. You can think of it
+ * as lazy array of return values of listeners for the `emit` with the given
+ * arguments.
+ */
+emit.lazy = function lazy(target, type, message /*, ...*/) {
+ let args = Array.slice(arguments, 2)
+ let listeners = observers(target, type).slice()
+ while (listeners.length) {
+ try {
+ yield listeners.shift().apply(target, args);
+ }
+ catch (error) {
+ // If exception is not thrown by a error listener and error listener is
+ // registered emit `error` event. Otherwise dump exception to the console.
+ if (type !== 'error' && observers(target, 'error').length)
+ emit(target, 'error', error);
+ else
+ console.exception(error);
+ }
+ }
+}
+exports.emit = emit;
+
+/**
+ * Removes an event `listener` for the given event `type` on the given event
+ * `target`. If no `listener` is passed removes all listeners of the given
+ * `type`. If `type` is not passed removes all the listeners of the given
+ * event `target`.
+ * @param {Object} target
+ * The event target object.
+ * @param {String} type
+ * The type of event.
+ * @param {Function} listener
+ * The listener function that processes the event.
+ */
+function off(target, type, listener) {
+ let length = arguments.length;
+ if (length === 3) {
+ let listeners = observers(target, type);
+ let index = listeners.indexOf(listener);
+ if (~index)
+ listeners.splice(index, 1);
+ }
+ else if (length === 2) {
+ observers(target, type).splice(0);
+ }
+ else if (length === 1) {
+ let listeners = event(target);
+ Object.keys(listeners).forEach(function(type) delete listeners[type]);
+ }
+}
+exports.off = off;
+
+/**
+ * Returns a number of event listeners registered for the given event `type`
+ * on the given event `target`.
+ */
+function count(target, type) {
+ return observers(target, type).length;
+}
+exports.count = count;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/event/target.js b/tools/addon-sdk-1.7/packages/api-utils/lib/event/target.js
new file mode 100644
index 0000000..60b19d2
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/event/target.js
@@ -0,0 +1,76 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+const { on, once, off } = require('./core');
+const { method } = require('../functional');
+const { Base } = require('../base');
+
+const EVENT_TYPE_PATTERN = /^on([A-Z]\w+$)/;
+
+/**
+ * `EventTarget` is an exemplar for creating an objects that can be used to
+ * add / remove event listeners on them. Events on these objects may be emitted
+ * via `emit` function exported by 'event/core' module.
+ */
+const EventTarget = Base.extend({
+ /**
+ * Method initializes `this` event source. It goes through properties of a
+ * given `options` and registers listeners for the ones that look like an
+ * event listeners.
+ */
+ initialize: function initialize(options) {
+ options = options || {};
+ // Go through each property and registers event listeners for those
+ // that have a name matching following pattern (`onEventType`).
+ Object.keys(options).forEach(function onEach(key) {
+ let match = EVENT_TYPE_PATTERN.exec(key);
+ let type = match && match[1].toLowerCase();
+ let listener = options[key];
+
+ if (type && typeof(listener) === 'function')
+ this.on(type, listener);
+ }, this);
+ },
+ /**
+ * Registers an event `listener` that is called every time events of
+ * specified `type` are emitted.
+ * @param {String} type
+ * The type of event.
+ * @param {Function} listener
+ * The listener function that processes the event.
+ * @example
+ * worker.on('message', function (data) {
+ * console.log('data received: ' + data)
+ * })
+ */
+ on: method(on),
+ /**
+ * Registers an event `listener` that is called once the next time an event
+ * of the specified `type` is emitted.
+ * @param {String} type
+ * The type of the event.
+ * @param {Function} listener
+ * The listener function that processes the event.
+ */
+ once: method(once),
+ /**
+ * Removes an event `listener` for the given event `type`.
+ * @param {String} type
+ * The type of event.
+ * @param {Function} listener
+ * The listener function that processes the event.
+ */
+ removeListener: function removeListener(type, listener) {
+ // Note: We can't just wrap `off` in `method` as we do it for other methods
+ // cause skipping a second or third argument will behave very differently
+ // than intended. This way we make sure all arguments are passed and only
+ // one listener is removed at most.
+ off(this, type, listener);
+ }
+});
+exports.EventTarget = EventTarget;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/events.js b/tools/addon-sdk-1.7/packages/api-utils/lib/events.js
new file mode 100644
index 0000000..531a7a3
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/events.js
@@ -0,0 +1,178 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const ERROR_TYPE = 'error',
+ UNCAUGHT_ERROR = 'An error event was dispatched for which there was'
+ + ' no listener.',
+ BAD_LISTENER = 'The event listener must be a function.';
+/**
+ * This object is used to create an `EventEmitter` that, useful for composing
+ * objects that emit events. It implements an interface like `EventTarget` from
+ * DOM Level 2, which is implemented by Node objects in implementations that
+ * support the DOM Event Model.
+ * @see http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget
+ * @see http://nodejs.org/api.html#EventEmitter
+ * @see http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/EventDispatcher.html
+ */
+const eventEmitter = {
+ /**
+ * Registers an event `listener` that is called every time events of
+ * specified `type` are emitted.
+ * @param {String} type
+ * The type of event.
+ * @param {Function} listener
+ * The listener function that processes the event.
+ * @example
+ * worker.on('message', function (data) {
+ * console.log('data received: ' + data)
+ * })
+ */
+ on: function on(type, listener) {
+ if ('function' !== typeof listener)
+ throw new Error(BAD_LISTENER);
+ let listeners = this._listeners(type);
+ if (0 > listeners.indexOf(listener))
+ listeners.push(listener);
+ // Use of `_public` is required by the legacy traits code that will go away
+ // once bug-637633 is fixed.
+ return this._public || this;
+ },
+
+ /**
+ * Registers an event `listener` that is called once the next time an event
+ * of the specified `type` is emitted.
+ * @param {String} type
+ * The type of the event.
+ * @param {Function} listener
+ * The listener function that processes the event.
+ */
+ once: function once(type, listener) {
+ this.on(type, function selfRemovableListener() {
+ this.removeListener(type, selfRemovableListener);
+ listener.apply(this, arguments);
+ });
+ },
+
+ /**
+ * Unregister `listener` for the specified event type.
+ * @param {String} type
+ * The type of event.
+ * @param {Function} listener
+ * The listener function that processes the event.
+ */
+ removeListener: function removeListener(type, listener) {
+ if ('function' !== typeof listener)
+ throw new Error(BAD_LISTENER);
+ let listeners = this._listeners(type),
+ index = listeners.indexOf(listener);
+ if (0 <= index)
+ listeners.splice(index, 1);
+ // Use of `_public` is required by the legacy traits code, that will go away
+ // once bug-637633 is fixed.
+ return this._public || this;
+ },
+
+ /**
+ * Hash of listeners on this EventEmitter.
+ */
+ _events: null,
+
+ /**
+ * Returns an array of listeners for the specified event `type`. This array
+ * can be manipulated, e.g. to remove listeners.
+ * @param {String} type
+ * The type of event.
+ */
+ _listeners: function listeners(type) {
+ let events = this._events || (this._events = {});
+ return events[type] || (events[type] = []);
+ },
+
+ /**
+ * Execute each of the listeners in order with the supplied arguments.
+ * Returns `true` if listener for this event was called, `false` if there are
+ * no listeners for this event `type`.
+ *
+ * All the exceptions that are thrown by listeners during the emit
+ * are caught and can be handled by listeners of 'error' event. Thrown
+ * exceptions are passed as an argument to an 'error' event listener.
+ * If no 'error' listener is registered exception will propagate to a
+ * caller of this method.
+ *
+ * **It's recommended to have a default 'error' listener in all the complete
+ * composition that in worst case may dump errors to the console.**
+ *
+ * @param {String} type
+ * The type of event.
+ * @params {Object|Number|String|Boolean}
+ * Arguments that will be passed to listeners.
+ * @returns {Boolean}
+ */
+ _emit: function _emit(type, event) {
+ let args = Array.slice(arguments);
+ // Use of `_public` is required by the legacy traits code that will go away
+ // once bug-637633 is fixed.
+ args.unshift(this._public || this);
+ return this._emitOnObject.apply(this, args);
+ },
+
+ /**
+ * A version of _emit that lets you specify the object on which listeners are
+ * called. This is a hack that is sometimes necessary when such an object
+ * (exports, for example) cannot be an EventEmitter for some reason, but other
+ * object(s) managing events for the object are EventEmitters. Once bug
+ * 577782 is fixed, this method shouldn't be necessary.
+ *
+ * @param {object} targetObj
+ * The object on which listeners will be called.
+ * @param {string} type
+ * The event name.
+ * @param {value} event
+ * The first argument to pass to listeners.
+ * @param {value} ...
+ * More arguments to pass to listeners.
+ * @returns {boolean}
+ */
+ _emitOnObject: function _emitOnObject(targetObj, type, event /* , ... */) {
+ let listeners = this._listeners(type).slice(0);
+ // If there is no 'error' event listener then throw.
+ if (type === ERROR_TYPE && !listeners.length)
+ console.exception(event);
+ if (!listeners.length)
+ return false;
+ let params = Array.slice(arguments, 2);
+ for each (let listener in listeners) {
+ try {
+ listener.apply(targetObj, params);
+ } catch(e) {
+ // Bug 726967: Ignore exceptions being throws while notifying the error
+ // in order to avoid infinite loops.
+ if (type !== ERROR_TYPE)
+ this._emit(ERROR_TYPE, e);
+ else
+ console.exception("Exception in error event listener " + e);
+ }
+ }
+ return true;
+ },
+
+ /**
+ * Removes all the event listeners for the specified event `type`.
+ * @param {String} type
+ * The type of event.
+ */
+ _removeAllListeners: function _removeAllListeners(type) {
+ if (typeof type == "undefined") {
+ this._events = null;
+ return this;
+ }
+
+ this._listeners(type).splice(0);
+ return this;
+ }
+};
+exports.EventEmitter = require("./traits").Trait.compose(eventEmitter);
+exports.EventEmitterTrait = require('./light-traits').Trait(eventEmitter);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/events/assembler.js b/tools/addon-sdk-1.7/packages/api-utils/lib/events/assembler.js
new file mode 100644
index 0000000..5d11be2
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/events/assembler.js
@@ -0,0 +1,53 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Trait } = require("../light-traits");
+const { removeListener, on } = require("../dom/events");
+
+/**
+ * Trait may be used for building objects / composing traits that wish to handle
+ * multiple dom events from multiple event targets in one place. Event targets
+ * can be added / removed by calling `observe / ignore` methods. Composer should
+ * provide array of event types it wishes to handle as property
+ * `supportedEventsTypes` and function for handling all those events as
+ * `handleEvent` property.
+ */
+exports.DOMEventAssembler = Trait({
+ /**
+ * Function that is supposed to handle all the supported events (that are
+ * present in the `supportedEventsTypes`) from all the observed
+ * `eventTargets`.
+ * @param {Event} event
+ * Event being dispatched.
+ */
+ handleEvent: Trait.required,
+ /**
+ * Array of supported event names.
+ * @type {String[]}
+ */
+ supportedEventsTypes: Trait.required,
+ /**
+ * Adds `eventTarget` to the list of observed `eventTarget`s. Listeners for
+ * supported events will be registered on the given `eventTarget`.
+ * @param {EventTarget} eventTarget
+ */
+ observe: function observe(eventTarget) {
+ this.supportedEventsTypes.forEach(function(eventType) {
+ on(eventTarget, eventType, this);
+ }, this);
+ },
+ /**
+ * Removes `eventTarget` from the list of observed `eventTarget`s. Listeners
+ * for all supported events will be unregistered from the given `eventTarget`.
+ * @param {EventTarget} eventTarget
+ */
+ ignore: function ignore(eventTarget) {
+ this.supportedEventsTypes.forEach(function(eventType) {
+ removeListener(eventTarget, eventType, this);
+ }, this);
+ }
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/file.js b/tools/addon-sdk-1.7/packages/api-utils/lib/file.js
new file mode 100644
index 0000000..0b4eac9
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/file.js
@@ -0,0 +1,192 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {Cc,Ci,Cr} = require("chrome");
+const byteStreams = require("./byte-streams");
+const textStreams = require("./text-streams");
+
+// Flags passed when opening a file. See nsprpub/pr/include/prio.h.
+const OPEN_FLAGS = {
+ RDONLY: parseInt("0x01"),
+ WRONLY: parseInt("0x02"),
+ CREATE_FILE: parseInt("0x08"),
+ APPEND: parseInt("0x10"),
+ TRUNCATE: parseInt("0x20"),
+ EXCL: parseInt("0x80")
+};
+
+var dirsvc = Cc["@mozilla.org/file/directory_service;1"]
+ .getService(Ci.nsIProperties);
+
+function MozFile(path) {
+ var file = Cc['@mozilla.org/file/local;1']
+ .createInstance(Ci.nsILocalFile);
+ file.initWithPath(path);
+ return file;
+}
+
+function ensureReadable(file) {
+ if (!file.isReadable())
+ throw new Error("path is not readable: " + file.path);
+}
+
+function ensureDir(file) {
+ ensureExists(file);
+ if (!file.isDirectory())
+ throw new Error("path is not a directory: " + file.path);
+}
+
+function ensureFile(file) {
+ ensureExists(file);
+ if (!file.isFile())
+ throw new Error("path is not a file: " + file.path);
+}
+
+function ensureExists(file) {
+ if (!file.exists())
+ throw friendlyError(Cr.NS_ERROR_FILE_NOT_FOUND, file.path);
+}
+
+function friendlyError(errOrResult, filename) {
+ var isResult = typeof(errOrResult) === "number";
+ var result = isResult ? errOrResult : errOrResult.result;
+ switch (result) {
+ case Cr.NS_ERROR_FILE_NOT_FOUND:
+ return new Error("path does not exist: " + filename);
+ }
+ return isResult ? new Error("XPCOM error code: " + errOrResult) : errOrResult;
+}
+
+exports.exists = function exists(filename) {
+ return MozFile(filename).exists();
+};
+
+exports.isFile = function isFile(filename) {
+ return MozFile(filename).isFile();
+};
+
+exports.read = function read(filename, mode) {
+ if (typeof(mode) !== "string")
+ mode = "";
+
+ // Ensure mode is read-only.
+ mode = /b/.test(mode) ? "b" : "";
+
+ var stream = exports.open(filename, mode);
+ try {
+ var str = stream.read();
+ }
+ finally {
+ stream.close();
+ }
+
+ return str;
+};
+
+exports.join = function join(base) {
+ if (arguments.length < 2)
+ throw new Error("need at least 2 args");
+ base = MozFile(base);
+ for (var i = 1; i < arguments.length; i++)
+ base.append(arguments[i]);
+ return base.path;
+};
+
+exports.dirname = function dirname(path) {
+ var parent = MozFile(path).parent;
+ return parent ? parent.path : "";
+};
+
+exports.basename = function basename(path) {
+ var leafName = MozFile(path).leafName;
+
+ // On Windows, leafName when the path is a volume letter and colon ("c:") is
+ // the path itself. But such a path has no basename, so we want the empty
+ // string.
+ return leafName == path ? "" : leafName;
+};
+
+exports.list = function list(path) {
+ var file = MozFile(path);
+ ensureDir(file);
+ ensureReadable(file);
+
+ var entries = file.directoryEntries;
+ var entryNames = [];
+ while(entries.hasMoreElements()) {
+ var entry = entries.getNext();
+ entry.QueryInterface(Ci.nsIFile);
+ entryNames.push(entry.leafName);
+ }
+ return entryNames;
+};
+
+exports.open = function open(filename, mode) {
+ var file = MozFile(filename);
+ if (typeof(mode) !== "string")
+ mode = "";
+
+ // File opened for write only.
+ if (/w/.test(mode)) {
+ if (file.exists())
+ ensureFile(file);
+ var stream = Cc['@mozilla.org/network/file-output-stream;1'].
+ createInstance(Ci.nsIFileOutputStream);
+ var openFlags = OPEN_FLAGS.WRONLY |
+ OPEN_FLAGS.CREATE_FILE |
+ OPEN_FLAGS.TRUNCATE;
+ var permFlags = parseInt("0644"); // u+rw go+r
+ try {
+ stream.init(file, openFlags, permFlags, 0);
+ }
+ catch (err) {
+ throw friendlyError(err, filename);
+ }
+ return /b/.test(mode) ?
+ new byteStreams.ByteWriter(stream) :
+ new textStreams.TextWriter(stream);
+ }
+
+ // File opened for read only, the default.
+ ensureFile(file);
+ stream = Cc['@mozilla.org/network/file-input-stream;1'].
+ createInstance(Ci.nsIFileInputStream);
+ try {
+ stream.init(file, OPEN_FLAGS.RDONLY, 0, 0);
+ }
+ catch (err) {
+ throw friendlyError(err, filename);
+ }
+ return /b/.test(mode) ?
+ new byteStreams.ByteReader(stream) :
+ new textStreams.TextReader(stream);
+};
+
+exports.remove = function remove(path) {
+ var file = MozFile(path);
+ ensureFile(file);
+ file.remove(false);
+};
+
+exports.mkpath = function mkpath(path) {
+ var file = MozFile(path);
+ if (!file.exists())
+ file.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755")); // u+rwx go+rx
+ else if (!file.isDirectory())
+ throw new Error("The path already exists and is not a directory: " + path);
+};
+
+exports.rmdir = function rmdir(path) {
+ var file = MozFile(path);
+ ensureDir(file);
+ try {
+ file.remove(false);
+ }
+ catch (err) {
+ // Bug 566950 explains why we're not catching a specific exception here.
+ throw new Error("The directory is not empty: " + path);
+ }
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/find-tests.js b/tools/addon-sdk-1.7/packages/api-utils/lib/find-tests.js
new file mode 100644
index 0000000..60550bf
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/find-tests.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// this file left intentionally blank
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/frame/utils.js b/tools/addon-sdk-1.7/packages/api-utils/lib/frame/utils.js
new file mode 100644
index 0000000..5c9da38
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/frame/utils.js
@@ -0,0 +1,59 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+const XUL = 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul';
+
+/**
+ * Creates a XUL `browser` element in a privileged document.
+ * @params {nsIDOMDocument} document
+ * @params {String} options.type
+ * By default is 'content' for possible values see:
+ * https://developer.mozilla.org/en/XUL/iframe#a-browser.type
+ * @params {String} options.uri
+ * URI of the document to be loaded into created frame.
+ * @params {Boolean} options.remote
+ * If `true` separate process will be used for this frame, also in such
+ * case all the following options are ignored.
+ * @params {Boolean} options.allowAuth
+ * Whether to allow auth dialogs. Defaults to `false`.
+ * @params {Boolean} options.allowJavascript
+ * Whether to allow Javascript execution. Defaults to `false`.
+ * @params {Boolean} options.allowPlugins
+ * Whether to allow plugin execution. Defaults to `false`.
+ */
+function create(document, options) {
+ options = options || {};
+ let remote = 'remote' in options && options.remote === true;
+
+ let frame = document.createElementNS(XUL, 'browser');
+ // Type="content" is mandatory to enable stuff here:
+ // http://mxr.mozilla.org/mozilla-central/source/content/base/src/nsFrameLoader.cpp#1776
+ frame.setAttribute('type', options.type || 'content');
+ frame.setAttribute('src', options.uri || 'about:blank');
+
+ // Load in separate process if `options.remote` is `true`.
+ // http://mxr.mozilla.org/mozilla-central/source/content/base/src/nsFrameLoader.cpp#1347
+ if (remote) {
+ // We remove XBL binding to avoid execution of code that is not going to
+ // work because browser has no docShell attribute in remote mode
+ // (for example)
+ frame.setAttribute('style', '-moz-binding: none;');
+ frame.setAttribute('remote', 'true');
+ }
+
+ document.documentElement.appendChild(frame);
+
+ // If browser is remote it won't have a `docShell`.
+ if (!remote) {
+ let docShell = frame.docShell;
+ docShell.allowAuth = options.allowAuth || false;
+ docShell.allowJavascript = options.allowJavascript || false;
+ docShell.allowPlugins = options.allowPlugins || false;
+ }
+
+ return frame;
+}
+exports.create = create;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/functional.js b/tools/addon-sdk-1.7/packages/api-utils/lib/functional.js
new file mode 100644
index 0000000..61738d9
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/functional.js
@@ -0,0 +1,159 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// Disclaimer: Most of the functions in this module implement APIs from
+// Jeremy Ashkenas's http://underscorejs.org/ library and all credits for
+// those goes to him.
+
+"use strict";
+
+const { setTimeout } = require("./timer");
+
+/**
+ * Takes `lambda` function and returns a method. When returned method is
+ * invoked it calls wrapped `lambda` and passes `this` as a first argument
+ * and given argument as rest.
+ */
+function method(lambda) {
+ return function method() {
+ return lambda.apply(null, [this].concat(Array.slice(arguments)));
+ }
+}
+exports.method = method;
+
+/**
+ * Takes a function and returns a wrapped one instead, calling which will call
+ * original function in the next turn of event loop. This is basically utility
+ * to do `setTimeout(function() { ... }, 0)`, with a difference that returned
+ * function is reused, instead of creating a new one each time. This also allows
+ * to use this functions as event listeners.
+ */
+function defer(f) {
+ return function deferred()
+ setTimeout(invoke, 0, f, arguments, this);
+}
+exports.defer = defer;
+// Exporting `remit` alias as `defer` may conflict with promises.
+exports.remit = defer;
+
+/**
+ * Invokes `callee` by passing `params` as an arguments and `self` as `this`
+ * pseudo-variable. Returns value that is returned by a callee.
+ * @param {Function} callee
+ * Function to invoke.
+ * @param {Array} params
+ * Arguments to invoke function with.
+ * @param {Object} self
+ * Object to be passed as a `this` pseudo variable.
+ */
+function invoke(callee, params, self) callee.apply(self, params);
+exports.invoke = invoke;
+
+/**
+ * Curries a function with the arguments given.
+ *
+ * @param {Function} fn
+ * The function to curry
+ *
+ * @returns The function curried
+ */
+function curry(fn) {
+ if (typeof fn !== "function")
+ throw new TypeError(String(fn) + " is not a function");
+
+ let args = Array.slice(arguments, 1);
+
+ return function() fn.apply(this, args.concat(Array.slice(arguments)));
+}
+exports.curry = curry;
+
+/**
+ * Returns the composition of a list of functions, where each function consumes
+ * the return value of the function that follows. In math terms, composing the
+ * functions `f()`, `g()`, and `h()` produces `f(g(h()))`.
+ * @example
+ *
+ * var greet = function(name) { return "hi: " + name; };
+ * var exclaim = function(statement) { return statement + "!"; };
+ * var welcome = compose(exclaim, greet);
+ *
+ * welcome('moe'); // => 'hi: moe!'
+ */
+function compose() {
+ let lambdas = Array.slice(arguments);
+ return function composed() {
+ let args = Array.slice(arguments), index = lambdas.length;
+ while (0 <= --index)
+ args = [ lambdas[index].apply(this, args) ];
+ return args[0];
+ };
+}
+exports.compose = compose;
+
+/*
+ * Returns the first function passed as an argument to the second,
+ * allowing you to adjust arguments, run code before and after, and
+ * conditionally execute the original function.
+ * @example
+ *
+ * var hello = function(name) { return "hello: " + name; };
+ * hello = wrap(hello, function(f) {
+ * return "before, " + f("moe") + ", after";
+ * });
+ *
+ * hello(); // => 'before, hello: moe, after'
+ */
+function wrap(f, wrapper) {
+ return function wrapped()
+ wrapper.apply(this, [ f ].concat(Array.slice(arguments)))
+};
+exports.wrap = wrap;
+
+/**
+ * Returns the same value that is used as the argument. In math: f(x) = x
+ */
+function identity(value) value
+exports.identity = identity;
+
+/**
+ * Memoizes a given function by caching the computed result. Useful for
+ * speeding up slow-running computations. If passed an optional hashFunction,
+ * it will be used to compute the hash key for storing the result, based on
+ * the arguments to the original function. The default hashFunction just uses
+ * the first argument to the memoized function as the key.
+ */
+function memoize(f, hasher) {
+ let memo = Object.create(null);
+ hasher = hasher || identity;
+ return function memoizer() {
+ let key = hasher.apply(this, arguments);
+ return key in memo ? memo[key] : (memo[key] = f.apply(this, arguments));
+ };
+}
+exports.memoize = memoize;
+
+/**
+ * Much like setTimeout, invokes function after wait milliseconds. If you pass
+ * the optional arguments, they will be forwarded on to the function when it is
+ * invoked.
+ */
+function delay(f, ms) {
+ let args = Array.slice(arguments, 2);
+ setTimeout(function(context) { return f.apply(context, args); }, ms, this);
+};
+exports.delay = delay;
+
+/**
+ * Creates a version of the function that can only be called one time. Repeated
+ * calls to the modified function will have no effect, returning the value from
+ * the original call. Useful for initialization functions, instead of having to
+ * set a boolean flag and then check it later.
+ */
+function once(f) {
+ let ran = false, cache;
+ return function() ran ? cache : (ran = true, cache = f.apply(this, arguments))
+};
+exports.once = once;
+// export cache as once will may be conflicting with event once a lot.
+exports.cache = once;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/globals!.js b/tools/addon-sdk-1.7/packages/api-utils/lib/globals!.js
new file mode 100644
index 0000000..01e85b7
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/globals!.js
@@ -0,0 +1,93 @@
+/* vim:set ts=2 sw=2 sts=2 expandtab */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+let { Cc, Ci } = require('chrome');
+let { PlainTextConsole } = require('./plain-text-console');
+let options = require('@packaging');
+let consoleService = Cc['@mozilla.org/consoleservice;1'].getService().
+ QueryInterface(Ci.nsIConsoleService);
+
+// On windows dump does not writes into stdout so cfx can't read thous dumps.
+// To workaround this issue we write to a special file from which cfx will
+// read and print to the console.
+// For more details see: bug-673383
+exports.dump = (function define(global) {
+ const PR_WRONLY = 0x02;
+ const PR_CREATE_FILE = 0x08;
+ const PR_APPEND = 0x10;
+ let print = Object.getPrototypeOf(global).dump
+ if (print) return print;
+ if ('logFile' in options) {
+ let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
+ file.initWithPath(options.logFile);
+ let stream = Cc["@mozilla.org/network/file-output-stream;1"].
+ createInstance(Ci.nsIFileOutputStream);
+ stream.init(file, PR_WRONLY|PR_CREATE_FILE|PR_APPEND, -1, 0);
+
+ return function print(message) {
+ message = String(message);
+ stream.write(message, message.length);
+ stream.flush();
+ };
+ }
+ return dump;
+})(this);
+
+// Override the default Iterator function with one that passes
+// a second argument to custom iterator methods that identifies
+// the call as originating from an Iterator function so the custom
+// iterator method can return [key, value] pairs just like default
+// iterators called via the default Iterator function.
+exports.Iterator = (function(DefaultIterator) {
+ return function Iterator(obj, keysOnly) {
+ if ("__iterator__" in obj && !keysOnly)
+ return obj.__iterator__.call(obj, false, true);
+ return DefaultIterator(obj, keysOnly);
+ };
+})(Iterator);
+
+// Bug 718230: We need to send console messages to stdout and JS Console
+function forsakenConsoleDump(msg, level) {
+ exports.dump(msg);
+
+ if (level === "error") {
+ let err = Cc["@mozilla.org/scripterror;1"].
+ createInstance(Ci.nsIScriptError);
+ msg = msg.replace(/^error: /, "");
+ err.init(msg, null, null, 0, 0, 0, "Add-on SDK");
+ consoleService.logMessage(err);
+ }
+ else
+ consoleService.logStringMessage(msg);
+};
+exports.console = new PlainTextConsole(forsakenConsoleDump);
+
+// Provide CommonJS `define` to allow authoring modules in a format that can be
+// loaded both into jetpack and into browser via AMD loaders.
+Object.defineProperty(exports, 'define', {
+ // `define` is provided as a lazy getter that binds below defined `define`
+ // function to the module scope, so that require, exports and module
+ // variables remain accessible.
+ configurable: true,
+ get: (function() {
+ function define(factory) {
+ factory = Array.slice(arguments).pop();
+ factory.call(this, this.require, this.exports, this.module);
+ }
+
+ return function getter() {
+ // Redefine `define` as a static property to make sure that module
+ // gets access to the same function so that `define === define` is
+ // `true`.
+ Object.defineProperty(this, 'define', {
+ configurable: false,
+ value: define.bind(this)
+ });
+ return this.define;
+ }
+ })()
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/hidden-frame.js b/tools/addon-sdk-1.7/packages/api-utils/lib/hidden-frame.js
new file mode 100644
index 0000000..6f0016b
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/hidden-frame.js
@@ -0,0 +1,166 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {Cc, Ci} = require("chrome");
+const errors = require("./errors");
+const apiUtils = require("./api-utils");
+const timer = require("./timer");
+
+const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
+
+let hostFrame, hostDocument, hiddenWindow, isHostFrameReady = false;
+
+if (!require("./xul-app").isOneOf(["Firefox", "Fennec", "Thunderbird"])) {
+ throw new Error([
+ "The hidden-frame module currently supports only Firefox and Thunderbird. ",
+ "In the future, we would like it to support other applications, however. ",
+ "Please see https://bugzilla.mozilla.org/show_bug.cgi?id=546740 for more ",
+ "information."
+ ].join(""));
+}
+
+let appShellService = Cc["@mozilla.org/appshell/appShellService;1"].
+ getService(Ci.nsIAppShellService);
+hiddenWindow = appShellService.hiddenDOMWindow;
+
+if (!hiddenWindow) {
+ throw new Error([
+ "The hidden-frame module needs an app that supports a hidden window. ",
+ "We would like it to support other applications, however. Please see ",
+ "https://bugzilla.mozilla.org/show_bug.cgi?id=546740 for more information."
+ ].join(""));
+}
+
+// Check if we can use the hidden window itself to host our iframes.
+// If it's not a suitable host, the hostFrame will be lazily created
+// by the first HiddenFrame instance.
+if (hiddenWindow.location.protocol == "chrome:" &&
+ (hiddenWindow.document.contentType == "application/vnd.mozilla.xul+xml" ||
+ hiddenWindow.document.contentType == "application/xhtml+xml")) {
+ hostFrame = hiddenWindow;
+ hostDocument = hiddenWindow.document;
+ isHostFrameReady = true;
+}
+
+function setHostFrameReady() {
+ hostDocument = hostFrame.contentDocument;
+ hostFrame.removeEventListener("DOMContentLoaded", setHostFrameReady, false);
+ isHostFrameReady = true;
+}
+
+// This cache is used to access friend properties between functions
+// without exposing them on the public API.
+let cache = [];
+
+exports.HiddenFrame = apiUtils.publicConstructor(HiddenFrame);
+
+function HiddenFrame(options) {
+ options = options || {};
+ let self = this;
+
+ for each (let [key, val] in Iterator(apiUtils.validateOptions(options, {
+ onReady: {
+ is: ["undefined", "function", "array"],
+ ok: function(v) {
+ if (apiUtils.getTypeOf(v) === "array") {
+ // make sure every item is a function
+ return v.every(function (item) typeof(item) === "function")
+ }
+ return true;
+ }
+ }
+ }))) {
+ if (typeof(val) != "undefined")
+ options[key] = val;
+ }
+
+ require("./collection").addCollectionProperty(this, "onReady");
+ if (options.onReady)
+ this.onReady.add(options.onReady);
+
+ if (!hostFrame) {
+ hostFrame = hiddenWindow.document.createElement("iframe");
+
+ // ugly ugly hack. This is the most lightweight chrome:// file I could find on the tree
+ // This hack should be removed by proper platform support on bug 565388
+ hostFrame.setAttribute("src", "chrome://global/content/mozilla.xhtml");
+ hostFrame.addEventListener("DOMContentLoaded", setHostFrameReady, false);
+
+ hiddenWindow.document.body.appendChild(hostFrame);
+ }
+
+ this.toString = function toString() "[object Frame]";
+}
+
+exports.add = function JP_SDK_Frame_add(frame) {
+ if (!(frame instanceof HiddenFrame))
+ throw new Error("The object to be added must be a HiddenFrame.");
+
+ // This instance was already added.
+ if (cache.filter(function (v) v.frame === frame)[0])
+ return frame;
+
+ function createElement() {
+ hostFrame.removeEventListener("DOMContentLoaded", createElement, false);
+
+ let element = hostDocument.createElementNS(XUL_NS, "iframe");
+
+ element.setAttribute("type", "content");
+ hostDocument.documentElement.appendChild(element);
+
+ /* Public API: hiddenFrame.element */
+ frame.__defineGetter__("element", function () element);
+
+ // Notify consumers that the frame is ready.
+ function onReadyListener(event) {
+ element.removeEventListener("DOMContentLoaded", onReadyListener, false);
+ if (event.target == element.contentDocument) {
+ for (let handler in frame.onReady)
+ errors.catchAndLog(function () handler.call(frame))();
+ }
+ }
+ element.addEventListener("DOMContentLoaded", onReadyListener, false);
+
+ cache.push({
+ frame: frame,
+ element: element,
+ unload: function unload() {
+ hostDocument.documentElement.removeChild(element);
+ }
+ });
+ }
+
+ /* Begin element construction or schedule it for later */
+ if (isHostFrameReady) {
+ createElement();
+ } else {
+ hostFrame.addEventListener("DOMContentLoaded", createElement, false);
+ }
+
+ return frame;
+}
+
+exports.remove = function remove(frame) {
+ if (!(frame instanceof HiddenFrame))
+ throw new Error("The object to be removed must be a HiddenFrame.");
+
+ let entry = cache.filter(function (v) v.frame === frame)[0];
+ if (!entry)
+ return;
+
+ entry.unload();
+ cache.splice(cache.indexOf(entry), 1);
+}
+
+require("./unload").when(function () {
+ for each (let entry in cache.slice())
+ exports.remove(entry.frame);
+
+ if (hostFrame && hostFrame !== hiddenWindow)
+ hiddenWindow.document.body.removeChild(hostFrame);
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/httpd.js b/tools/addon-sdk-1.7/packages/api-utils/lib/httpd.js
new file mode 100644
index 0000000..7f6a363
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/httpd.js
@@ -0,0 +1,5166 @@
+/* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+* License, v. 2.0. If a copy of the MPL was not distributed with this
+* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+* An implementation of an HTTP server both as a loadable script and as an XPCOM
+* component. See the accompanying README file for user documentation on
+* httpd.js.
+*/
+
+
+var {components,Cc,Ci,Cr,Cu} = require("chrome");
+components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+const CC = components.Constructor;
+
+const PR_UINT32_MAX = Math.pow(2, 32) - 1;
+
+/** True if debugging output is enabled, false otherwise. */
+var DEBUG = false; // non-const *only* so tweakable in server tests
+
+/** True if debugging output should be timestamped. */
+var DEBUG_TIMESTAMP = false; // non-const so tweakable in server tests
+
+var gGlobalObject = Cc["@mozilla.org/systemprincipal;1"].createInstance();
+
+/**
+* Asserts that the given condition holds. If it doesn't, the given message is
+* dumped, a stack trace is printed, and an exception is thrown to attempt to
+* stop execution (which unfortunately must rely upon the exception not being
+* accidentally swallowed by the code that uses it).
+*/
+function NS_ASSERT(cond, msg)
+{
+ if (DEBUG && !cond)
+ {
+ dumpn("###!!!");
+ dumpn("###!!! ASSERTION" + (msg ? ": " + msg : "!"));
+ dumpn("###!!! Stack follows:");
+
+ var stack = new Error().stack.split(/\n/);
+ dumpn(stack.map(function(val) { return "###!!! " + val; }).join("\n"));
+
+ throw Cr.NS_ERROR_ABORT;
+ }
+}
+
+/** Constructs an HTTP error object. */
+function HttpError(code, description)
+{
+ this.code = code;
+ this.description = description;
+}
+HttpError.prototype =
+{
+ toString: function()
+ {
+ return this.code + " " + this.description;
+ }
+};
+
+/**
+* Errors thrown to trigger specific HTTP server responses.
+*/
+const HTTP_400 = new HttpError(400, "Bad Request");
+const HTTP_401 = new HttpError(401, "Unauthorized");
+const HTTP_402 = new HttpError(402, "Payment Required");
+const HTTP_403 = new HttpError(403, "Forbidden");
+const HTTP_404 = new HttpError(404, "Not Found");
+const HTTP_405 = new HttpError(405, "Method Not Allowed");
+const HTTP_406 = new HttpError(406, "Not Acceptable");
+const HTTP_407 = new HttpError(407, "Proxy Authentication Required");
+const HTTP_408 = new HttpError(408, "Request Timeout");
+const HTTP_409 = new HttpError(409, "Conflict");
+const HTTP_410 = new HttpError(410, "Gone");
+const HTTP_411 = new HttpError(411, "Length Required");
+const HTTP_412 = new HttpError(412, "Precondition Failed");
+const HTTP_413 = new HttpError(413, "Request Entity Too Large");
+const HTTP_414 = new HttpError(414, "Request-URI Too Long");
+const HTTP_415 = new HttpError(415, "Unsupported Media Type");
+const HTTP_417 = new HttpError(417, "Expectation Failed");
+
+const HTTP_500 = new HttpError(500, "Internal Server Error");
+const HTTP_501 = new HttpError(501, "Not Implemented");
+const HTTP_502 = new HttpError(502, "Bad Gateway");
+const HTTP_503 = new HttpError(503, "Service Unavailable");
+const HTTP_504 = new HttpError(504, "Gateway Timeout");
+const HTTP_505 = new HttpError(505, "HTTP Version Not Supported");
+
+/** Creates a hash with fields corresponding to the values in arr. */
+function array2obj(arr)
+{
+ var obj = {};
+ for (var i = 0; i < arr.length; i++)
+ obj[arr[i]] = arr[i];
+ return obj;
+}
+
+/** Returns an array of the integers x through y, inclusive. */
+function range(x, y)
+{
+ var arr = [];
+ for (var i = x; i <= y; i++)
+ arr.push(i);
+ return arr;
+}
+
+/** An object (hash) whose fields are the numbers of all HTTP error codes. */
+const HTTP_ERROR_CODES = array2obj(range(400, 417).concat(range(500, 505)));
+
+
+/**
+* The character used to distinguish hidden files from non-hidden files, a la
+* the leading dot in Apache. Since that mechanism also hides files from
+* easy display in LXR, ls output, etc. however, we choose instead to use a
+* suffix character. If a requested file ends with it, we append another
+* when getting the file on the server. If it doesn't, we just look up that
+* file. Therefore, any file whose name ends with exactly one of the character
+* is "hidden" and available for use by the server.
+*/
+const HIDDEN_CHAR = "^";
+
+/**
+* The file name suffix indicating the file containing overridden headers for
+* a requested file.
+*/
+const HEADERS_SUFFIX = HIDDEN_CHAR + "headers" + HIDDEN_CHAR;
+
+/** Type used to denote SJS scripts for CGI-like functionality. */
+const SJS_TYPE = "sjs";
+
+/** Base for relative timestamps produced by dumpn(). */
+var firstStamp = 0;
+
+/** dump(str) with a trailing "\n" -- only outputs if DEBUG. */
+function dumpn(str)
+{
+ if (DEBUG)
+ {
+ var prefix = "HTTPD-INFO | ";
+ if (DEBUG_TIMESTAMP)
+ {
+ if (firstStamp === 0)
+ firstStamp = Date.now();
+
+ var elapsed = Date.now() - firstStamp; // milliseconds
+ var min = Math.floor(elapsed / 60000);
+ var sec = (elapsed % 60000) / 1000;
+
+ if (sec < 10)
+ prefix += min + ":0" + sec.toFixed(3) + " | ";
+ else
+ prefix += min + ":" + sec.toFixed(3) + " | ";
+ }
+
+ dump(prefix + str + "\n");
+ }
+}
+
+/** Dumps the current JS stack if DEBUG. */
+function dumpStack()
+{
+ // peel off the frames for dumpStack() and Error()
+ var stack = new Error().stack.split(/\n/).slice(2);
+ stack.forEach(dumpn);
+}
+
+
+/** The XPCOM thread manager. */
+var gThreadManager = null;
+
+/** The XPCOM prefs service. */
+var gRootPrefBranch = null;
+function getRootPrefBranch()
+{
+ if (!gRootPrefBranch)
+ {
+ gRootPrefBranch = Cc["@mozilla.org/preferences-service;1"]
+ .getService(Ci.nsIPrefBranch);
+ }
+ return gRootPrefBranch;
+}
+
+/**
+* JavaScript constructors for commonly-used classes; precreating these is a
+* speedup over doing the same from base principles. See the docs at
+* http://developer.mozilla.org/en/docs/components.Constructor for details.
+*/
+const ServerSocket = CC("@mozilla.org/network/server-socket;1",
+ "nsIServerSocket",
+ "init");
+const ScriptableInputStream = CC("@mozilla.org/scriptableinputstream;1",
+ "nsIScriptableInputStream",
+ "init");
+const Pipe = CC("@mozilla.org/pipe;1",
+ "nsIPipe",
+ "init");
+const FileInputStream = CC("@mozilla.org/network/file-input-stream;1",
+ "nsIFileInputStream",
+ "init");
+const ConverterInputStream = CC("@mozilla.org/intl/converter-input-stream;1",
+ "nsIConverterInputStream",
+ "init");
+const WritablePropertyBag = CC("@mozilla.org/hash-property-bag;1",
+ "nsIWritablePropertyBag2");
+const SupportsString = CC("@mozilla.org/supports-string;1",
+ "nsISupportsString");
+
+/* These two are non-const only so a test can overwrite them. */
+var BinaryInputStream = CC("@mozilla.org/binaryinputstream;1",
+ "nsIBinaryInputStream",
+ "setInputStream");
+var BinaryOutputStream = CC("@mozilla.org/binaryoutputstream;1",
+ "nsIBinaryOutputStream",
+ "setOutputStream");
+
+/**
+* Returns the RFC 822/1123 representation of a date.
+*
+* @param date : Number
+* the date, in milliseconds from midnight (00:00:00), January 1, 1970 GMT
+* @returns string
+* the representation of the given date
+*/
+function toDateString(date)
+{
+ //
+ // rfc1123-date = wkday "," SP date1 SP time SP "GMT"
+ // date1 = 2DIGIT SP month SP 4DIGIT
+ // ; day month year (e.g., 02 Jun 1982)
+ // time = 2DIGIT ":" 2DIGIT ":" 2DIGIT
+ // ; 00:00:00 - 23:59:59
+ // wkday = "Mon" | "Tue" | "Wed"
+ // | "Thu" | "Fri" | "Sat" | "Sun"
+ // month = "Jan" | "Feb" | "Mar" | "Apr"
+ // | "May" | "Jun" | "Jul" | "Aug"
+ // | "Sep" | "Oct" | "Nov" | "Dec"
+ //
+
+ const wkdayStrings = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
+ const monthStrings = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
+
+ /**
+* Processes a date and returns the encoded UTC time as a string according to
+* the format specified in RFC 2616.
+*
+* @param date : Date
+* the date to process
+* @returns string
+* a string of the form "HH:MM:SS", ranging from "00:00:00" to "23:59:59"
+*/
+ function toTime(date)
+ {
+ var hrs = date.getUTCHours();
+ var rv = (hrs < 10) ? "0" + hrs : hrs;
+
+ var mins = date.getUTCMinutes();
+ rv += ":";
+ rv += (mins < 10) ? "0" + mins : mins;
+
+ var secs = date.getUTCSeconds();
+ rv += ":";
+ rv += (secs < 10) ? "0" + secs : secs;
+
+ return rv;
+ }
+
+ /**
+* Processes a date and returns the encoded UTC date as a string according to
+* the date1 format specified in RFC 2616.
+*
+* @param date : Date
+* the date to process
+* @returns string
+* a string of the form "HH:MM:SS", ranging from "00:00:00" to "23:59:59"
+*/
+ function toDate1(date)
+ {
+ var day = date.getUTCDate();
+ var month = date.getUTCMonth();
+ var year = date.getUTCFullYear();
+
+ var rv = (day < 10) ? "0" + day : day;
+ rv += " " + monthStrings[month];
+ rv += " " + year;
+
+ return rv;
+ }
+
+ date = new Date(date);
+
+ const fmtString = "%wkday%, %date1% %time% GMT";
+ var rv = fmtString.replace("%wkday%", wkdayStrings[date.getUTCDay()]);
+ rv = rv.replace("%time%", toTime(date));
+ return rv.replace("%date1%", toDate1(date));
+}
+
+/**
+* Prints out a human-readable representation of the object o and its fields,
+* omitting those whose names begin with "_" if showMembers != true (to ignore
+* "private" properties exposed via getters/setters).
+*/
+function printObj(o, showMembers)
+{
+ var s = "******************************\n";
+ s += "o = {\n";
+ for (var i in o)
+ {
+ if (typeof(i) != "string" ||
+ (showMembers || (i.length > 0 && i[0] != "_")))
+ s+= " " + i + ": " + o[i] + ",\n";
+ }
+ s += " };\n";
+ s += "******************************";
+ dumpn(s);
+}
+
+/**
+* Instantiates a new HTTP server.
+*/
+function nsHttpServer()
+{
+ if (!gThreadManager)
+ gThreadManager = Cc["@mozilla.org/thread-manager;1"].getService();
+
+ /** The port on which this server listens. */
+ this._port = undefined;
+
+ /** The socket associated with this. */
+ this._socket = null;
+
+ /** The handler used to process requests to this server. */
+ this._handler = new ServerHandler(this);
+
+ /** Naming information for this server. */
+ this._identity = new ServerIdentity();
+
+ /**
+* Indicates when the server is to be shut down at the end of the request.
+*/
+ this._doQuit = false;
+
+ /**
+* True if the socket in this is closed (and closure notifications have been
+* sent and processed if the socket was ever opened), false otherwise.
+*/
+ this._socketClosed = true;
+
+ /**
+* Used for tracking existing connections and ensuring that all connections
+* are properly cleaned up before server shutdown; increases by 1 for every
+* new incoming connection.
+*/
+ this._connectionGen = 0;
+
+ /**
+* Hash of all open connections, indexed by connection number at time of
+* creation.
+*/
+ this._connections = {};
+}
+nsHttpServer.prototype =
+{
+ classID: components.ID("{54ef6f81-30af-4b1d-ac55-8ba811293e41}"),
+
+ // NSISERVERSOCKETLISTENER
+
+ /**
+* Processes an incoming request coming in on the given socket and contained
+* in the given transport.
+*
+* @param socket : nsIServerSocket
+* the socket through which the request was served
+* @param trans : nsISocketTransport
+* the transport for the request/response
+* @see nsIServerSocketListener.onSocketAccepted
+*/
+ onSocketAccepted: function(socket, trans)
+ {
+ dumpn("*** onSocketAccepted(socket=" + socket + ", trans=" + trans + ")");
+
+ dumpn(">>> new connection on " + trans.host + ":" + trans.port);
+
+ const SEGMENT_SIZE = 8192;
+ const SEGMENT_COUNT = 1024;
+ try
+ {
+ var input = trans.openInputStream(0, SEGMENT_SIZE, SEGMENT_COUNT)
+ .QueryInterface(Ci.nsIAsyncInputStream);
+ var output = trans.openOutputStream(0, 0, 0);
+ }
+ catch (e)
+ {
+ dumpn("*** error opening transport streams: " + e);
+ trans.close(Cr.NS_BINDING_ABORTED);
+ return;
+ }
+
+ var connectionNumber = ++this._connectionGen;
+
+ try
+ {
+ var conn = new Connection(input, output, this, socket.port, trans.port,
+ connectionNumber);
+ var reader = new RequestReader(conn);
+
+ // XXX add request timeout functionality here!
+
+ // Note: must use main thread here, or we might get a GC that will cause
+ // threadsafety assertions. We really need to fix XPConnect so that
+ // you can actually do things in multi-threaded JS. :-(
+ input.asyncWait(reader, 0, 0, gThreadManager.mainThread);
+ }
+ catch (e)
+ {
+ // Assume this connection can't be salvaged and bail on it completely;
+ // don't attempt to close it so that we can assert that any connection
+ // being closed is in this._connections.
+ dumpn("*** error in initial request-processing stages: " + e);
+ trans.close(Cr.NS_BINDING_ABORTED);
+ return;
+ }
+
+ this._connections[connectionNumber] = conn;
+ dumpn("*** starting connection " + connectionNumber);
+ },
+
+ /**
+* Called when the socket associated with this is closed.
+*
+* @param socket : nsIServerSocket
+* the socket being closed
+* @param status : nsresult
+* the reason the socket stopped listening (NS_BINDING_ABORTED if the server
+* was stopped using nsIHttpServer.stop)
+* @see nsIServerSocketListener.onStopListening
+*/
+ onStopListening: function(socket, status)
+ {
+ dumpn(">>> shutting down server on port " + socket.port);
+ this._socketClosed = true;
+ if (!this._hasOpenConnections())
+ {
+ dumpn("*** no open connections, notifying async from onStopListening");
+
+ // Notify asynchronously so that any pending teardown in stop() has a
+ // chance to run first.
+ var self = this;
+ var stopEvent =
+ {
+ run: function()
+ {
+ dumpn("*** _notifyStopped async callback");
+ self._notifyStopped();
+ }
+ };
+ gThreadManager.currentThread
+ .dispatch(stopEvent, Ci.nsIThread.DISPATCH_NORMAL);
+ }
+ },
+
+ // NSIHTTPSERVER
+
+ //
+ // see nsIHttpServer.start
+ //
+ start: function(port)
+ {
+ this._start(port, "localhost")
+ },
+
+ _start: function(port, host)
+ {
+ if (this._socket)
+ throw Cr.NS_ERROR_ALREADY_INITIALIZED;
+
+ this._port = port;
+ this._doQuit = this._socketClosed = false;
+
+ this._host = host;
+
+ // The listen queue needs to be long enough to handle
+ // network.http.max-connections-per-server concurrent connections,
+ // plus a safety margin in case some other process is talking to
+ // the server as well.
+ var prefs = getRootPrefBranch();
+ var maxConnections =
+ prefs.getIntPref("network.http.max-connections-per-server") + 5;
+
+ try
+ {
+ var loopback = true;
+ if (this._host != "127.0.0.1" && this._host != "localhost") {
+ var loopback = false;
+ }
+
+ var socket = new ServerSocket(this._port,
+ loopback, // true = localhost, false = everybody
+ maxConnections);
+ dumpn(">>> listening on port " + socket.port + ", " + maxConnections +
+ " pending connections");
+ socket.asyncListen(this);
+ this._identity._initialize(port, host, true);
+ this._socket = socket;
+ }
+ catch (e)
+ {
+ dumpn("!!! could not start server on port " + port + ": " + e);
+ throw Cr.NS_ERROR_NOT_AVAILABLE;
+ }
+ },
+
+ //
+ // see nsIHttpServer.stop
+ //
+ stop: function(callback)
+ {
+ if (!callback)
+ throw Cr.NS_ERROR_NULL_POINTER;
+ if (!this._socket)
+ throw Cr.NS_ERROR_UNEXPECTED;
+
+ this._stopCallback = typeof callback === "function"
+ ? callback
+ : function() { callback.onStopped(); };
+
+ dumpn(">>> stopping listening on port " + this._socket.port);
+ this._socket.close();
+ this._socket = null;
+
+ // We can't have this identity any more, and the port on which we're running
+ // this server now could be meaningless the next time around.
+ this._identity._teardown();
+
+ this._doQuit = false;
+
+ // socket-close notification and pending request completion happen async
+ },
+
+ //
+ // see nsIHttpServer.registerFile
+ //
+ registerFile: function(path, file)
+ {
+ if (file && (!file.exists() || file.isDirectory()))
+ throw Cr.NS_ERROR_INVALID_ARG;
+
+ this._handler.registerFile(path, file);
+ },
+
+ //
+ // see nsIHttpServer.registerDirectory
+ //
+ registerDirectory: function(path, directory)
+ {
+ // XXX true path validation!
+ if (path.charAt(0) != "/" ||
+ path.charAt(path.length - 1) != "/" ||
+ (directory &&
+ (!directory.exists() || !directory.isDirectory())))
+ throw Cr.NS_ERROR_INVALID_ARG;
+
+ // XXX determine behavior of nonexistent /foo/bar when a /foo/bar/ mapping
+ // exists!
+
+ this._handler.registerDirectory(path, directory);
+ },
+
+ //
+ // see nsIHttpServer.registerPathHandler
+ //
+ registerPathHandler: function(path, handler)
+ {
+ this._handler.registerPathHandler(path, handler);
+ },
+
+ //
+ // see nsIHttpServer.registerErrorHandler
+ //
+ registerErrorHandler: function(code, handler)
+ {
+ this._handler.registerErrorHandler(code, handler);
+ },
+
+ //
+ // see nsIHttpServer.setIndexHandler
+ //
+ setIndexHandler: function(handler)
+ {
+ this._handler.setIndexHandler(handler);
+ },
+
+ //
+ // see nsIHttpServer.registerContentType
+ //
+ registerContentType: function(ext, type)
+ {
+ this._handler.registerContentType(ext, type);
+ },
+
+ //
+ // see nsIHttpServer.serverIdentity
+ //
+ get identity()
+ {
+ return this._identity;
+ },
+
+ //
+ // see nsIHttpServer.getState
+ //
+ getState: function(path, k)
+ {
+ return this._handler._getState(path, k);
+ },
+
+ //
+ // see nsIHttpServer.setState
+ //
+ setState: function(path, k, v)
+ {
+ return this._handler._setState(path, k, v);
+ },
+
+ //
+ // see nsIHttpServer.getSharedState
+ //
+ getSharedState: function(k)
+ {
+ return this._handler._getSharedState(k);
+ },
+
+ //
+ // see nsIHttpServer.setSharedState
+ //
+ setSharedState: function(k, v)
+ {
+ return this._handler._setSharedState(k, v);
+ },
+
+ //
+ // see nsIHttpServer.getObjectState
+ //
+ getObjectState: function(k)
+ {
+ return this._handler._getObjectState(k);
+ },
+
+ //
+ // see nsIHttpServer.setObjectState
+ //
+ setObjectState: function(k, v)
+ {
+ return this._handler._setObjectState(k, v);
+ },
+
+
+ // NSISUPPORTS
+
+ //
+ // see nsISupports.QueryInterface
+ //
+ QueryInterface: function(iid)
+ {
+ if (iid.equals(Ci.nsIServerSocketListener) || iid.equals(Ci.nsISupports))
+ return this;
+
+ throw Cr.NS_ERROR_NO_INTERFACE;
+ },
+
+
+ // NON-XPCOM PUBLIC API
+
+ /**
+* Returns true iff this server is not running (and is not in the process of
+* serving any requests still to be processed when the server was last
+* stopped after being run).
+*/
+ isStopped: function()
+ {
+ return this._socketClosed && !this._hasOpenConnections();
+ },
+
+ // PRIVATE IMPLEMENTATION
+
+ /** True if this server has any open connections to it, false otherwise. */
+ _hasOpenConnections: function()
+ {
+ //
+ // If we have any open connections, they're tracked as numeric properties on
+ // |this._connections|. The non-standard __count__ property could be used
+ // to check whether there are any properties, but standard-wise, even
+ // looking forward to ES5, there's no less ugly yet still O(1) way to do
+ // this.
+ //
+ for (var n in this._connections)
+ return true;
+ return false;
+ },
+
+ /** Calls the server-stopped callback provided when stop() was called. */
+ _notifyStopped: function()
+ {
+ NS_ASSERT(this._stopCallback !== null, "double-notifying?");
+ NS_ASSERT(!this._hasOpenConnections(), "should be done serving by now");
+
+ //
+ // NB: We have to grab this now, null out the member, *then* call the
+ // callback here, or otherwise the callback could (indirectly) futz with
+ // this._stopCallback by starting and immediately stopping this, at
+ // which point we'd be nulling out a field we no longer have a right to
+ // modify.
+ //
+ var callback = this._stopCallback;
+ this._stopCallback = null;
+ try
+ {
+ callback();
+ }
+ catch (e)
+ {
+ // not throwing because this is specified as being usually (but not
+ // always) asynchronous
+ dump("!!! error running onStopped callback: " + e + "\n");
+ }
+ },
+
+ /**
+* Notifies this server that the given connection has been closed.
+*
+* @param connection : Connection
+* the connection that was closed
+*/
+ _connectionClosed: function(connection)
+ {
+ NS_ASSERT(connection.number in this._connections,
+ "closing a connection " + this + " that we never added to the " +
+ "set of open connections?");
+ NS_ASSERT(this._connections[connection.number] === connection,
+ "connection number mismatch? " +
+ this._connections[connection.number]);
+ delete this._connections[connection.number];
+
+ // Fire a pending server-stopped notification if it's our responsibility.
+ if (!this._hasOpenConnections() && this._socketClosed)
+ this._notifyStopped();
+ },
+
+ /**
+* Requests that the server be shut down when possible.
+*/
+ _requestQuit: function()
+ {
+ dumpn(">>> requesting a quit");
+ dumpStack();
+ this._doQuit = true;
+ }
+};
+
+
+//
+// RFC 2396 section 3.2.2:
+//
+// host = hostname | IPv4address
+// hostname = *( domainlabel "." ) toplabel [ "." ]
+// domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
+// toplabel = alpha | alpha *( alphanum | "-" ) alphanum
+// IPv4address = 1*digit "." 1*digit "." 1*digit "." 1*digit
+//
+
+const HOST_REGEX =
+ new RegExp("^(?:" +
+ // *( domainlabel "." )
+ "(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)*" +
+ // toplabel
+ "[a-z](?:[a-z0-9-]*[a-z0-9])?" +
+ "|" +
+ // IPv4 address
+ "\\d+\\.\\d+\\.\\d+\\.\\d+" +
+ ")$",
+ "i");
+
+
+/**
+* Represents the identity of a server. An identity consists of a set of
+* (scheme, host, port) tuples denoted as locations (allowing a single server to
+* serve multiple sites or to be used behind both HTTP and HTTPS proxies for any
+* host/port). Any incoming request must be to one of these locations, or it
+* will be rejected with an HTTP 400 error. One location, denoted as the
+* primary location, is the location assigned in contexts where a location
+* cannot otherwise be endogenously derived, such as for HTTP/1.0 requests.
+*
+* A single identity may contain at most one location per unique host/port pair;
+* other than that, no restrictions are placed upon what locations may
+* constitute an identity.
+*/
+function ServerIdentity()
+{
+ /** The scheme of the primary location. */
+ this._primaryScheme = "http";
+
+ /** The hostname of the primary location. */
+ this._primaryHost = "127.0.0.1"
+
+ /** The port number of the primary location. */
+ this._primaryPort = -1;
+
+ /**
+* The current port number for the corresponding server, stored so that a new
+* primary location can always be set if the current one is removed.
+*/
+ this._defaultPort = -1;
+
+ /**
+* Maps hosts to maps of ports to schemes, e.g. the following would represent
+* https://example.com:789/ and http://example.org/:
+*
+* {
+* "xexample.com": { 789: "https" },
+* "xexample.org": { 80: "http" }
+* }
+*
+* Note the "x" prefix on hostnames, which prevents collisions with special
+* JS names like "prototype".
+*/
+ this._locations = { "xlocalhost": {} };
+}
+ServerIdentity.prototype =
+{
+ // NSIHTTPSERVERIDENTITY
+
+ //
+ // see nsIHttpServerIdentity.primaryScheme
+ //
+ get primaryScheme()
+ {
+ if (this._primaryPort === -1)
+ throw Cr.NS_ERROR_NOT_INITIALIZED;
+ return this._primaryScheme;
+ },
+
+ //
+ // see nsIHttpServerIdentity.primaryHost
+ //
+ get primaryHost()
+ {
+ if (this._primaryPort === -1)
+ throw Cr.NS_ERROR_NOT_INITIALIZED;
+ return this._primaryHost;
+ },
+
+ //
+ // see nsIHttpServerIdentity.primaryPort
+ //
+ get primaryPort()
+ {
+ if (this._primaryPort === -1)
+ throw Cr.NS_ERROR_NOT_INITIALIZED;
+ return this._primaryPort;
+ },
+
+ //
+ // see nsIHttpServerIdentity.add
+ //
+ add: function(scheme, host, port)
+ {
+ this._validate(scheme, host, port);
+
+ var entry = this._locations["x" + host];
+ if (!entry)
+ this._locations["x" + host] = entry = {};
+
+ entry[port] = scheme;
+ },
+
+ //
+ // see nsIHttpServerIdentity.remove
+ //
+ remove: function(scheme, host, port)
+ {
+ this._validate(scheme, host, port);
+
+ var entry = this._locations["x" + host];
+ if (!entry)
+ return false;
+
+ var present = port in entry;
+ delete entry[port];
+
+ if (this._primaryScheme == scheme &&
+ this._primaryHost == host &&
+ this._primaryPort == port &&
+ this._defaultPort !== -1)
+ {
+ // Always keep at least one identity in existence at any time, unless
+ // we're in the process of shutting down (the last condition above).
+ this._primaryPort = -1;
+ this._initialize(this._defaultPort, host, false);
+ }
+
+ return present;
+ },
+
+ //
+ // see nsIHttpServerIdentity.has
+ //
+ has: function(scheme, host, port)
+ {
+ this._validate(scheme, host, port);
+
+ return "x" + host in this._locations &&
+ scheme === this._locations["x" + host][port];
+ },
+
+ //
+ // see nsIHttpServerIdentity.has
+ //
+ getScheme: function(host, port)
+ {
+ this._validate("http", host, port);
+
+ var entry = this._locations["x" + host];
+ if (!entry)
+ return "";
+
+ return entry[port] || "";
+ },
+
+ //
+ // see nsIHttpServerIdentity.setPrimary
+ //
+ setPrimary: function(scheme, host, port)
+ {
+ this._validate(scheme, host, port);
+
+ this.add(scheme, host, port);
+
+ this._primaryScheme = scheme;
+ this._primaryHost = host;
+ this._primaryPort = port;
+ },
+
+
+ // NSISUPPORTS
+
+ //
+ // see nsISupports.QueryInterface
+ //
+ QueryInterface: function(iid)
+ {
+ if (iid.equals(Ci.nsIHttpServerIdentity) || iid.equals(Ci.nsISupports))
+ return this;
+
+ throw Cr.NS_ERROR_NO_INTERFACE;
+ },
+
+
+ // PRIVATE IMPLEMENTATION
+
+ /**
+* Initializes the primary name for the corresponding server, based on the
+* provided port number.
+*/
+ _initialize: function(port, host, addSecondaryDefault)
+ {
+ this._host = host;
+ if (this._primaryPort !== -1)
+ this.add("http", host, port);
+ else
+ this.setPrimary("http", "localhost", port);
+ this._defaultPort = port;
+
+ // Only add this if we're being called at server startup
+ if (addSecondaryDefault && host != "127.0.0.1")
+ this.add("http", "127.0.0.1", port);
+ },
+
+ /**
+* Called at server shutdown time, unsets the primary location only if it was
+* the default-assigned location and removes the default location from the
+* set of locations used.
+*/
+ _teardown: function()
+ {
+ if (this._host != "127.0.0.1") {
+ // Not the default primary location, nothing special to do here
+ this.remove("http", "127.0.0.1", this._defaultPort);
+ }
+
+ // This is a *very* tricky bit of reasoning here; make absolutely sure the
+ // tests for this code pass before you commit changes to it.
+ if (this._primaryScheme == "http" &&
+ this._primaryHost == this._host &&
+ this._primaryPort == this._defaultPort)
+ {
+ // Make sure we don't trigger the readding logic in .remove(), then remove
+ // the default location.
+ var port = this._defaultPort;
+ this._defaultPort = -1;
+ this.remove("http", this._host, port);
+
+ // Ensure a server start triggers the setPrimary() path in ._initialize()
+ this._primaryPort = -1;
+ }
+ else
+ {
+ // No reason not to remove directly as it's not our primary location
+ this.remove("http", this._host, this._defaultPort);
+ }
+ },
+
+ /**
+* Ensures scheme, host, and port are all valid with respect to RFC 2396.
+*
+* @throws NS_ERROR_ILLEGAL_VALUE
+* if any argument doesn't match the corresponding production
+*/
+ _validate: function(scheme, host, port)
+ {
+ if (scheme !== "http" && scheme !== "https")
+ {
+ dumpn("*** server only supports http/https schemes: '" + scheme + "'");
+ dumpStack();
+ throw Cr.NS_ERROR_ILLEGAL_VALUE;
+ }
+ if (!HOST_REGEX.test(host))
+ {
+ dumpn("*** unexpected host: '" + host + "'");
+ throw Cr.NS_ERROR_ILLEGAL_VALUE;
+ }
+ if (port < 0 || port > 65535)
+ {
+ dumpn("*** unexpected port: '" + port + "'");
+ throw Cr.NS_ERROR_ILLEGAL_VALUE;
+ }
+ }
+};
+
+
+/**
+* Represents a connection to the server (and possibly in the future the thread
+* on which the connection is processed).
+*
+* @param input : nsIInputStream
+* stream from which incoming data on the connection is read
+* @param output : nsIOutputStream
+* stream to write data out the connection
+* @param server : nsHttpServer
+* the server handling the connection
+* @param port : int
+* the port on which the server is running
+* @param outgoingPort : int
+* the outgoing port used by this connection
+* @param number : uint
+* a serial number used to uniquely identify this connection
+*/
+function Connection(input, output, server, port, outgoingPort, number)
+{
+ dumpn("*** opening new connection " + number + " on port " + outgoingPort);
+
+ /** Stream of incoming data. */
+ this.input = input;
+
+ /** Stream for outgoing data. */
+ this.output = output;
+
+ /** The server associated with this request. */
+ this.server = server;
+
+ /** The port on which the server is running. */
+ this.port = port;
+
+ /** The outgoing poort used by this connection. */
+ this._outgoingPort = outgoingPort;
+
+ /** The serial number of this connection. */
+ this.number = number;
+
+ /**
+* The request for which a response is being generated, null if the
+* incoming request has not been fully received or if it had errors.
+*/
+ this.request = null;
+
+ /** State variables for debugging. */
+ this._closed = this._processed = false;
+}
+Connection.prototype =
+{
+ /** Closes this connection's input/output streams. */
+ close: function()
+ {
+ dumpn("*** closing connection " + this.number +
+ " on port " + this._outgoingPort);
+
+ this.input.close();
+ this.output.close();
+ this._closed = true;
+
+ var server = this.server;
+ server._connectionClosed(this);
+
+ // If an error triggered a server shutdown, act on it now
+ if (server._doQuit)
+ server.stop(function() { /* not like we can do anything better */ });
+ },
+
+ /**
+* Initiates processing of this connection, using the data in the given
+* request.
+*
+* @param request : Request
+* the request which should be processed
+*/
+ process: function(request)
+ {
+ NS_ASSERT(!this._closed && !this._processed);
+
+ this._processed = true;
+
+ this.request = request;
+ this.server._handler.handleResponse(this);
+ },
+
+ /**
+* Initiates processing of this connection, generating a response with the
+* given HTTP error code.
+*
+* @param code : uint
+* an HTTP code, so in the range [0, 1000)
+* @param request : Request
+* incomplete data about the incoming request (since there were errors
+* during its processing
+*/
+ processError: function(code, request)
+ {
+ NS_ASSERT(!this._closed && !this._processed);
+
+ this._processed = true;
+ this.request = request;
+ this.server._handler.handleError(code, this);
+ },
+
+ /** Converts this to a string for debugging purposes. */
+ toString: function()
+ {
+ return "<Connection(" + this.number +
+ (this.request ? ", " + this.request.path : "") +"): " +
+ (this._closed ? "closed" : "open") + ">";
+ }
+};
+
+
+
+/** Returns an array of count bytes from the given input stream. */
+function readBytes(inputStream, count)
+{
+ return new BinaryInputStream(inputStream).readByteArray(count);
+}
+
+
+
+/** Request reader processing states; see RequestReader for details. */
+const READER_IN_REQUEST_LINE = 0;
+const READER_IN_HEADERS = 1;
+const READER_IN_BODY = 2;
+const READER_FINISHED = 3;
+
+
+/**
+* Reads incoming request data asynchronously, does any necessary preprocessing,
+* and forwards it to the request handler. Processing occurs in three states:
+*
+* READER_IN_REQUEST_LINE Reading the request's status line
+* READER_IN_HEADERS Reading headers in the request
+* READER_IN_BODY Reading the body of the request
+* READER_FINISHED Entire request has been read and processed
+*
+* During the first two stages, initial metadata about the request is gathered
+* into a Request object. Once the status line and headers have been processed,
+* we start processing the body of the request into the Request. Finally, when
+* the entire body has been read, we create a Response and hand it off to the
+* ServerHandler to be given to the appropriate request handler.
+*
+* @param connection : Connection
+* the connection for the request being read
+*/
+function RequestReader(connection)
+{
+ /** Connection metadata for this request. */
+ this._connection = connection;
+
+ /**
+* A container providing line-by-line access to the raw bytes that make up the
+* data which has been read from the connection but has not yet been acted
+* upon (by passing it to the request handler or by extracting request
+* metadata from it).
+*/
+ this._data = new LineData();
+
+ /**
+* The amount of data remaining to be read from the body of this request.
+* After all headers in the request have been read this is the value in the
+* Content-Length header, but as the body is read its value decreases to zero.
+*/
+ this._contentLength = 0;
+
+ /** The current state of parsing the incoming request. */
+ this._state = READER_IN_REQUEST_LINE;
+
+ /** Metadata constructed from the incoming request for the request handler. */
+ this._metadata = new Request(connection.port);
+
+ /**
+* Used to preserve state if we run out of line data midway through a
+* multi-line header. _lastHeaderName stores the name of the header, while
+* _lastHeaderValue stores the value we've seen so far for the header.
+*
+* These fields are always either both undefined or both strings.
+*/
+ this._lastHeaderName = this._lastHeaderValue = undefined;
+}
+RequestReader.prototype =
+{
+ // NSIINPUTSTREAMCALLBACK
+
+ /**
+* Called when more data from the incoming request is available. This method
+* then reads the available data from input and deals with that data as
+* necessary, depending upon the syntax of already-downloaded data.
+*
+* @param input : nsIAsyncInputStream
+* the stream of incoming data from the connection
+*/
+ onInputStreamReady: function(input)
+ {
+ dumpn("*** onInputStreamReady(input=" + input + ") on thread " +
+ gThreadManager.currentThread + " (main is " +
+ gThreadManager.mainThread + ")");
+ dumpn("*** this._state == " + this._state);
+
+ // Handle cases where we get more data after a request error has been
+ // discovered but *before* we can close the connection.
+ var data = this._data;
+ if (!data)
+ return;
+
+ try
+ {
+ data.appendBytes(readBytes(input, input.available()));
+ }
+ catch (e)
+ {
+ if (streamClosed(e))
+ {
+ dumpn("*** WARNING: unexpected error when reading from socket; will " +
+ "be treated as if the input stream had been closed");
+ dumpn("*** WARNING: actual error was: " + e);
+ }
+
+ // We've lost a race -- input has been closed, but we're still expecting
+ // to read more data. available() will throw in this case, and since
+ // we're dead in the water now, destroy the connection.
+ dumpn("*** onInputStreamReady called on a closed input, destroying " +
+ "connection");
+ this._connection.close();
+ return;
+ }
+
+ switch (this._state)
+ {
+ default:
+ NS_ASSERT(false, "invalid state: " + this._state);
+ break;
+
+ case READER_IN_REQUEST_LINE:
+ if (!this._processRequestLine())
+ break;
+ /* fall through */
+
+ case READER_IN_HEADERS:
+ if (!this._processHeaders())
+ break;
+ /* fall through */
+
+ case READER_IN_BODY:
+ this._processBody();
+ }
+
+ if (this._state != READER_FINISHED)
+ input.asyncWait(this, 0, 0, gThreadManager.currentThread);
+ },
+
+ //
+ // see nsISupports.QueryInterface
+ //
+ QueryInterface: function(aIID)
+ {
+ if (aIID.equals(Ci.nsIInputStreamCallback) ||
+ aIID.equals(Ci.nsISupports))
+ return this;
+
+ throw Cr.NS_ERROR_NO_INTERFACE;
+ },
+
+
+ // PRIVATE API
+
+ /**
+* Processes unprocessed, downloaded data as a request line.
+*
+* @returns boolean
+* true iff the request line has been fully processed
+*/
+ _processRequestLine: function()
+ {
+ NS_ASSERT(this._state == READER_IN_REQUEST_LINE);
+
+ // Servers SHOULD ignore any empty line(s) received where a Request-Line
+ // is expected (section 4.1).
+ var data = this._data;
+ var line = {};
+ var readSuccess;
+ while ((readSuccess = data.readLine(line)) && line.value == "")
+ dumpn("*** ignoring beginning blank line...");
+
+ // if we don't have a full line, wait until we do
+ if (!readSuccess)
+ return false;
+
+ // we have the first non-blank line
+ try
+ {
+ this._parseRequestLine(line.value);
+ this._state = READER_IN_HEADERS;
+ return true;
+ }
+ catch (e)
+ {
+ this._handleError(e);
+ return false;
+ }
+ },
+
+ /**
+* Processes stored data, assuming it is either at the beginning or in
+* the middle of processing request headers.
+*
+* @returns boolean
+* true iff header data in the request has been fully processed
+*/
+ _processHeaders: function()
+ {
+ NS_ASSERT(this._state == READER_IN_HEADERS);
+
+ // XXX things to fix here:
+ //
+ // - need to support RFC 2047-encoded non-US-ASCII characters
+
+ try
+ {
+ var done = this._parseHeaders();
+ if (done)
+ {
+ var request = this._metadata;
+
+ // XXX this is wrong for requests with transfer-encodings applied to
+ // them, particularly chunked (which by its nature can have no
+ // meaningful Content-Length header)!
+ this._contentLength = request.hasHeader("Content-Length")
+ ? parseInt(request.getHeader("Content-Length"), 10)
+ : 0;
+ dumpn("_processHeaders, Content-length=" + this._contentLength);
+
+ this._state = READER_IN_BODY;
+ }
+ return done;
+ }
+ catch (e)
+ {
+ this._handleError(e);
+ return false;
+ }
+ },
+
+ /**
+* Processes stored data, assuming it is either at the beginning or in
+* the middle of processing the request body.
+*
+* @returns boolean
+* true iff the request body has been fully processed
+*/
+ _processBody: function()
+ {
+ NS_ASSERT(this._state == READER_IN_BODY);
+
+ // XXX handle chunked transfer-coding request bodies!
+
+ try
+ {
+ if (this._contentLength > 0)
+ {
+ var data = this._data.purge();
+ var count = Math.min(data.length, this._contentLength);
+ dumpn("*** loading data=" + data + " len=" + data.length +
+ " excess=" + (data.length - count));
+
+ var bos = new BinaryOutputStream(this._metadata._bodyOutputStream);
+ bos.writeByteArray(data, count);
+ this._contentLength -= count;
+ }
+
+ dumpn("*** remaining body data len=" + this._contentLength);
+ if (this._contentLength == 0)
+ {
+ this._validateRequest();
+ this._state = READER_FINISHED;
+ this._handleResponse();
+ return true;
+ }
+
+ return false;
+ }
+ catch (e)
+ {
+ this._handleError(e);
+ return false;
+ }
+ },
+
+ /**
+* Does various post-header checks on the data in this request.
+*
+* @throws : HttpError
+* if the request was malformed in some way
+*/
+ _validateRequest: function()
+ {
+ NS_ASSERT(this._state == READER_IN_BODY);
+
+ dumpn("*** _validateRequest");
+
+ var metadata = this._metadata;
+ var headers = metadata._headers;
+
+ // 19.6.1.1 -- servers MUST report 400 to HTTP/1.1 requests w/o Host header
+ var identity = this._connection.server.identity;
+ if (metadata._httpVersion.atLeast(nsHttpVersion.HTTP_1_1))
+ {
+ if (!headers.hasHeader("Host"))
+ {
+ dumpn("*** malformed HTTP/1.1 or greater request with no Host header!");
+ throw HTTP_400;
+ }
+
+ // If the Request-URI wasn't absolute, then we need to determine our host.
+ // We have to determine what scheme was used to access us based on the
+ // server identity data at this point, because the request just doesn't
+ // contain enough data on its own to do this, sadly.
+ if (!metadata._host)
+ {
+ var host, port;
+ var hostPort = headers.getHeader("Host");
+ var colon = hostPort.indexOf(":");
+ if (colon < 0)
+ {
+ host = hostPort;
+ port = "";
+ }
+ else
+ {
+ host = hostPort.substring(0, colon);
+ port = hostPort.substring(colon + 1);
+ }
+
+ // NB: We allow an empty port here because, oddly, a colon may be
+ // present even without a port number, e.g. "example.com:"; in this
+ // case the default port applies.
+ if (!HOST_REGEX.test(host) || !/^\d*$/.test(port))
+ {
+ dumpn("*** malformed hostname (" + hostPort + ") in Host " +
+ "header, 400 time");
+ throw HTTP_400;
+ }
+
+ // If we're not given a port, we're stuck, because we don't know what
+ // scheme to use to look up the correct port here, in general. Since
+ // the HTTPS case requires a tunnel/proxy and thus requires that the
+ // requested URI be absolute (and thus contain the necessary
+ // information), let's assume HTTP will prevail and use that.
+ port = +port || 80;
+
+ var scheme = identity.getScheme(host, port);
+ if (!scheme)
+ {
+ dumpn("*** unrecognized hostname (" + hostPort + ") in Host " +
+ "header, 400 time");
+ throw HTTP_400;
+ }
+
+ metadata._scheme = scheme;
+ metadata._host = host;
+ metadata._port = port;
+ }
+ }
+ else
+ {
+ NS_ASSERT(metadata._host === undefined,
+ "HTTP/1.0 doesn't allow absolute paths in the request line!");
+
+ metadata._scheme = identity.primaryScheme;
+ metadata._host = identity.primaryHost;
+ metadata._port = identity.primaryPort;
+ }
+
+ NS_ASSERT(identity.has(metadata._scheme, metadata._host, metadata._port),
+ "must have a location we recognize by now!");
+ },
+
+ /**
+* Handles responses in case of error, either in the server or in the request.
+*
+* @param e
+* the specific error encountered, which is an HttpError in the case where
+* the request is in some way invalid or cannot be fulfilled; if this isn't
+* an HttpError we're going to be paranoid and shut down, because that
+* shouldn't happen, ever
+*/
+ _handleError: function(e)
+ {
+ // Don't fall back into normal processing!
+ this._state = READER_FINISHED;
+
+ var server = this._connection.server;
+ if (e instanceof HttpError)
+ {
+ var code = e.code;
+ }
+ else
+ {
+ dumpn("!!! UNEXPECTED ERROR: " + e +
+ (e.lineNumber ? ", line " + e.lineNumber : ""));
+
+ // no idea what happened -- be paranoid and shut down
+ code = 500;
+ server._requestQuit();
+ }
+
+ // make attempted reuse of data an error
+ this._data = null;
+
+ this._connection.processError(code, this._metadata);
+ },
+
+ /**
+* Now that we've read the request line and headers, we can actually hand off
+* the request to be handled.
+*
+* This method is called once per request, after the request line and all
+* headers and the body, if any, have been received.
+*/
+ _handleResponse: function()
+ {
+ NS_ASSERT(this._state == READER_FINISHED);
+
+ // We don't need the line-based data any more, so make attempted reuse an
+ // error.
+ this._data = null;
+
+ this._connection.process(this._metadata);
+ },
+
+
+ // PARSING
+
+ /**
+* Parses the request line for the HTTP request associated with this.
+*
+* @param line : string
+* the request line
+*/
+ _parseRequestLine: function(line)
+ {
+ NS_ASSERT(this._state == READER_IN_REQUEST_LINE);
+
+ dumpn("*** _parseRequestLine('" + line + "')");
+
+ var metadata = this._metadata;
+
+ // clients and servers SHOULD accept any amount of SP or HT characters
+ // between fields, even though only a single SP is required (section 19.3)
+ var request = line.split(/[ \t]+/);
+ if (!request || request.length != 3)
+ throw HTTP_400;
+
+ metadata._method = request[0];
+
+ // get the HTTP version
+ var ver = request[2];
+ var match = ver.match(/^HTTP\/(\d+\.\d+)$/);
+ if (!match)
+ throw HTTP_400;
+
+ // determine HTTP version
+ try
+ {
+ metadata._httpVersion = new nsHttpVersion(match[1]);
+ if (!metadata._httpVersion.atLeast(nsHttpVersion.HTTP_1_0))
+ throw "unsupported HTTP version";
+ }
+ catch (e)
+ {
+ // we support HTTP/1.0 and HTTP/1.1 only
+ throw HTTP_501;
+ }
+
+
+ var fullPath = request[1];
+ var serverIdentity = this._connection.server.identity;
+
+ var scheme, host, port;
+
+ if (fullPath.charAt(0) != "/")
+ {
+ // No absolute paths in the request line in HTTP prior to 1.1
+ if (!metadata._httpVersion.atLeast(nsHttpVersion.HTTP_1_1))
+ throw HTTP_400;
+
+ try
+ {
+ var uri = Cc["@mozilla.org/network/io-service;1"]
+ .getService(Ci.nsIIOService)
+ .newURI(fullPath, null, null);
+ fullPath = uri.path;
+ scheme = uri.scheme;
+ host = metadata._host = uri.asciiHost;
+ port = uri.port;
+ if (port === -1)
+ {
+ if (scheme === "http")
+ port = 80;
+ else if (scheme === "https")
+ port = 443;
+ else
+ throw HTTP_400;
+ }
+ }
+ catch (e)
+ {
+ // If the host is not a valid host on the server, the response MUST be a
+ // 400 (Bad Request) error message (section 5.2). Alternately, the URI
+ // is malformed.
+ throw HTTP_400;
+ }
+
+ if (!serverIdentity.has(scheme, host, port) || fullPath.charAt(0) != "/")
+ throw HTTP_400;
+ }
+
+ var splitter = fullPath.indexOf("?");
+ if (splitter < 0)
+ {
+ // _queryString already set in ctor
+ metadata._path = fullPath;
+ }
+ else
+ {
+ metadata._path = fullPath.substring(0, splitter);
+ metadata._queryString = fullPath.substring(splitter + 1);
+ }
+
+ metadata._scheme = scheme;
+ metadata._host = host;
+ metadata._port = port;
+ },
+
+ /**
+* Parses all available HTTP headers in this until the header-ending CRLFCRLF,
+* adding them to the store of headers in the request.
+*
+* @throws
+* HTTP_400 if the headers are malformed
+* @returns boolean
+* true if all headers have now been processed, false otherwise
+*/
+ _parseHeaders: function()
+ {
+ NS_ASSERT(this._state == READER_IN_HEADERS);
+
+ dumpn("*** _parseHeaders");
+
+ var data = this._data;
+
+ var headers = this._metadata._headers;
+ var lastName = this._lastHeaderName;
+ var lastVal = this._lastHeaderValue;
+
+ var line = {};
+ while (true)
+ {
+ NS_ASSERT(!((lastVal === undefined) ^ (lastName === undefined)),
+ lastName === undefined ?
+ "lastVal without lastName? lastVal: '" + lastVal + "'" :
+ "lastName without lastVal? lastName: '" + lastName + "'");
+
+ if (!data.readLine(line))
+ {
+ // save any data we have from the header we might still be processing
+ this._lastHeaderName = lastName;
+ this._lastHeaderValue = lastVal;
+ return false;
+ }
+
+ var lineText = line.value;
+ var firstChar = lineText.charAt(0);
+
+ // blank line means end of headers
+ if (lineText == "")
+ {
+ // we're finished with the previous header
+ if (lastName)
+ {
+ try
+ {
+ headers.setHeader(lastName, lastVal, true);
+ }
+ catch (e)
+ {
+ dumpn("*** e == " + e);
+ throw HTTP_400;
+ }
+ }
+ else
+ {
+ // no headers in request -- valid for HTTP/1.0 requests
+ }
+
+ // either way, we're done processing headers
+ this._state = READER_IN_BODY;
+ return true;
+ }
+ else if (firstChar == " " || firstChar == "\t")
+ {
+ // multi-line header if we've already seen a header line
+ if (!lastName)
+ {
+ // we don't have a header to continue!
+ throw HTTP_400;
+ }
+
+ // append this line's text to the value; starts with SP/HT, so no need
+ // for separating whitespace
+ lastVal += lineText;
+ }
+ else
+ {
+ // we have a new header, so set the old one (if one existed)
+ if (lastName)
+ {
+ try
+ {
+ headers.setHeader(lastName, lastVal, true);
+ }
+ catch (e)
+ {
+ dumpn("*** e == " + e);
+ throw HTTP_400;
+ }
+ }
+
+ var colon = lineText.indexOf(":"); // first colon must be splitter
+ if (colon < 1)
+ {
+ // no colon or missing header field-name
+ throw HTTP_400;
+ }
+
+ // set header name, value (to be set in the next loop, usually)
+ lastName = lineText.substring(0, colon);
+ lastVal = lineText.substring(colon + 1);
+ } // empty, continuation, start of header
+ } // while (true)
+ }
+};
+
+
+/** The character codes for CR and LF. */
+const CR = 0x0D, LF = 0x0A;
+
+/**
+* Calculates the number of characters before the first CRLF pair in array, or
+* -1 if the array contains no CRLF pair.
+*
+* @param array : Array
+* an array of numbers in the range [0, 256), each representing a single
+* character; the first CRLF is the lowest index i where
+* |array[i] == "\r".charCodeAt(0)| and |array[i+1] == "\n".charCodeAt(0)|,
+* if such an |i| exists, and -1 otherwise
+* @returns int
+* the index of the first CRLF if any were present, -1 otherwise
+*/
+function findCRLF(array)
+{
+ for (var i = array.indexOf(CR); i >= 0; i = array.indexOf(CR, i + 1))
+ {
+ if (array[i + 1] == LF)
+ return i;
+ }
+ return -1;
+}
+
+
+/**
+* A container which provides line-by-line access to the arrays of bytes with
+* which it is seeded.
+*/
+function LineData()
+{
+ /** An array of queued bytes from which to get line-based characters. */
+ this._data = [];
+}
+LineData.prototype =
+{
+ /**
+* Appends the bytes in the given array to the internal data cache maintained
+* by this.
+*/
+ appendBytes: function(bytes)
+ {
+ Array.prototype.push.apply(this._data, bytes);
+ },
+
+ /**
+* Removes and returns a line of data, delimited by CRLF, from this.
+*
+* @param out
+* an object whose "value" property will be set to the first line of text
+* present in this, sans CRLF, if this contains a full CRLF-delimited line
+* of text; if this doesn't contain enough data, the value of the property
+* is undefined
+* @returns boolean
+* true if a full line of data could be read from the data in this, false
+* otherwise
+*/
+ readLine: function(out)
+ {
+ var data = this._data;
+ var length = findCRLF(data);
+ if (length < 0)
+ return false;
+
+ //
+ // We have the index of the CR, so remove all the characters, including
+ // CRLF, from the array with splice, and convert the removed array into the
+ // corresponding string, from which we then strip the trailing CRLF.
+ //
+ // Getting the line in this matter acknowledges that substring is an O(1)
+ // operation in SpiderMonkey because strings are immutable, whereas two
+ // splices, both from the beginning of the data, are less likely to be as
+ // cheap as a single splice plus two extra character conversions.
+ //
+ var line = String.fromCharCode.apply(null, data.splice(0, length + 2));
+ out.value = line.substring(0, length);
+
+ return true;
+ },
+
+ /**
+* Removes the bytes currently within this and returns them in an array.
+*
+* @returns Array
+* the bytes within this when this method is called
+*/
+ purge: function()
+ {
+ var data = this._data;
+ this._data = [];
+ return data;
+ }
+};
+
+
+
+/**
+* Creates a request-handling function for an nsIHttpRequestHandler object.
+*/
+function createHandlerFunc(handler)
+{
+ return function(metadata, response) { handler.handle(metadata, response); };
+}
+
+
+/**
+* The default handler for directories; writes an HTML response containing a
+* slightly-formatted directory listing.
+*/
+function defaultIndexHandler(metadata, response)
+{
+ response.setHeader("Content-Type", "text/html", false);
+
+ var path = htmlEscape(decodeURI(metadata.path));
+
+ //
+ // Just do a very basic bit of directory listings -- no need for too much
+ // fanciness, especially since we don't have a style sheet in which we can
+ // stick rules (don't want to pollute the default path-space).
+ //
+
+ var body = '<html>\
+<head>\
+<title>' + path + '</title>\
+</head>\
+<body>\
+<h1>' + path + '</h1>\
+<ol style="list-style-type: none">';
+
+ var directory = metadata.getProperty("directory").QueryInterface(Ci.nsILocalFile);
+ NS_ASSERT(directory && directory.isDirectory());
+
+ var fileList = [];
+ var files = directory.directoryEntries;
+ while (files.hasMoreElements())
+ {
+ var f = files.getNext().QueryInterface(Ci.nsIFile);
+ var name = f.leafName;
+ if (!f.isHidden() &&
+ (name.charAt(name.length - 1) != HIDDEN_CHAR ||
+ name.charAt(name.length - 2) == HIDDEN_CHAR))
+ fileList.push(f);
+ }
+
+ fileList.sort(fileSort);
+
+ for (var i = 0; i < fileList.length; i++)
+ {
+ var file = fileList[i];
+ try
+ {
+ var name = file.leafName;
+ if (name.charAt(name.length - 1) == HIDDEN_CHAR)
+ name = name.substring(0, name.length - 1);
+ var sep = file.isDirectory() ? "/" : "";
+
+ // Note: using " to delimit the attribute here because encodeURIComponent
+ // passes through '.
+ var item = '<li><a href="' + encodeURIComponent(name) + sep + '">' +
+ htmlEscape(name) + sep +
+ '</a></li>';
+
+ body += item;
+ }
+ catch (e) { /* some file system error, ignore the file */ }
+ }
+
+ body += ' </ol>\
+</body>\
+</html>';
+
+ response.bodyOutputStream.write(body, body.length);
+}
+
+/**
+* Sorts a and b (nsIFile objects) into an aesthetically pleasing order.
+*/
+function fileSort(a, b)
+{
+ var dira = a.isDirectory(), dirb = b.isDirectory();
+
+ if (dira && !dirb)
+ return -1;
+ if (dirb && !dira)
+ return 1;
+
+ var namea = a.leafName.toLowerCase(), nameb = b.leafName.toLowerCase();
+ return nameb > namea ? -1 : 1;
+}
+
+
+/**
+* Converts an externally-provided path into an internal path for use in
+* determining file mappings.
+*
+* @param path
+* the path to convert
+* @param encoded
+* true if the given path should be passed through decodeURI prior to
+* conversion
+* @throws URIError
+* if path is incorrectly encoded
+*/
+function toInternalPath(path, encoded)
+{
+ if (encoded)
+ path = decodeURI(path);
+
+ var comps = path.split("/");
+ for (var i = 0, sz = comps.length; i < sz; i++)
+ {
+ var comp = comps[i];
+ if (comp.charAt(comp.length - 1) == HIDDEN_CHAR)
+ comps[i] = comp + HIDDEN_CHAR;
+ }
+ return comps.join("/");
+}
+
+
+/**
+* Adds custom-specified headers for the given file to the given response, if
+* any such headers are specified.
+*
+* @param file
+* the file on the disk which is to be written
+* @param metadata
+* metadata about the incoming request
+* @param response
+* the Response to which any specified headers/data should be written
+* @throws HTTP_500
+* if an error occurred while processing custom-specified headers
+*/
+function maybeAddHeaders(file, metadata, response)
+{
+ var name = file.leafName;
+ if (name.charAt(name.length - 1) == HIDDEN_CHAR)
+ name = name.substring(0, name.length - 1);
+
+ var headerFile = file.parent;
+ headerFile.append(name + HEADERS_SUFFIX);
+
+ if (!headerFile.exists())
+ return;
+
+ const PR_RDONLY = 0x01;
+ var fis = new FileInputStream(headerFile, PR_RDONLY, parseInt("444", 8),
+ Ci.nsIFileInputStream.CLOSE_ON_EOF);
+
+ try
+ {
+ var lis = new ConverterInputStream(fis, "UTF-8", 1024, 0x0);
+ lis.QueryInterface(Ci.nsIUnicharLineInputStream);
+
+ var line = {value: ""};
+ var more = lis.readLine(line);
+
+ if (!more && line.value == "")
+ return;
+
+
+ // request line
+
+ var status = line.value;
+ if (status.indexOf("HTTP ") == 0)
+ {
+ status = status.substring(5);
+ var space = status.indexOf(" ");
+ var code, description;
+ if (space < 0)
+ {
+ code = status;
+ description = "";
+ }
+ else
+ {
+ code = status.substring(0, space);
+ description = status.substring(space + 1, status.length);
+ }
+
+ response.setStatusLine(metadata.httpVersion, parseInt(code, 10), description);
+
+ line.value = "";
+ more = lis.readLine(line);
+ }
+
+ // headers
+ while (more || line.value != "")
+ {
+ var header = line.value;
+ var colon = header.indexOf(":");
+
+ response.setHeader(header.substring(0, colon),
+ header.substring(colon + 1, header.length),
+ false); // allow overriding server-set headers
+
+ line.value = "";
+ more = lis.readLine(line);
+ }
+ }
+ catch (e)
+ {
+ dumpn("WARNING: error in headers for " + metadata.path + ": " + e);
+ throw HTTP_500;
+ }
+ finally
+ {
+ fis.close();
+ }
+}
+
+
+/**
+* An object which handles requests for a server, executing default and
+* overridden behaviors as instructed by the code which uses and manipulates it.
+* Default behavior includes the paths / and /trace (diagnostics), with some
+* support for HTTP error pages for various codes and fallback to HTTP 500 if
+* those codes fail for any reason.
+*
+* @param server : nsHttpServer
+* the server in which this handler is being used
+*/
+function ServerHandler(server)
+{
+ // FIELDS
+
+ /**
+* The nsHttpServer instance associated with this handler.
+*/
+ this._server = server;
+
+ /**
+* A FileMap object containing the set of path->nsILocalFile mappings for
+* all directory mappings set in the server (e.g., "/" for /var/www/html/,
+* "/foo/bar/" for /local/path/, and "/foo/bar/baz/" for /local/path2).
+*
+* Note carefully: the leading and trailing "/" in each path (not file) are
+* removed before insertion to simplify the code which uses this. You have
+* been warned!
+*/
+ this._pathDirectoryMap = new FileMap();
+
+ /**
+* Custom request handlers for the server in which this resides. Path-handler
+* pairs are stored as property-value pairs in this property.
+*
+* @see ServerHandler.prototype._defaultPaths
+*/
+ this._overridePaths = {};
+
+ /**
+* Custom request handlers for the error handlers in the server in which this
+* resides. Path-handler pairs are stored as property-value pairs in this
+* property.
+*
+* @see ServerHandler.prototype._defaultErrors
+*/
+ this._overrideErrors = {};
+
+ /**
+* Maps file extensions to their MIME types in the server, overriding any
+* mapping that might or might not exist in the MIME service.
+*/
+ this._mimeMappings = {};
+
+ /**
+* The default handler for requests for directories, used to serve directories
+* when no index file is present.
+*/
+ this._indexHandler = defaultIndexHandler;
+
+ /** Per-path state storage for the server. */
+ this._state = {};
+
+ /** Entire-server state storage. */
+ this._sharedState = {};
+
+ /** Entire-server state storage for nsISupports values. */
+ this._objectState = {};
+}
+ServerHandler.prototype =
+{
+ // PUBLIC API
+
+ /**
+* Handles a request to this server, responding to the request appropriately
+* and initiating server shutdown if necessary.
+*
+* This method never throws an exception.
+*
+* @param connection : Connection
+* the connection for this request
+*/
+ handleResponse: function(connection)
+ {
+ var request = connection.request;
+ var response = new Response(connection);
+
+ var path = request.path;
+ dumpn("*** path == " + path);
+
+ try
+ {
+ try
+ {
+ if (path in this._overridePaths)
+ {
+ // explicit paths first, then files based on existing directory mappings,
+ // then (if the file doesn't exist) built-in server default paths
+ dumpn("calling override for " + path);
+ this._overridePaths[path](request, response);
+ }
+ else
+ {
+ this._handleDefault(request, response);
+ }
+ }
+ catch (e)
+ {
+ if (response.partiallySent())
+ {
+ response.abort(e);
+ return;
+ }
+
+ if (!(e instanceof HttpError))
+ {
+ dumpn("*** unexpected error: e == " + e);
+ throw HTTP_500;
+ }
+ if (e.code !== 404)
+ throw e;
+
+ dumpn("*** default: " + (path in this._defaultPaths));
+
+ response = new Response(connection);
+ if (path in this._defaultPaths)
+ this._defaultPaths[path](request, response);
+ else
+ throw HTTP_404;
+ }
+ }
+ catch (e)
+ {
+ if (response.partiallySent())
+ {
+ response.abort(e);
+ return;
+ }
+
+ var errorCode = "internal";
+
+ try
+ {
+ if (!(e instanceof HttpError))
+ throw e;
+
+ errorCode = e.code;
+ dumpn("*** errorCode == " + errorCode);
+
+ response = new Response(connection);
+ if (e.customErrorHandling)
+ e.customErrorHandling(response);
+ this._handleError(errorCode, request, response);
+ return;
+ }
+ catch (e2)
+ {
+ dumpn("*** error handling " + errorCode + " error: " +
+ "e2 == " + e2 + ", shutting down server");
+
+ connection.server._requestQuit();
+ response.abort(e2);
+ return;
+ }
+ }
+
+ response.complete();
+ },
+
+ //
+ // see nsIHttpServer.registerFile
+ //
+ registerFile: function(path, file)
+ {
+ if (!file)
+ {
+ dumpn("*** unregistering '" + path + "' mapping");
+ delete this._overridePaths[path];
+ return;
+ }
+
+ dumpn("*** registering '" + path + "' as mapping to " + file.path);
+ file = file.clone();
+
+ var self = this;
+ this._overridePaths[path] =
+ function(request, response)
+ {
+ if (!file.exists())
+ throw HTTP_404;
+
+ response.setStatusLine(request.httpVersion, 200, "OK");
+ self._writeFileResponse(request, file, response, 0, file.fileSize);
+ };
+ },
+
+ //
+ // see nsIHttpServer.registerPathHandler
+ //
+ registerPathHandler: function(path, handler)
+ {
+ // XXX true path validation!
+ if (path.charAt(0) != "/")
+ throw Cr.NS_ERROR_INVALID_ARG;
+
+ this._handlerToField(handler, this._overridePaths, path);
+ },
+
+ //
+ // see nsIHttpServer.registerDirectory
+ //
+ registerDirectory: function(path, directory)
+ {
+ // strip off leading and trailing '/' so that we can use lastIndexOf when
+ // determining exactly how a path maps onto a mapped directory --
+ // conditional is required here to deal with "/".substring(1, 0) being
+ // converted to "/".substring(0, 1) per the JS specification
+ var key = path.length == 1 ? "" : path.substring(1, path.length - 1);
+
+ // the path-to-directory mapping code requires that the first character not
+ // be "/", or it will go into an infinite loop
+ if (key.charAt(0) == "/")
+ throw Cr.NS_ERROR_INVALID_ARG;
+
+ key = toInternalPath(key, false);
+
+ if (directory)
+ {
+ dumpn("*** mapping '" + path + "' to the location " + directory.path);
+ this._pathDirectoryMap.put(key, directory);
+ }
+ else
+ {
+ dumpn("*** removing mapping for '" + path + "'");
+ this._pathDirectoryMap.put(key, null);
+ }
+ },
+
+ //
+ // see nsIHttpServer.registerErrorHandler
+ //
+ registerErrorHandler: function(err, handler)
+ {
+ if (!(err in HTTP_ERROR_CODES))
+ dumpn("*** WARNING: registering non-HTTP/1.1 error code " +
+ "(" + err + ") handler -- was this intentional?");
+
+ this._handlerToField(handler, this._overrideErrors, err);
+ },
+
+ //
+ // see nsIHttpServer.setIndexHandler
+ //
+ setIndexHandler: function(handler)
+ {
+ if (!handler)
+ handler = defaultIndexHandler;
+ else if (typeof(handler) != "function")
+ handler = createHandlerFunc(handler);
+
+ this._indexHandler = handler;
+ },
+
+ //
+ // see nsIHttpServer.registerContentType
+ //
+ registerContentType: function(ext, type)
+ {
+ if (!type)
+ delete this._mimeMappings[ext];
+ else
+ this._mimeMappings[ext] = headerUtils.normalizeFieldValue(type);
+ },
+
+ // PRIVATE API
+
+ /**
+* Sets or remove (if handler is null) a handler in an object with a key.
+*
+* @param handler
+* a handler, either function or an nsIHttpRequestHandler
+* @param dict
+* The object to attach the handler to.
+* @param key
+* The field name of the handler.
+*/
+ _handlerToField: function(handler, dict, key)
+ {
+ // for convenience, handler can be a function if this is run from xpcshell
+ if (typeof(handler) == "function")
+ dict[key] = handler;
+ else if (handler)
+ dict[key] = createHandlerFunc(handler);
+ else
+ delete dict[key];
+ },
+
+ /**
+* Handles a request which maps to a file in the local filesystem (if a base
+* path has already been set; otherwise the 404 error is thrown).
+*
+* @param metadata : Request
+* metadata for the incoming request
+* @param response : Response
+* an uninitialized Response to the given request, to be initialized by a
+* request handler
+* @throws HTTP_###
+* if an HTTP error occurred (usually HTTP_404); note that in this case the
+* calling code must handle post-processing of the response
+*/
+ _handleDefault: function(metadata, response)
+ {
+ dumpn("*** _handleDefault()");
+
+ response.setStatusLine(metadata.httpVersion, 200, "OK");
+
+ var path = metadata.path;
+ NS_ASSERT(path.charAt(0) == "/", "invalid path: <" + path + ">");
+
+ // determine the actual on-disk file; this requires finding the deepest
+ // path-to-directory mapping in the requested URL
+ var file = this._getFileForPath(path);
+
+ // the "file" might be a directory, in which case we either serve the
+ // contained index.html or make the index handler write the response
+ if (file.exists() && file.isDirectory())
+ {
+ file.append("index.html"); // make configurable?
+ if (!file.exists() || file.isDirectory())
+ {
+ metadata._ensurePropertyBag();
+ metadata._bag.setPropertyAsInterface("directory", file.parent);
+ this._indexHandler(metadata, response);
+ return;
+ }
+ }
+
+ // alternately, the file might not exist
+ if (!file.exists())
+ throw HTTP_404;
+
+ var start, end;
+ if (metadata._httpVersion.atLeast(nsHttpVersion.HTTP_1_1) &&
+ metadata.hasHeader("Range") &&
+ this._getTypeFromFile(file) !== SJS_TYPE)
+ {
+ var rangeMatch = metadata.getHeader("Range").match(/^bytes=(\d+)?-(\d+)?$/);
+ if (!rangeMatch)
+ throw HTTP_400;
+
+ if (rangeMatch[1] !== undefined)
+ start = parseInt(rangeMatch[1], 10);
+
+ if (rangeMatch[2] !== undefined)
+ end = parseInt(rangeMatch[2], 10);
+
+ if (start === undefined && end === undefined)
+ throw HTTP_400;
+
+ // No start given, so the end is really the count of bytes from the
+ // end of the file.
+ if (start === undefined)
+ {
+ start = Math.max(0, file.fileSize - end);
+ end = file.fileSize - 1;
+ }
+
+ // start and end are inclusive
+ if (end === undefined || end >= file.fileSize)
+ end = file.fileSize - 1;
+
+ if (start !== undefined && start >= file.fileSize) {
+ var HTTP_416 = new HttpError(416, "Requested Range Not Satisfiable");
+ HTTP_416.customErrorHandling = function(errorResponse)
+ {
+ maybeAddHeaders(file, metadata, errorResponse);
+ };
+ throw HTTP_416;
+ }
+
+ if (end < start)
+ {
+ response.setStatusLine(metadata.httpVersion, 200, "OK");
+ start = 0;
+ end = file.fileSize - 1;
+ }
+ else
+ {
+ response.setStatusLine(metadata.httpVersion, 206, "Partial Content");
+ var contentRange = "bytes " + start + "-" + end + "/" + file.fileSize;
+ response.setHeader("Content-Range", contentRange);
+ }
+ }
+ else
+ {
+ start = 0;
+ end = file.fileSize - 1;
+ }
+
+ // finally...
+ dumpn("*** handling '" + path + "' as mapping to " + file.path + " from " +
+ start + " to " + end + " inclusive");
+ this._writeFileResponse(metadata, file, response, start, end - start + 1);
+ },
+
+ /**
+* Writes an HTTP response for the given file, including setting headers for
+* file metadata.
+*
+* @param metadata : Request
+* the Request for which a response is being generated
+* @param file : nsILocalFile
+* the file which is to be sent in the response
+* @param response : Response
+* the response to which the file should be written
+* @param offset: uint
+* the byte offset to skip to when writing
+* @param count: uint
+* the number of bytes to write
+*/
+ _writeFileResponse: function(metadata, file, response, offset, count)
+ {
+ const PR_RDONLY = 0x01;
+
+ var type = this._getTypeFromFile(file);
+ if (type === SJS_TYPE)
+ {
+ var fis = new FileInputStream(file, PR_RDONLY, parseInt("444", 8),
+ Ci.nsIFileInputStream.CLOSE_ON_EOF);
+
+ try
+ {
+ var sis = new ScriptableInputStream(fis);
+ var s = Cu.Sandbox(gGlobalObject);
+ s.importFunction(dump, "dump");
+
+ // Define a basic key-value state-preservation API across requests, with
+ // keys initially corresponding to the empty string.
+ var self = this;
+ var path = metadata.path;
+ s.importFunction(function getState(k)
+ {
+ return self._getState(path, k);
+ });
+ s.importFunction(function setState(k, v)
+ {
+ self._setState(path, k, v);
+ });
+ s.importFunction(function getSharedState(k)
+ {
+ return self._getSharedState(k);
+ });
+ s.importFunction(function setSharedState(k, v)
+ {
+ self._setSharedState(k, v);
+ });
+ s.importFunction(function getObjectState(k, callback)
+ {
+ callback(self._getObjectState(k));
+ });
+ s.importFunction(function setObjectState(k, v)
+ {
+ self._setObjectState(k, v);
+ });
+ s.importFunction(function registerPathHandler(p, h)
+ {
+ self.registerPathHandler(p, h);
+ });
+
+ // Make it possible for sjs files to access their location
+ this._setState(path, "__LOCATION__", file.path);
+
+ try
+ {
+ // Alas, the line number in errors dumped to console when calling the
+ // request handler is simply an offset from where we load the SJS file.
+ // Work around this in a reasonably non-fragile way by dynamically
+ // getting the line number where we evaluate the SJS file. Don't
+ // separate these two lines!
+ var line = new Error().lineNumber;
+ Cu.evalInSandbox(sis.read(file.fileSize), s);
+ }
+ catch (e)
+ {
+ dumpn("*** syntax error in SJS at " + file.path + ": " + e);
+ throw HTTP_500;
+ }
+
+ try
+ {
+ s.handleRequest(metadata, response);
+ }
+ catch (e)
+ {
+ dump("*** error running SJS at " + file.path + ": " +
+ e + " on line " +
+ (e instanceof Error
+ ? e.lineNumber + " in httpd.js"
+ : (e.lineNumber - line)) + "\n");
+ throw HTTP_500;
+ }
+ }
+ finally
+ {
+ fis.close();
+ }
+ }
+ else
+ {
+ try
+ {
+ response.setHeader("Last-Modified",
+ toDateString(file.lastModifiedTime),
+ false);
+ }
+ catch (e) { /* lastModifiedTime threw, ignore */ }
+
+ response.setHeader("Content-Type", type, false);
+ maybeAddHeaders(file, metadata, response);
+ response.setHeader("Content-Length", "" + count, false);
+
+ var fis = new FileInputStream(file, PR_RDONLY, parseInt("444", 8),
+ Ci.nsIFileInputStream.CLOSE_ON_EOF);
+
+ offset = offset || 0;
+ count = count || file.fileSize;
+ NS_ASSERT(offset === 0 || offset < file.fileSize, "bad offset");
+ NS_ASSERT(count >= 0, "bad count");
+ NS_ASSERT(offset + count <= file.fileSize, "bad total data size");
+
+ try
+ {
+ if (offset !== 0)
+ {
+ // Seek (or read, if seeking isn't supported) to the correct offset so
+ // the data sent to the client matches the requested range.
+ if (fis instanceof Ci.nsISeekableStream)
+ fis.seek(Ci.nsISeekableStream.NS_SEEK_SET, offset);
+ else
+ new ScriptableInputStream(fis).read(offset);
+ }
+ }
+ catch (e)
+ {
+ fis.close();
+ throw e;
+ }
+
+ function writeMore()
+ {
+ gThreadManager.currentThread
+ .dispatch(writeData, Ci.nsIThread.DISPATCH_NORMAL);
+ }
+
+ var input = new BinaryInputStream(fis);
+ var output = new BinaryOutputStream(response.bodyOutputStream);
+ var writeData =
+ {
+ run: function()
+ {
+ var chunkSize = Math.min(65536, count);
+ count -= chunkSize;
+ NS_ASSERT(count >= 0, "underflow");
+
+ try
+ {
+ var data = input.readByteArray(chunkSize);
+ NS_ASSERT(data.length === chunkSize,
+ "incorrect data returned? got " + data.length +
+ ", expected " + chunkSize);
+ output.writeByteArray(data, data.length);
+ if (count === 0)
+ {
+ fis.close();
+ response.finish();
+ }
+ else
+ {
+ writeMore();
+ }
+ }
+ catch (e)
+ {
+ try
+ {
+ fis.close();
+ }
+ finally
+ {
+ response.finish();
+ }
+ throw e;
+ }
+ }
+ };
+
+ writeMore();
+
+ // Now that we know copying will start, flag the response as async.
+ response.processAsync();
+ }
+ },
+
+ /**
+* Get the value corresponding to a given key for the given path for SJS state
+* preservation across requests.
+*
+* @param path : string
+* the path from which the given state is to be retrieved
+* @param k : string
+* the key whose corresponding value is to be returned
+* @returns string
+* the corresponding value, which is initially the empty string
+*/
+ _getState: function(path, k)
+ {
+ var state = this._state;
+ if (path in state && k in state[path])
+ return state[path][k];
+ return "";
+ },
+
+ /**
+* Set the value corresponding to a given key for the given path for SJS state
+* preservation across requests.
+*
+* @param path : string
+* the path from which the given state is to be retrieved
+* @param k : string
+* the key whose corresponding value is to be set
+* @param v : string
+* the value to be set
+*/
+ _setState: function(path, k, v)
+ {
+ if (typeof v !== "string")
+ throw new Error("non-string value passed");
+ var state = this._state;
+ if (!(path in state))
+ state[path] = {};
+ state[path][k] = v;
+ },
+
+ /**
+* Get the value corresponding to a given key for SJS state preservation
+* across requests.
+*
+* @param k : string
+* the key whose corresponding value is to be returned
+* @returns string
+* the corresponding value, which is initially the empty string
+*/
+ _getSharedState: function(k)
+ {
+ var state = this._sharedState;
+ if (k in state)
+ return state[k];
+ return "";
+ },
+
+ /**
+* Set the value corresponding to a given key for SJS state preservation
+* across requests.
+*
+* @param k : string
+* the key whose corresponding value is to be set
+* @param v : string
+* the value to be set
+*/
+ _setSharedState: function(k, v)
+ {
+ if (typeof v !== "string")
+ throw new Error("non-string value passed");
+ this._sharedState[k] = v;
+ },
+
+ /**
+* Returns the object associated with the given key in the server for SJS
+* state preservation across requests.
+*
+* @param k : string
+* the key whose corresponding object is to be returned
+* @returns nsISupports
+* the corresponding object, or null if none was present
+*/
+ _getObjectState: function(k)
+ {
+ if (typeof k !== "string")
+ throw new Error("non-string key passed");
+ return this._objectState[k] || null;
+ },
+
+ /**
+* Sets the object associated with the given key in the server for SJS
+* state preservation across requests.
+*
+* @param k : string
+* the key whose corresponding object is to be set
+* @param v : nsISupports
+* the object to be associated with the given key; may be null
+*/
+ _setObjectState: function(k, v)
+ {
+ if (typeof k !== "string")
+ throw new Error("non-string key passed");
+ if (typeof v !== "object")
+ throw new Error("non-object value passed");
+ if (v && !("QueryInterface" in v))
+ {
+ throw new Error("must pass an nsISupports; use wrappedJSObject to ease " +
+ "pain when using the server from JS");
+ }
+
+ this._objectState[k] = v;
+ },
+
+ /**
+* Gets a content-type for the given file, first by checking for any custom
+* MIME-types registered with this handler for the file's extension, second by
+* asking the global MIME service for a content-type, and finally by failing
+* over to application/octet-stream.
+*
+* @param file : nsIFile
+* the nsIFile for which to get a file type
+* @returns string
+* the best content-type which can be determined for the file
+*/
+ _getTypeFromFile: function(file)
+ {
+ try
+ {
+ var name = file.leafName;
+ var dot = name.lastIndexOf(".");
+ if (dot > 0)
+ {
+ var ext = name.slice(dot + 1);
+ if (ext in this._mimeMappings)
+ return this._mimeMappings[ext];
+ }
+ return Cc["@mozilla.org/uriloader/external-helper-app-service;1"]
+ .getService(Ci.nsIMIMEService)
+ .getTypeFromFile(file);
+ }
+ catch (e)
+ {
+ return "application/octet-stream";
+ }
+ },
+
+ /**
+* Returns the nsILocalFile which corresponds to the path, as determined using
+* all registered path->directory mappings and any paths which are explicitly
+* overridden.
+*
+* @param path : string
+* the server path for which a file should be retrieved, e.g. "/foo/bar"
+* @throws HttpError
+* when the correct action is the corresponding HTTP error (i.e., because no
+* mapping was found for a directory in path, the referenced file doesn't
+* exist, etc.)
+* @returns nsILocalFile
+* the file to be sent as the response to a request for the path
+*/
+ _getFileForPath: function(path)
+ {
+ // decode and add underscores as necessary
+ try
+ {
+ path = toInternalPath(path, true);
+ }
+ catch (e)
+ {
+ throw HTTP_400; // malformed path
+ }
+
+ // next, get the directory which contains this path
+ var pathMap = this._pathDirectoryMap;
+
+ // An example progression of tmp for a path "/foo/bar/baz/" might be:
+ // "foo/bar/baz/", "foo/bar/baz", "foo/bar", "foo", ""
+ var tmp = path.substring(1);
+ while (true)
+ {
+ // do we have a match for current head of the path?
+ var file = pathMap.get(tmp);
+ if (file)
+ {
+ // XXX hack; basically disable showing mapping for /foo/bar/ when the
+ // requested path was /foo/bar, because relative links on the page
+ // will all be incorrect -- we really need the ability to easily
+ // redirect here instead
+ if (tmp == path.substring(1) &&
+ tmp.length != 0 &&
+ tmp.charAt(tmp.length - 1) != "/")
+ file = null;
+ else
+ break;
+ }
+
+ // if we've finished trying all prefixes, exit
+ if (tmp == "")
+ break;
+
+ tmp = tmp.substring(0, tmp.lastIndexOf("/"));
+ }
+
+ // no mapping applies, so 404
+ if (!file)
+ throw HTTP_404;
+
+
+ // last, get the file for the path within the determined directory
+ var parentFolder = file.parent;
+ var dirIsRoot = (parentFolder == null);
+
+ // Strategy here is to append components individually, making sure we
+ // never move above the given directory; this allows paths such as
+ // "<file>/foo/../bar" but prevents paths such as "<file>/../base-sibling";
+ // this component-wise approach also means the code works even on platforms
+ // which don't use "/" as the directory separator, such as Windows
+ var leafPath = path.substring(tmp.length + 1);
+ var comps = leafPath.split("/");
+ for (var i = 0, sz = comps.length; i < sz; i++)
+ {
+ var comp = comps[i];
+
+ if (comp == "..")
+ file = file.parent;
+ else if (comp == "." || comp == "")
+ continue;
+ else
+ file.append(comp);
+
+ if (!dirIsRoot && file.equals(parentFolder))
+ throw HTTP_403;
+ }
+
+ return file;
+ },
+
+ /**
+* Writes the error page for the given HTTP error code over the given
+* connection.
+*
+* @param errorCode : uint
+* the HTTP error code to be used
+* @param connection : Connection
+* the connection on which the error occurred
+*/
+ handleError: function(errorCode, connection)
+ {
+ var response = new Response(connection);
+
+ dumpn("*** error in request: " + errorCode);
+
+ this._handleError(errorCode, new Request(connection.port), response);
+ },
+
+ /**
+* Handles a request which generates the given error code, using the
+* user-defined error handler if one has been set, gracefully falling back to
+* the x00 status code if the code has no handler, and failing to status code
+* 500 if all else fails.
+*
+* @param errorCode : uint
+* the HTTP error which is to be returned
+* @param metadata : Request
+* metadata for the request, which will often be incomplete since this is an
+* error
+* @param response : Response
+* an uninitialized Response should be initialized when this method
+* completes with information which represents the desired error code in the
+* ideal case or a fallback code in abnormal circumstances (i.e., 500 is a
+* fallback for 505, per HTTP specs)
+*/
+ _handleError: function(errorCode, metadata, response)
+ {
+ if (!metadata)
+ throw Cr.NS_ERROR_NULL_POINTER;
+
+ var errorX00 = errorCode - (errorCode % 100);
+
+ try
+ {
+ if (!(errorCode in HTTP_ERROR_CODES))
+ dumpn("*** WARNING: requested invalid error: " + errorCode);
+
+ // RFC 2616 says that we should try to handle an error by its class if we
+ // can't otherwise handle it -- if that fails, we revert to handling it as
+ // a 500 internal server error, and if that fails we throw and shut down
+ // the server
+
+ // actually handle the error
+ try
+ {
+ if (errorCode in this._overrideErrors)
+ this._overrideErrors[errorCode](metadata, response);
+ else
+ this._defaultErrors[errorCode](metadata, response);
+ }
+ catch (e)
+ {
+ if (response.partiallySent())
+ {
+ response.abort(e);
+ return;
+ }
+
+ // don't retry the handler that threw
+ if (errorX00 == errorCode)
+ throw HTTP_500;
+
+ dumpn("*** error in handling for error code " + errorCode + ", " +
+ "falling back to " + errorX00 + "...");
+ response = new Response(response._connection);
+ if (errorX00 in this._overrideErrors)
+ this._overrideErrors[errorX00](metadata, response);
+ else if (errorX00 in this._defaultErrors)
+ this._defaultErrors[errorX00](metadata, response);
+ else
+ throw HTTP_500;
+ }
+ }
+ catch (e)
+ {
+ if (response.partiallySent())
+ {
+ response.abort();
+ return;
+ }
+
+ // we've tried everything possible for a meaningful error -- now try 500
+ dumpn("*** error in handling for error code " + errorX00 + ", falling " +
+ "back to 500...");
+
+ try
+ {
+ response = new Response(response._connection);
+ if (500 in this._overrideErrors)
+ this._overrideErrors[500](metadata, response);
+ else
+ this._defaultErrors[500](metadata, response);
+ }
+ catch (e2)
+ {
+ dumpn("*** multiple errors in default error handlers!");
+ dumpn("*** e == " + e + ", e2 == " + e2);
+ response.abort(e2);
+ return;
+ }
+ }
+
+ response.complete();
+ },
+
+ // FIELDS
+
+ /**
+* This object contains the default handlers for the various HTTP error codes.
+*/
+ _defaultErrors:
+ {
+ 400: function(metadata, response)
+ {
+ // none of the data in metadata is reliable, so hard-code everything here
+ response.setStatusLine("1.1", 400, "Bad Request");
+ response.setHeader("Content-Type", "text/plain", false);
+
+ var body = "Bad request\n";
+ response.bodyOutputStream.write(body, body.length);
+ },
+ 403: function(metadata, response)
+ {
+ response.setStatusLine(metadata.httpVersion, 403, "Forbidden");
+ response.setHeader("Content-Type", "text/html", false);
+
+ var body = "<html>\
+<head><title>403 Forbidden</title></head>\
+<body>\
+<h1>403 Forbidden</h1>\
+</body>\
+</html>";
+ response.bodyOutputStream.write(body, body.length);
+ },
+ 404: function(metadata, response)
+ {
+ response.setStatusLine(metadata.httpVersion, 404, "Not Found");
+ response.setHeader("Content-Type", "text/html", false);
+
+ var body = "<html>\
+<head><title>404 Not Found</title></head>\
+<body>\
+<h1>404 Not Found</h1>\
+<p>\
+<span style='font-family: monospace;'>" +
+ htmlEscape(metadata.path) +
+ "</span> was not found.\
+</p>\
+</body>\
+</html>";
+ response.bodyOutputStream.write(body, body.length);
+ },
+ 416: function(metadata, response)
+ {
+ response.setStatusLine(metadata.httpVersion,
+ 416,
+ "Requested Range Not Satisfiable");
+ response.setHeader("Content-Type", "text/html", false);
+
+ var body = "<html>\
+<head>\
+<title>416 Requested Range Not Satisfiable</title></head>\
+<body>\
+<h1>416 Requested Range Not Satisfiable</h1>\
+<p>The byte range was not valid for the\
+requested resource.\
+</p>\
+</body>\
+</html>";
+ response.bodyOutputStream.write(body, body.length);
+ },
+ 500: function(metadata, response)
+ {
+ response.setStatusLine(metadata.httpVersion,
+ 500,
+ "Internal Server Error");
+ response.setHeader("Content-Type", "text/html", false);
+
+ var body = "<html>\
+<head><title>500 Internal Server Error</title></head>\
+<body>\
+<h1>500 Internal Server Error</h1>\
+<p>Something's broken in this server and\
+needs to be fixed.</p>\
+</body>\
+</html>";
+ response.bodyOutputStream.write(body, body.length);
+ },
+ 501: function(metadata, response)
+ {
+ response.setStatusLine(metadata.httpVersion, 501, "Not Implemented");
+ response.setHeader("Content-Type", "text/html", false);
+
+ var body = "<html>\
+<head><title>501 Not Implemented</title></head>\
+<body>\
+<h1>501 Not Implemented</h1>\
+<p>This server is not (yet) Apache.</p>\
+</body>\
+</html>";
+ response.bodyOutputStream.write(body, body.length);
+ },
+ 505: function(metadata, response)
+ {
+ response.setStatusLine("1.1", 505, "HTTP Version Not Supported");
+ response.setHeader("Content-Type", "text/html", false);
+
+ var body = "<html>\
+<head><title>505 HTTP Version Not Supported</title></head>\
+<body>\
+<h1>505 HTTP Version Not Supported</h1>\
+<p>This server only supports HTTP/1.0 and HTTP/1.1\
+connections.</p>\
+</body>\
+</html>";
+ response.bodyOutputStream.write(body, body.length);
+ }
+ },
+
+ /**
+* Contains handlers for the default set of URIs contained in this server.
+*/
+ _defaultPaths:
+ {
+ "/": function(metadata, response)
+ {
+ response.setStatusLine(metadata.httpVersion, 200, "OK");
+ response.setHeader("Content-Type", "text/html", false);
+
+ var body = "<html>\
+<head><title>httpd.js</title></head>\
+<body>\
+<h1>httpd.js</h1>\
+<p>If you're seeing this page, httpd.js is up and\
+serving requests! Now set a base path and serve some\
+files!</p>\
+</body>\
+</html>";
+
+ response.bodyOutputStream.write(body, body.length);
+ },
+
+ "/trace": function(metadata, response)
+ {
+ response.setStatusLine(metadata.httpVersion, 200, "OK");
+ response.setHeader("Content-Type", "text/plain", false);
+
+ var body = "Request-URI: " +
+ metadata.scheme + "://" + metadata.host + ":" + metadata.port +
+ metadata.path + "\n\n";
+ body += "Request (semantically equivalent, slightly reformatted):\n\n";
+ body += metadata.method + " " + metadata.path;
+
+ if (metadata.queryString)
+ body += "?" + metadata.queryString;
+
+ body += " HTTP/" + metadata.httpVersion + "\r\n";
+
+ var headEnum = metadata.headers;
+ while (headEnum.hasMoreElements())
+ {
+ var fieldName = headEnum.getNext()
+ .QueryInterface(Ci.nsISupportsString)
+ .data;
+ body += fieldName + ": " + metadata.getHeader(fieldName) + "\r\n";
+ }
+
+ response.bodyOutputStream.write(body, body.length);
+ }
+ }
+};
+
+
+/**
+* Maps absolute paths to files on the local file system (as nsILocalFiles).
+*/
+function FileMap()
+{
+ /** Hash which will map paths to nsILocalFiles. */
+ this._map = {};
+}
+FileMap.prototype =
+{
+ // PUBLIC API
+
+ /**
+* Maps key to a clone of the nsILocalFile value if value is non-null;
+* otherwise, removes any extant mapping for key.
+*
+* @param key : string
+* string to which a clone of value is mapped
+* @param value : nsILocalFile
+* the file to map to key, or null to remove a mapping
+*/
+ put: function(key, value)
+ {
+ if (value)
+ this._map[key] = value.clone();
+ else
+ delete this._map[key];
+ },
+
+ /**
+* Returns a clone of the nsILocalFile mapped to key, or null if no such
+* mapping exists.
+*
+* @param key : string
+* key to which the returned file maps
+* @returns nsILocalFile
+* a clone of the mapped file, or null if no mapping exists
+*/
+ get: function(key)
+ {
+ var val = this._map[key];
+ return val ? val.clone() : null;
+ }
+};
+
+
+// Response CONSTANTS
+
+// token = *<any CHAR except CTLs or separators>
+// CHAR = <any US-ASCII character (0-127)>
+// CTL = <any US-ASCII control character (0-31) and DEL (127)>
+// separators = "(" | ")" | "<" | ">" | "@"
+// | "," | ";" | ":" | "\" | <">
+// | "/" | "[" | "]" | "?" | "="
+// | "{" | "}" | SP | HT
+const IS_TOKEN_ARRAY =
+ [0, 0, 0, 0, 0, 0, 0, 0, // 0
+ 0, 0, 0, 0, 0, 0, 0, 0, // 8
+ 0, 0, 0, 0, 0, 0, 0, 0, // 16
+ 0, 0, 0, 0, 0, 0, 0, 0, // 24
+
+ 0, 1, 0, 1, 1, 1, 1, 1, // 32
+ 0, 0, 1, 1, 0, 1, 1, 0, // 40
+ 1, 1, 1, 1, 1, 1, 1, 1, // 48
+ 1, 1, 0, 0, 0, 0, 0, 0, // 56
+
+ 0, 1, 1, 1, 1, 1, 1, 1, // 64
+ 1, 1, 1, 1, 1, 1, 1, 1, // 72
+ 1, 1, 1, 1, 1, 1, 1, 1, // 80
+ 1, 1, 1, 0, 0, 0, 1, 1, // 88
+
+ 1, 1, 1, 1, 1, 1, 1, 1, // 96
+ 1, 1, 1, 1, 1, 1, 1, 1, // 104
+ 1, 1, 1, 1, 1, 1, 1, 1, // 112
+ 1, 1, 1, 0, 1, 0, 1]; // 120
+
+
+/**
+* Determines whether the given character code is a CTL.
+*
+* @param code : uint
+* the character code
+* @returns boolean
+* true if code is a CTL, false otherwise
+*/
+function isCTL(code)
+{
+ return (code >= 0 && code <= 31) || (code == 127);
+}
+
+/**
+* Represents a response to an HTTP request, encapsulating all details of that
+* response. This includes all headers, the HTTP version, status code and
+* explanation, and the entity itself.
+*
+* @param connection : Connection
+* the connection over which this response is to be written
+*/
+function Response(connection)
+{
+ /** The connection over which this response will be written. */
+ this._connection = connection;
+
+ /**
+* The HTTP version of this response; defaults to 1.1 if not set by the
+* handler.
+*/
+ this._httpVersion = nsHttpVersion.HTTP_1_1;
+
+ /**
+* The HTTP code of this response; defaults to 200.
+*/
+ this._httpCode = 200;
+
+ /**
+* The description of the HTTP code in this response; defaults to "OK".
+*/
+ this._httpDescription = "OK";
+
+ /**
+* An nsIHttpHeaders object in which the headers in this response should be
+* stored. This property is null after the status line and headers have been
+* written to the network, and it may be modified up until it is cleared,
+* except if this._finished is set first (in which case headers are written
+* asynchronously in response to a finish() call not preceded by
+* flushHeaders()).
+*/
+ this._headers = new nsHttpHeaders();
+
+ /**
+* Set to true when this response is ended (completely constructed if possible
+* and the connection closed); further actions on this will then fail.
+*/
+ this._ended = false;
+
+ /**
+* A stream used to hold data written to the body of this response.
+*/
+ this._bodyOutputStream = null;
+
+ /**
+* A stream containing all data that has been written to the body of this
+* response so far. (Async handlers make the data contained in this
+* unreliable as a way of determining content length in general, but auxiliary
+* saved information can sometimes be used to guarantee reliability.)
+*/
+ this._bodyInputStream = null;
+
+ /**
+* A stream copier which copies data to the network. It is initially null
+* until replaced with a copier for response headers; when headers have been
+* fully sent it is replaced with a copier for the response body, remaining
+* so for the duration of response processing.
+*/
+ this._asyncCopier = null;
+
+ /**
+* True if this response has been designated as being processed
+* asynchronously rather than for the duration of a single call to
+* nsIHttpRequestHandler.handle.
+*/
+ this._processAsync = false;
+
+ /**
+* True iff finish() has been called on this, signaling that no more changes
+* to this may be made.
+*/
+ this._finished = false;
+
+ /**
+* True iff powerSeized() has been called on this, signaling that this
+* response is to be handled manually by the response handler (which may then
+* send arbitrary data in response, even non-HTTP responses).
+*/
+ this._powerSeized = false;
+}
+Response.prototype =
+{
+ // PUBLIC CONSTRUCTION API
+
+ //
+ // see nsIHttpResponse.bodyOutputStream
+ //
+ get bodyOutputStream()
+ {
+ if (this._finished)
+ throw Cr.NS_ERROR_NOT_AVAILABLE;
+
+ if (!this._bodyOutputStream)
+ {
+ var pipe = new Pipe(true, false, Response.SEGMENT_SIZE, PR_UINT32_MAX,
+ null);
+ this._bodyOutputStream = pipe.outputStream;
+ this._bodyInputStream = pipe.inputStream;
+ if (this._processAsync || this._powerSeized)
+ this._startAsyncProcessor();
+ }
+
+ return this._bodyOutputStream;
+ },
+
+ //
+ // see nsIHttpResponse.write
+ //
+ write: function(data)
+ {
+ if (this._finished)
+ throw Cr.NS_ERROR_NOT_AVAILABLE;
+
+ var dataAsString = String(data);
+ this.bodyOutputStream.write(dataAsString, dataAsString.length);
+ },
+
+ //
+ // see nsIHttpResponse.setStatusLine
+ //
+ setStatusLine: function(httpVersion, code, description)
+ {
+ if (!this._headers || this._finished || this._powerSeized)
+ throw Cr.NS_ERROR_NOT_AVAILABLE;
+ this._ensureAlive();
+
+ if (!(code >= 0 && code < 1000))
+ throw Cr.NS_ERROR_INVALID_ARG;
+
+ try
+ {
+ var httpVer;
+ // avoid version construction for the most common cases
+ if (!httpVersion || httpVersion == "1.1")
+ httpVer = nsHttpVersion.HTTP_1_1;
+ else if (httpVersion == "1.0")
+ httpVer = nsHttpVersion.HTTP_1_0;
+ else
+ httpVer = new nsHttpVersion(httpVersion);
+ }
+ catch (e)
+ {
+ throw Cr.NS_ERROR_INVALID_ARG;
+ }
+
+ // Reason-Phrase = *<TEXT, excluding CR, LF>
+ // TEXT = <any OCTET except CTLs, but including LWS>
+ //
+ // XXX this ends up disallowing octets which aren't Unicode, I think -- not
+ // much to do if description is IDL'd as string
+ if (!description)
+ description = "";
+ for (var i = 0; i < description.length; i++)
+ if (isCTL(description.charCodeAt(i)) && description.charAt(i) != "\t")
+ throw Cr.NS_ERROR_INVALID_ARG;
+
+ // set the values only after validation to preserve atomicity
+ this._httpDescription = description;
+ this._httpCode = code;
+ this._httpVersion = httpVer;
+ },
+
+ //
+ // see nsIHttpResponse.setHeader
+ //
+ setHeader: function(name, value, merge)
+ {
+ if (!this._headers || this._finished || this._powerSeized)
+ throw Cr.NS_ERROR_NOT_AVAILABLE;
+ this._ensureAlive();
+
+ this._headers.setHeader(name, value, merge);
+ },
+
+ //
+ // see nsIHttpResponse.processAsync
+ //
+ processAsync: function()
+ {
+ if (this._finished)
+ throw Cr.NS_ERROR_UNEXPECTED;
+ if (this._powerSeized)
+ throw Cr.NS_ERROR_NOT_AVAILABLE;
+ if (this._processAsync)
+ return;
+ this._ensureAlive();
+
+ dumpn("*** processing connection " + this._connection.number + " async");
+ this._processAsync = true;
+
+ /*
+* Either the bodyOutputStream getter or this method is responsible for
+* starting the asynchronous processor and catching writes of data to the
+* response body of async responses as they happen, for the purpose of
+* forwarding those writes to the actual connection's output stream.
+* If bodyOutputStream is accessed first, calling this method will create
+* the processor (when it first is clear that body data is to be written
+* immediately, not buffered). If this method is called first, accessing
+* bodyOutputStream will create the processor. If only this method is
+* called, we'll write nothing, neither headers nor the nonexistent body,
+* until finish() is called. Since that delay is easily avoided by simply
+* getting bodyOutputStream or calling write(""), we don't worry about it.
+*/
+ if (this._bodyOutputStream && !this._asyncCopier)
+ this._startAsyncProcessor();
+ },
+
+ //
+ // see nsIHttpResponse.seizePower
+ //
+ seizePower: function()
+ {
+ if (this._processAsync)
+ throw Cr.NS_ERROR_NOT_AVAILABLE;
+ if (this._finished)
+ throw Cr.NS_ERROR_UNEXPECTED;
+ if (this._powerSeized)
+ return;
+ this._ensureAlive();
+
+ dumpn("*** forcefully seizing power over connection " +
+ this._connection.number + "...");
+
+ // Purge any already-written data without sending it. We could as easily
+ // swap out the streams entirely, but that makes it possible to acquire and
+ // unknowingly use a stale reference, so we require there only be one of
+ // each stream ever for any response to avoid this complication.
+ if (this._asyncCopier)
+ this._asyncCopier.cancel(Cr.NS_BINDING_ABORTED);
+ this._asyncCopier = null;
+ if (this._bodyOutputStream)
+ {
+ var input = new BinaryInputStream(this._bodyInputStream);
+ var avail;
+ while ((avail = input.available()) > 0)
+ input.readByteArray(avail);
+ }
+
+ this._powerSeized = true;
+ if (this._bodyOutputStream)
+ this._startAsyncProcessor();
+ },
+
+ //
+ // see nsIHttpResponse.finish
+ //
+ finish: function()
+ {
+ if (!this._processAsync && !this._powerSeized)
+ throw Cr.NS_ERROR_UNEXPECTED;
+ if (this._finished)
+ return;
+
+ dumpn("*** finishing connection " + this._connection.number);
+ this._startAsyncProcessor(); // in case bodyOutputStream was never accessed
+ if (this._bodyOutputStream)
+ this._bodyOutputStream.close();
+ this._finished = true;
+ },
+
+
+ // NSISUPPORTS
+
+ //
+ // see nsISupports.QueryInterface
+ //
+ QueryInterface: function(iid)
+ {
+ if (iid.equals(Ci.nsIHttpResponse) || iid.equals(Ci.nsISupports))
+ return this;
+
+ throw Cr.NS_ERROR_NO_INTERFACE;
+ },
+
+
+ // POST-CONSTRUCTION API (not exposed externally)
+
+ /**
+* The HTTP version number of this, as a string (e.g. "1.1").
+*/
+ get httpVersion()
+ {
+ this._ensureAlive();
+ return this._httpVersion.toString();
+ },
+
+ /**
+* The HTTP status code of this response, as a string of three characters per
+* RFC 2616.
+*/
+ get httpCode()
+ {
+ this._ensureAlive();
+
+ var codeString = (this._httpCode < 10 ? "0" : "") +
+ (this._httpCode < 100 ? "0" : "") +
+ this._httpCode;
+ return codeString;
+ },
+
+ /**
+* The description of the HTTP status code of this response, or "" if none is
+* set.
+*/
+ get httpDescription()
+ {
+ this._ensureAlive();
+
+ return this._httpDescription;
+ },
+
+ /**
+* The headers in this response, as an nsHttpHeaders object.
+*/
+ get headers()
+ {
+ this._ensureAlive();
+
+ return this._headers;
+ },
+
+ //
+ // see nsHttpHeaders.getHeader
+ //
+ getHeader: function(name)
+ {
+ this._ensureAlive();
+
+ return this._headers.getHeader(name);
+ },
+
+ /**
+* Determines whether this response may be abandoned in favor of a newly
+* constructed response. A response may be abandoned only if it is not being
+* sent asynchronously and if raw control over it has not been taken from the
+* server.
+*
+* @returns boolean
+* true iff no data has been written to the network
+*/
+ partiallySent: function()
+ {
+ dumpn("*** partiallySent()");
+ return this._processAsync || this._powerSeized;
+ },
+
+ /**
+* If necessary, kicks off the remaining request processing needed to be done
+* after a request handler performs its initial work upon this response.
+*/
+ complete: function()
+ {
+ dumpn("*** complete()");
+ if (this._processAsync || this._powerSeized)
+ {
+ NS_ASSERT(this._processAsync ^ this._powerSeized,
+ "can't both send async and relinquish power");
+ return;
+ }
+
+ NS_ASSERT(!this.partiallySent(), "completing a partially-sent response?");
+
+ this._startAsyncProcessor();
+
+ // Now make sure we finish processing this request!
+ if (this._bodyOutputStream)
+ this._bodyOutputStream.close();
+ },
+
+ /**
+* Abruptly ends processing of this response, usually due to an error in an
+* incoming request but potentially due to a bad error handler. Since we
+* cannot handle the error in the usual way (giving an HTTP error page in
+* response) because data may already have been sent (or because the response
+* might be expected to have been generated asynchronously or completely from
+* scratch by the handler), we stop processing this response and abruptly
+* close the connection.
+*
+* @param e : Error
+* the exception which precipitated this abort, or null if no such exception
+* was generated
+*/
+ abort: function(e)
+ {
+ dumpn("*** abort(<" + e + ">)");
+
+ // This response will be ended by the processor if one was created.
+ var copier = this._asyncCopier;
+ if (copier)
+ {
+ // We dispatch asynchronously here so that any pending writes of data to
+ // the connection will be deterministically written. This makes it easier
+ // to specify exact behavior, and it makes observable behavior more
+ // predictable for clients. Note that the correctness of this depends on
+ // callbacks in response to _waitToReadData in WriteThroughCopier
+ // happening asynchronously with respect to the actual writing of data to
+ // bodyOutputStream, as they currently do; if they happened synchronously,
+ // an event which ran before this one could write more data to the
+ // response body before we get around to canceling the copier. We have
+ // tests for this in test_seizepower.js, however, and I can't think of a
+ // way to handle both cases without removing bodyOutputStream access and
+ // moving its effective write(data, length) method onto Response, which
+ // would be slower and require more code than this anyway.
+ gThreadManager.currentThread.dispatch({
+ run: function()
+ {
+ dumpn("*** canceling copy asynchronously...");
+ copier.cancel(Cr.NS_ERROR_UNEXPECTED);
+ }
+ }, Ci.nsIThread.DISPATCH_NORMAL);
+ }
+ else
+ {
+ this.end();
+ }
+ },
+
+ /**
+* Closes this response's network connection, marks the response as finished,
+* and notifies the server handler that the request is done being processed.
+*/
+ end: function()
+ {
+ NS_ASSERT(!this._ended, "ending this response twice?!?!");
+
+ this._connection.close();
+ if (this._bodyOutputStream)
+ this._bodyOutputStream.close();
+
+ this._finished = true;
+ this._ended = true;
+ },
+
+ // PRIVATE IMPLEMENTATION
+
+ /**
+* Sends the status line and headers of this response if they haven't been
+* sent and initiates the process of copying data written to this response's
+* body to the network.
+*/
+ _startAsyncProcessor: function()
+ {
+ dumpn("*** _startAsyncProcessor()");
+
+ // Handle cases where we're being called a second time. The former case
+ // happens when this is triggered both by complete() and by processAsync(),
+ // while the latter happens when processAsync() in conjunction with sent
+ // data causes abort() to be called.
+ if (this._asyncCopier || this._ended)
+ {
+ dumpn("*** ignoring second call to _startAsyncProcessor");
+ return;
+ }
+
+ // Send headers if they haven't been sent already and should be sent, then
+ // asynchronously continue to send the body.
+ if (this._headers && !this._powerSeized)
+ {
+ this._sendHeaders();
+ return;
+ }
+
+ this._headers = null;
+ this._sendBody();
+ },
+
+ /**
+* Signals that all modifications to the response status line and headers are
+* complete and then sends that data over the network to the client. Once
+* this method completes, a different response to the request that resulted
+* in this response cannot be sent -- the only possible action in case of
+* error is to abort the response and close the connection.
+*/
+ _sendHeaders: function()
+ {
+ dumpn("*** _sendHeaders()");
+
+ NS_ASSERT(this._headers);
+ NS_ASSERT(!this._powerSeized);
+
+ // request-line
+ var statusLine = "HTTP/" + this.httpVersion + " " +
+ this.httpCode + " " +
+ this.httpDescription + "\r\n";
+
+ // header post-processing
+
+ var headers = this._headers;
+ headers.setHeader("Connection", "close", false);
+ headers.setHeader("Server", "httpd.js", false);
+ if (!headers.hasHeader("Date"))
+ headers.setHeader("Date", toDateString(Date.now()), false);
+
+ // Any response not being processed asynchronously must have an associated
+ // Content-Length header for reasons of backwards compatibility with the
+ // initial server, which fully buffered every response before sending it.
+ // Beyond that, however, it's good to do this anyway because otherwise it's
+ // impossible to test behaviors that depend on the presence or absence of a
+ // Content-Length header.
+ if (!this._processAsync)
+ {
+ dumpn("*** non-async response, set Content-Length");
+
+ var bodyStream = this._bodyInputStream;
+ var avail = bodyStream ? bodyStream.available() : 0;
+
+ // XXX assumes stream will always report the full amount of data available
+ headers.setHeader("Content-Length", "" + avail, false);
+ }
+
+
+ // construct and send response
+ dumpn("*** header post-processing completed, sending response head...");
+
+ // request-line
+ var preambleData = [statusLine];
+
+ // headers
+ var headEnum = headers.enumerator;
+ while (headEnum.hasMoreElements())
+ {
+ var fieldName = headEnum.getNext()
+ .QueryInterface(Ci.nsISupportsString)
+ .data;
+ var values = headers.getHeaderValues(fieldName);
+ for (var i = 0, sz = values.length; i < sz; i++)
+ preambleData.push(fieldName + ": " + values[i] + "\r\n");
+ }
+
+ // end request-line/headers
+ preambleData.push("\r\n");
+
+ var preamble = preambleData.join("");
+
+ var responseHeadPipe = new Pipe(true, false, 0, PR_UINT32_MAX, null);
+ responseHeadPipe.outputStream.write(preamble, preamble.length);
+
+ var response = this;
+ var copyObserver =
+ {
+ onStartRequest: function(request, cx)
+ {
+ dumpn("*** preamble copying started");
+ },
+
+ onStopRequest: function(request, cx, statusCode)
+ {
+ dumpn("*** preamble copying complete " +
+ "[status=0x" + statusCode.toString(16) + "]");
+
+ if (!components.isSuccessCode(statusCode))
+ {
+ dumpn("!!! header copying problems: non-success statusCode, " +
+ "ending response");
+
+ response.end();
+ }
+ else
+ {
+ response._sendBody();
+ }
+ },
+
+ QueryInterface: function(aIID)
+ {
+ if (aIID.equals(Ci.nsIRequestObserver) || aIID.equals(Ci.nsISupports))
+ return this;
+
+ throw Cr.NS_ERROR_NO_INTERFACE;
+ }
+ };
+
+ var headerCopier = this._asyncCopier =
+ new WriteThroughCopier(responseHeadPipe.inputStream,
+ this._connection.output,
+ copyObserver, null);
+
+ responseHeadPipe.outputStream.close();
+
+ // Forbid setting any more headers or modifying the request line.
+ this._headers = null;
+ },
+
+ /**
+* Asynchronously writes the body of the response (or the entire response, if
+* seizePower() has been called) to the network.
+*/
+ _sendBody: function()
+ {
+ dumpn("*** _sendBody");
+
+ NS_ASSERT(!this._headers, "still have headers around but sending body?");
+
+ // If no body data was written, we're done
+ if (!this._bodyInputStream)
+ {
+ dumpn("*** empty body, response finished");
+ this.end();
+ return;
+ }
+
+ var response = this;
+ var copyObserver =
+ {
+ onStartRequest: function(request, context)
+ {
+ dumpn("*** onStartRequest");
+ },
+
+ onStopRequest: function(request, cx, statusCode)
+ {
+ dumpn("*** onStopRequest [status=0x" + statusCode.toString(16) + "]");
+
+ if (statusCode === Cr.NS_BINDING_ABORTED)
+ {
+ dumpn("*** terminating copy observer without ending the response");
+ }
+ else
+ {
+ if (!components.isSuccessCode(statusCode))
+ dumpn("*** WARNING: non-success statusCode in onStopRequest");
+
+ response.end();
+ }
+ },
+
+ QueryInterface: function(aIID)
+ {
+ if (aIID.equals(Ci.nsIRequestObserver) || aIID.equals(Ci.nsISupports))
+ return this;
+
+ throw Cr.NS_ERROR_NO_INTERFACE;
+ }
+ };
+
+ dumpn("*** starting async copier of body data...");
+ this._asyncCopier =
+ new WriteThroughCopier(this._bodyInputStream, this._connection.output,
+ copyObserver, null);
+ },
+
+ /** Ensures that this hasn't been ended. */
+ _ensureAlive: function()
+ {
+ NS_ASSERT(!this._ended, "not handling response lifetime correctly");
+ }
+};
+
+/**
+* Size of the segments in the buffer used in storing response data and writing
+* it to the socket.
+*/
+Response.SEGMENT_SIZE = 8192;
+
+/** Serves double duty in WriteThroughCopier implementation. */
+function notImplemented()
+{
+ throw Cr.NS_ERROR_NOT_IMPLEMENTED;
+}
+
+/** Returns true iff the given exception represents stream closure. */
+function streamClosed(e)
+{
+ return e === Cr.NS_BASE_STREAM_CLOSED ||
+ (typeof e === "object" && e.result === Cr.NS_BASE_STREAM_CLOSED);
+}
+
+/** Returns true iff the given exception represents a blocked stream. */
+function wouldBlock(e)
+{
+ return e === Cr.NS_BASE_STREAM_WOULD_BLOCK ||
+ (typeof e === "object" && e.result === Cr.NS_BASE_STREAM_WOULD_BLOCK);
+}
+
+/**
+* Copies data from source to sink as it becomes available, when that data can
+* be written to sink without blocking.
+*
+* @param source : nsIAsyncInputStream
+* the stream from which data is to be read
+* @param sink : nsIAsyncOutputStream
+* the stream to which data is to be copied
+* @param observer : nsIRequestObserver
+* an observer which will be notified when the copy starts and finishes
+* @param context : nsISupports
+* context passed to observer when notified of start/stop
+* @throws NS_ERROR_NULL_POINTER
+* if source, sink, or observer are null
+*/
+function WriteThroughCopier(source, sink, observer, context)
+{
+ if (!source || !sink || !observer)
+ throw Cr.NS_ERROR_NULL_POINTER;
+
+ /** Stream from which data is being read. */
+ this._source = source;
+
+ /** Stream to which data is being written. */
+ this._sink = sink;
+
+ /** Observer watching this copy. */
+ this._observer = observer;
+
+ /** Context for the observer watching this. */
+ this._context = context;
+
+ /**
+* True iff this is currently being canceled (cancel has been called, the
+* callback may not yet have been made).
+*/
+ this._canceled = false;
+
+ /**
+* False until all data has been read from input and written to output, at
+* which point this copy is completed and cancel() is asynchronously called.
+*/
+ this._completed = false;
+
+ /** Required by nsIRequest, meaningless. */
+ this.loadFlags = 0;
+ /** Required by nsIRequest, meaningless. */
+ this.loadGroup = null;
+ /** Required by nsIRequest, meaningless. */
+ this.name = "response-body-copy";
+
+ /** Status of this request. */
+ this.status = Cr.NS_OK;
+
+ /** Arrays of byte strings waiting to be written to output. */
+ this._pendingData = [];
+
+ // start copying
+ try
+ {
+ observer.onStartRequest(this, context);
+ this._waitToReadData();
+ this._waitForSinkClosure();
+ }
+ catch (e)
+ {
+ dumpn("!!! error starting copy: " + e +
+ ("lineNumber" in e ? ", line " + e.lineNumber : ""));
+ dumpn(e.stack);
+ this.cancel(Cr.NS_ERROR_UNEXPECTED);
+ }
+}
+WriteThroughCopier.prototype =
+{
+ /* nsISupports implementation */
+
+ QueryInterface: function(iid)
+ {
+ if (iid.equals(Ci.nsIInputStreamCallback) ||
+ iid.equals(Ci.nsIOutputStreamCallback) ||
+ iid.equals(Ci.nsIRequest) ||
+ iid.equals(Ci.nsISupports))
+ {
+ return this;
+ }
+
+ throw Cr.NS_ERROR_NO_INTERFACE;
+ },
+
+
+ // NSIINPUTSTREAMCALLBACK
+
+ /**
+* Receives a more-data-in-input notification and writes the corresponding
+* data to the output.
+*
+* @param input : nsIAsyncInputStream
+* the input stream on whose data we have been waiting
+*/
+ onInputStreamReady: function(input)
+ {
+ if (this._source === null)
+ return;
+
+ dumpn("*** onInputStreamReady");
+
+ //
+ // Ordinarily we'll read a non-zero amount of data from input, queue it up
+ // to be written and then wait for further callbacks. The complications in
+ // this method are the cases where we deviate from that behavior when errors
+ // occur or when copying is drawing to a finish.
+ //
+ // The edge cases when reading data are:
+ //
+ // Zero data is read
+ // If zero data was read, we're at the end of available data, so we can
+ // should stop reading and move on to writing out what we have (or, if
+ // we've already done that, onto notifying of completion).
+ // A stream-closed exception is thrown
+ // This is effectively a less kind version of zero data being read; the
+ // only difference is that we notify of completion with that result
+ // rather than with NS_OK.
+ // Some other exception is thrown
+ // This is the least kind result. We don't know what happened, so we
+ // act as though the stream closed except that we notify of completion
+ // with the result NS_ERROR_UNEXPECTED.
+ //
+
+ var bytesWanted = 0, bytesConsumed = -1;
+ try
+ {
+ input = new BinaryInputStream(input);
+
+ bytesWanted = Math.min(input.available(), Response.SEGMENT_SIZE);
+ dumpn("*** input wanted: " + bytesWanted);
+
+ if (bytesWanted > 0)
+ {
+ var data = input.readByteArray(bytesWanted);
+ bytesConsumed = data.length;
+ this._pendingData.push(String.fromCharCode.apply(String, data));
+ }
+
+ dumpn("*** " + bytesConsumed + " bytes read");
+
+ // Handle the zero-data edge case in the same place as all other edge
+ // cases are handled.
+ if (bytesWanted === 0)
+ throw Cr.NS_BASE_STREAM_CLOSED;
+ }
+ catch (e)
+ {
+ if (streamClosed(e))
+ {
+ dumpn("*** input stream closed");
+ e = bytesWanted === 0 ? Cr.NS_OK : Cr.NS_ERROR_UNEXPECTED;
+ }
+ else
+ {
+ dumpn("!!! unexpected error reading from input, canceling: " + e);
+ e = Cr.NS_ERROR_UNEXPECTED;
+ }
+
+ this._doneReadingSource(e);
+ return;
+ }
+
+ var pendingData = this._pendingData;
+
+ NS_ASSERT(bytesConsumed > 0);
+ NS_ASSERT(pendingData.length > 0, "no pending data somehow?");
+ NS_ASSERT(pendingData[pendingData.length - 1].length > 0,
+ "buffered zero bytes of data?");
+
+ NS_ASSERT(this._source !== null);
+
+ // Reading has gone great, and we've gotten data to write now. What if we
+ // don't have a place to write that data, because output went away just
+ // before this read? Drop everything on the floor, including new data, and
+ // cancel at this point.
+ if (this._sink === null)
+ {
+ pendingData.length = 0;
+ this._doneReadingSource(Cr.NS_ERROR_UNEXPECTED);
+ return;
+ }
+
+ // Okay, we've read the data, and we know we have a place to write it. We
+ // need to queue up the data to be written, but *only* if none is queued
+ // already -- if data's already queued, the code that actually writes the
+ // data will make sure to wait on unconsumed pending data.
+ try
+ {
+ if (pendingData.length === 1)
+ this._waitToWriteData();
+ }
+ catch (e)
+ {
+ dumpn("!!! error waiting to write data just read, swallowing and " +
+ "writing only what we already have: " + e);
+ this._doneWritingToSink(Cr.NS_ERROR_UNEXPECTED);
+ return;
+ }
+
+ // Whee! We successfully read some data, and it's successfully queued up to
+ // be written. All that remains now is to wait for more data to read.
+ try
+ {
+ this._waitToReadData();
+ }
+ catch (e)
+ {
+ dumpn("!!! error waiting to read more data: " + e);
+ this._doneReadingSource(Cr.NS_ERROR_UNEXPECTED);
+ }
+ },
+
+
+ // NSIOUTPUTSTREAMCALLBACK
+
+ /**
+* Callback when data may be written to the output stream without blocking, or
+* when the output stream has been closed.
+*
+* @param output : nsIAsyncOutputStream
+* the output stream on whose writability we've been waiting, also known as
+* this._sink
+*/
+ onOutputStreamReady: function(output)
+ {
+ if (this._sink === null)
+ return;
+
+ dumpn("*** onOutputStreamReady");
+
+ var pendingData = this._pendingData;
+ if (pendingData.length === 0)
+ {
+ // There's no pending data to write. The only way this can happen is if
+ // we're waiting on the output stream's closure, so we can respond to a
+ // copying failure as quickly as possible (rather than waiting for data to
+ // be available to read and then fail to be copied). Therefore, we must
+ // be done now -- don't bother to attempt to write anything and wrap
+ // things up.
+ dumpn("!!! output stream closed prematurely, ending copy");
+
+ this._doneWritingToSink(Cr.NS_ERROR_UNEXPECTED);
+ return;
+ }
+
+
+ NS_ASSERT(pendingData[0].length > 0, "queued up an empty quantum?");
+
+ //
+ // Write out the first pending quantum of data. The possible errors here
+ // are:
+ //
+ // The write might fail because we can't write that much data
+ // Okay, we've written what we can now, so re-queue what's left and
+ // finish writing it out later.
+ // The write failed because the stream was closed
+ // Discard pending data that we can no longer write, stop reading, and
+ // signal that copying finished.
+ // Some other error occurred.
+ // Same as if the stream were closed, but notify with the status
+ // NS_ERROR_UNEXPECTED so the observer knows something was wonky.
+ //
+
+ try
+ {
+ var quantum = pendingData[0];
+
+ // XXX |quantum| isn't guaranteed to be ASCII, so we're relying on
+ // undefined behavior! We're only using this because writeByteArray
+ // is unusably broken for asynchronous output streams; see bug 532834
+ // for details.
+ var bytesWritten = output.write(quantum, quantum.length);
+ if (bytesWritten === quantum.length)
+ pendingData.shift();
+ else
+ pendingData[0] = quantum.substring(bytesWritten);
+
+ dumpn("*** wrote " + bytesWritten + " bytes of data");
+ }
+ catch (e)
+ {
+ if (wouldBlock(e))
+ {
+ NS_ASSERT(pendingData.length > 0,
+ "stream-blocking exception with no data to write?");
+ NS_ASSERT(pendingData[0].length > 0,
+ "stream-blocking exception with empty quantum?");
+ this._waitToWriteData();
+ return;
+ }
+
+ if (streamClosed(e))
+ dumpn("!!! output stream prematurely closed, signaling error...");
+ else
+ dumpn("!!! unknown error: " + e + ", quantum=" + quantum);
+
+ this._doneWritingToSink(Cr.NS_ERROR_UNEXPECTED);
+ return;
+ }
+
+ // The day is ours! Quantum written, now let's see if we have more data
+ // still to write.
+ try
+ {
+ if (pendingData.length > 0)
+ {
+ this._waitToWriteData();
+ return;
+ }
+ }
+ catch (e)
+ {
+ dumpn("!!! unexpected error waiting to write pending data: " + e);
+ this._doneWritingToSink(Cr.NS_ERROR_UNEXPECTED);
+ return;
+ }
+
+ // Okay, we have no more pending data to write -- but might we get more in
+ // the future?
+ if (this._source !== null)
+ {
+ /*
+* If we might, then wait for the output stream to be closed. (We wait
+* only for closure because we have no data to write -- and if we waited
+* for a specific amount of data, we would get repeatedly notified for no
+* reason if over time the output stream permitted more and more data to
+* be written to it without blocking.)
+*/
+ this._waitForSinkClosure();
+ }
+ else
+ {
+ /*
+* On the other hand, if we can't have more data because the input
+* stream's gone away, then it's time to notify of copy completion.
+* Victory!
+*/
+ this._sink = null;
+ this._cancelOrDispatchCancelCallback(Cr.NS_OK);
+ }
+ },
+
+
+ // NSIREQUEST
+
+ /** Returns true if the cancel observer hasn't been notified yet. */
+ isPending: function()
+ {
+ return !this._completed;
+ },
+
+ /** Not implemented, don't use! */
+ suspend: notImplemented,
+ /** Not implemented, don't use! */
+ resume: notImplemented,
+
+ /**
+* Cancels data reading from input, asynchronously writes out any pending
+* data, and causes the observer to be notified with the given error code when
+* all writing has finished.
+*
+* @param status : nsresult
+* the status to pass to the observer when data copying has been canceled
+*/
+ cancel: function(status)
+ {
+ dumpn("*** cancel(" + status.toString(16) + ")");
+
+ if (this._canceled)
+ {
+ dumpn("*** suppressing a late cancel");
+ return;
+ }
+
+ this._canceled = true;
+ this.status = status;
+
+ // We could be in the middle of absolutely anything at this point. Both
+ // input and output might still be around, we might have pending data to
+ // write, and in general we know nothing about the state of the world. We
+ // therefore must assume everything's in progress and take everything to its
+ // final steady state (or so far as it can go before we need to finish
+ // writing out remaining data).
+
+ this._doneReadingSource(status);
+ },
+
+
+ // PRIVATE IMPLEMENTATION
+
+ /**
+* Stop reading input if we haven't already done so, passing e as the status
+* when closing the stream, and kick off a copy-completion notice if no more
+* data remains to be written.
+*
+* @param e : nsresult
+* the status to be used when closing the input stream
+*/
+ _doneReadingSource: function(e)
+ {
+ dumpn("*** _doneReadingSource(0x" + e.toString(16) + ")");
+
+ this._finishSource(e);
+ if (this._pendingData.length === 0)
+ this._sink = null;
+ else
+ NS_ASSERT(this._sink !== null, "null output?");
+
+ // If we've written out all data read up to this point, then it's time to
+ // signal completion.
+ if (this._sink === null)
+ {
+ NS_ASSERT(this._pendingData.length === 0, "pending data still?");
+ this._cancelOrDispatchCancelCallback(e);
+ }
+ },
+
+ /**
+* Stop writing output if we haven't already done so, discard any data that
+* remained to be sent, close off input if it wasn't already closed, and kick
+* off a copy-completion notice.
+*
+* @param e : nsresult
+* the status to be used when closing input if it wasn't already closed
+*/
+ _doneWritingToSink: function(e)
+ {
+ dumpn("*** _doneWritingToSink(0x" + e.toString(16) + ")");
+
+ this._pendingData.length = 0;
+ this._sink = null;
+ this._doneReadingSource(e);
+ },
+
+ /**
+* Completes processing of this copy: either by canceling the copy if it
+* hasn't already been canceled using the provided status, or by dispatching
+* the cancel callback event (with the originally provided status, of course)
+* if it already has been canceled.
+*
+* @param status : nsresult
+* the status code to use to cancel this, if this hasn't already been
+* canceled
+*/
+ _cancelOrDispatchCancelCallback: function(status)
+ {
+ dumpn("*** _cancelOrDispatchCancelCallback(" + status + ")");
+
+ NS_ASSERT(this._source === null, "should have finished input");
+ NS_ASSERT(this._sink === null, "should have finished output");
+ NS_ASSERT(this._pendingData.length === 0, "should have no pending data");
+
+ if (!this._canceled)
+ {
+ this.cancel(status);
+ return;
+ }
+
+ var self = this;
+ var event =
+ {
+ run: function()
+ {
+ dumpn("*** onStopRequest async callback");
+
+ self._completed = true;
+ try
+ {
+ self._observer.onStopRequest(self, self._context, self.status);
+ }
+ catch (e)
+ {
+ NS_ASSERT(false,
+ "how are we throwing an exception here? we control " +
+ "all the callers! " + e);
+ }
+ }
+ };
+
+ gThreadManager.currentThread.dispatch(event, Ci.nsIThread.DISPATCH_NORMAL);
+ },
+
+ /**
+* Kicks off another wait for more data to be available from the input stream.
+*/
+ _waitToReadData: function()
+ {
+ dumpn("*** _waitToReadData");
+ this._source.asyncWait(this, 0, Response.SEGMENT_SIZE,
+ gThreadManager.mainThread);
+ },
+
+ /**
+* Kicks off another wait until data can be written to the output stream.
+*/
+ _waitToWriteData: function()
+ {
+ dumpn("*** _waitToWriteData");
+
+ var pendingData = this._pendingData;
+ NS_ASSERT(pendingData.length > 0, "no pending data to write?");
+ NS_ASSERT(pendingData[0].length > 0, "buffered an empty write?");
+
+ this._sink.asyncWait(this, 0, pendingData[0].length,
+ gThreadManager.mainThread);
+ },
+
+ /**
+* Kicks off a wait for the sink to which data is being copied to be closed.
+* We wait for stream closure when we don't have any data to be copied, rather
+* than waiting to write a specific amount of data. We can't wait to write
+* data because the sink might be infinitely writable, and if no data appears
+* in the source for a long time we might have to spin quite a bit waiting to
+* write, waiting to write again, &c. Waiting on stream closure instead means
+* we'll get just one notification if the sink dies. Note that when data
+* starts arriving from the sink we'll resume waiting for data to be written,
+* dropping this closure-only callback entirely.
+*/
+ _waitForSinkClosure: function()
+ {
+ dumpn("*** _waitForSinkClosure");
+
+ this._sink.asyncWait(this, Ci.nsIAsyncOutputStream.WAIT_CLOSURE_ONLY, 0,
+ gThreadManager.mainThread);
+ },
+
+ /**
+* Closes input with the given status, if it hasn't already been closed;
+* otherwise a no-op.
+*
+* @param status : nsresult
+* status code use to close the source stream if necessary
+*/
+ _finishSource: function(status)
+ {
+ dumpn("*** _finishSource(" + status.toString(16) + ")");
+
+ if (this._source !== null)
+ {
+ this._source.closeWithStatus(status);
+ this._source = null;
+ }
+ }
+};
+
+
+/**
+* A container for utility functions used with HTTP headers.
+*/
+const headerUtils =
+{
+ /**
+* Normalizes fieldName (by converting it to lowercase) and ensures it is a
+* valid header field name (although not necessarily one specified in RFC
+* 2616).
+*
+* @throws NS_ERROR_INVALID_ARG
+* if fieldName does not match the field-name production in RFC 2616
+* @returns string
+* fieldName converted to lowercase if it is a valid header, for characters
+* where case conversion is possible
+*/
+ normalizeFieldName: function(fieldName)
+ {
+ if (fieldName == "")
+ throw Cr.NS_ERROR_INVALID_ARG;
+
+ for (var i = 0, sz = fieldName.length; i < sz; i++)
+ {
+ if (!IS_TOKEN_ARRAY[fieldName.charCodeAt(i)])
+ {
+ dumpn(fieldName + " is not a valid header field name!");
+ throw Cr.NS_ERROR_INVALID_ARG;
+ }
+ }
+
+ return fieldName.toLowerCase();
+ },
+
+ /**
+* Ensures that fieldValue is a valid header field value (although not
+* necessarily as specified in RFC 2616 if the corresponding field name is
+* part of the HTTP protocol), normalizes the value if it is, and
+* returns the normalized value.
+*
+* @param fieldValue : string
+* a value to be normalized as an HTTP header field value
+* @throws NS_ERROR_INVALID_ARG
+* if fieldValue does not match the field-value production in RFC 2616
+* @returns string
+* fieldValue as a normalized HTTP header field value
+*/
+ normalizeFieldValue: function(fieldValue)
+ {
+ // field-value = *( field-content | LWS )
+ // field-content = <the OCTETs making up the field-value
+ // and consisting of either *TEXT or combinations
+ // of token, separators, and quoted-string>
+ // TEXT = <any OCTET except CTLs,
+ // but including LWS>
+ // LWS = [CRLF] 1*( SP | HT )
+ //
+ // quoted-string = ( <"> *(qdtext | quoted-pair ) <"> )
+ // qdtext = <any TEXT except <">>
+ // quoted-pair = "\" CHAR
+ // CHAR = <any US-ASCII character (octets 0 - 127)>
+
+ // Any LWS that occurs between field-content MAY be replaced with a single
+ // SP before interpreting the field value or forwarding the message
+ // downstream (section 4.2); we replace 1*LWS with a single SP
+ var val = fieldValue.replace(/(?:(?:\r\n)?[ \t]+)+/g, " ");
+
+ // remove leading/trailing LWS (which has been converted to SP)
+ val = val.replace(/^ +/, "").replace(/ +$/, "");
+
+ // that should have taken care of all CTLs, so val should contain no CTLs
+ for (var i = 0, len = val.length; i < len; i++)
+ if (isCTL(val.charCodeAt(i)))
+ throw Cr.NS_ERROR_INVALID_ARG;
+
+ // XXX disallows quoted-pair where CHAR is a CTL -- will not invalidly
+ // normalize, however, so this can be construed as a tightening of the
+ // spec and not entirely as a bug
+ return val;
+ }
+};
+
+
+
+/**
+* Converts the given string into a string which is safe for use in an HTML
+* context.
+*
+* @param str : string
+* the string to make HTML-safe
+* @returns string
+* an HTML-safe version of str
+*/
+function htmlEscape(str)
+{
+ // this is naive, but it'll work
+ var s = "";
+ for (var i = 0; i < str.length; i++)
+ s += "&#" + str.charCodeAt(i) + ";";
+ return s;
+}
+
+
+/**
+* Constructs an object representing an HTTP version (see section 3.1).
+*
+* @param versionString
+* a string of the form "#.#", where # is an non-negative decimal integer with
+* or without leading zeros
+* @throws
+* if versionString does not specify a valid HTTP version number
+*/
+function nsHttpVersion(versionString)
+{
+ var matches = /^(\d+)\.(\d+)$/.exec(versionString);
+ if (!matches)
+ throw "Not a valid HTTP version!";
+
+ /** The major version number of this, as a number. */
+ this.major = parseInt(matches[1], 10);
+
+ /** The minor version number of this, as a number. */
+ this.minor = parseInt(matches[2], 10);
+
+ if (isNaN(this.major) || isNaN(this.minor) ||
+ this.major < 0 || this.minor < 0)
+ throw "Not a valid HTTP version!";
+}
+nsHttpVersion.prototype =
+{
+ /**
+* Returns the standard string representation of the HTTP version represented
+* by this (e.g., "1.1").
+*/
+ toString: function ()
+ {
+ return this.major + "." + this.minor;
+ },
+
+ /**
+* Returns true if this represents the same HTTP version as otherVersion,
+* false otherwise.
+*
+* @param otherVersion : nsHttpVersion
+* the version to compare against this
+*/
+ equals: function (otherVersion)
+ {
+ return this.major == otherVersion.major &&
+ this.minor == otherVersion.minor;
+ },
+
+ /** True if this >= otherVersion, false otherwise. */
+ atLeast: function(otherVersion)
+ {
+ return this.major > otherVersion.major ||
+ (this.major == otherVersion.major &&
+ this.minor >= otherVersion.minor);
+ }
+};
+
+nsHttpVersion.HTTP_1_0 = new nsHttpVersion("1.0");
+nsHttpVersion.HTTP_1_1 = new nsHttpVersion("1.1");
+
+
+/**
+* An object which stores HTTP headers for a request or response.
+*
+* Note that since headers are case-insensitive, this object converts headers to
+* lowercase before storing them. This allows the getHeader and hasHeader
+* methods to work correctly for any case of a header, but it means that the
+* values returned by .enumerator may not be equal case-sensitively to the
+* values passed to setHeader when adding headers to this.
+*/
+function nsHttpHeaders()
+{
+ /**
+* A hash of headers, with header field names as the keys and header field
+* values as the values. Header field names are case-insensitive, but upon
+* insertion here they are converted to lowercase. Header field values are
+* normalized upon insertion to contain no leading or trailing whitespace.
+*
+* Note also that per RFC 2616, section 4.2, two headers with the same name in
+* a message may be treated as one header with the same field name and a field
+* value consisting of the separate field values joined together with a "," in
+* their original order. This hash stores multiple headers with the same name
+* in this manner.
+*/
+ this._headers = {};
+}
+nsHttpHeaders.prototype =
+{
+ /**
+* Sets the header represented by name and value in this.
+*
+* @param name : string
+* the header name
+* @param value : string
+* the header value
+* @throws NS_ERROR_INVALID_ARG
+* if name or value is not a valid header component
+*/
+ setHeader: function(fieldName, fieldValue, merge)
+ {
+ var name = headerUtils.normalizeFieldName(fieldName);
+ var value = headerUtils.normalizeFieldValue(fieldValue);
+
+ // The following three headers are stored as arrays because their real-world
+ // syntax prevents joining individual headers into a single header using
+ // ",". See also <http://hg.mozilla.org/mozilla-central/diff/9b2a99adc05e/netwerk/protocol/http/src/nsHttpHeaderArray.cpp#l77>
+ if (merge && name in this._headers)
+ {
+ if (name === "www-authenticate" ||
+ name === "proxy-authenticate" ||
+ name === "set-cookie")
+ {
+ this._headers[name].push(value);
+ }
+ else
+ {
+ this._headers[name][0] += "," + value;
+ NS_ASSERT(this._headers[name].length === 1,
+ "how'd a non-special header have multiple values?")
+ }
+ }
+ else
+ {
+ this._headers[name] = [value];
+ }
+ },
+
+ /**
+* Returns the value for the header specified by this.
+*
+* @throws NS_ERROR_INVALID_ARG
+* if fieldName does not constitute a valid header field name
+* @throws NS_ERROR_NOT_AVAILABLE
+* if the given header does not exist in this
+* @returns string
+* the field value for the given header, possibly with non-semantic changes
+* (i.e., leading/trailing whitespace stripped, whitespace runs replaced
+* with spaces, etc.) at the option of the implementation; multiple
+* instances of the header will be combined with a comma, except for
+* the three headers noted in the description of getHeaderValues
+*/
+ getHeader: function(fieldName)
+ {
+ return this.getHeaderValues(fieldName).join("\n");
+ },
+
+ /**
+* Returns the value for the header specified by fieldName as an array.
+*
+* @throws NS_ERROR_INVALID_ARG
+* if fieldName does not constitute a valid header field name
+* @throws NS_ERROR_NOT_AVAILABLE
+* if the given header does not exist in this
+* @returns [string]
+* an array of all the header values in this for the given
+* header name. Header values will generally be collapsed
+* into a single header by joining all header values together
+* with commas, but certain headers (Proxy-Authenticate,
+* WWW-Authenticate, and Set-Cookie) violate the HTTP spec
+* and cannot be collapsed in this manner. For these headers
+* only, the returned array may contain multiple elements if
+* that header has been added more than once.
+*/
+ getHeaderValues: function(fieldName)
+ {
+ var name = headerUtils.normalizeFieldName(fieldName);
+
+ if (name in this._headers)
+ return this._headers[name];
+ else
+ throw Cr.NS_ERROR_NOT_AVAILABLE;
+ },
+
+ /**
+* Returns true if a header with the given field name exists in this, false
+* otherwise.
+*
+* @param fieldName : string
+* the field name whose existence is to be determined in this
+* @throws NS_ERROR_INVALID_ARG
+* if fieldName does not constitute a valid header field name
+* @returns boolean
+* true if the header's present, false otherwise
+*/
+ hasHeader: function(fieldName)
+ {
+ var name = headerUtils.normalizeFieldName(fieldName);
+ return (name in this._headers);
+ },
+
+ /**
+* Returns a new enumerator over the field names of the headers in this, as
+* nsISupportsStrings. The names returned will be in lowercase, regardless of
+* how they were input using setHeader (header names are case-insensitive per
+* RFC 2616).
+*/
+ get enumerator()
+ {
+ var headers = [];
+ for (var i in this._headers)
+ {
+ var supports = new SupportsString();
+ supports.data = i;
+ headers.push(supports);
+ }
+
+ return new nsSimpleEnumerator(headers);
+ }
+};
+
+
+/**
+* Constructs an nsISimpleEnumerator for the given array of items.
+*
+* @param items : Array
+* the items, which must all implement nsISupports
+*/
+function nsSimpleEnumerator(items)
+{
+ this._items = items;
+ this._nextIndex = 0;
+}
+nsSimpleEnumerator.prototype =
+{
+ hasMoreElements: function()
+ {
+ return this._nextIndex < this._items.length;
+ },
+ getNext: function()
+ {
+ if (!this.hasMoreElements())
+ throw Cr.NS_ERROR_NOT_AVAILABLE;
+
+ return this._items[this._nextIndex++];
+ },
+ QueryInterface: function(aIID)
+ {
+ if (Ci.nsISimpleEnumerator.equals(aIID) ||
+ Ci.nsISupports.equals(aIID))
+ return this;
+
+ throw Cr.NS_ERROR_NO_INTERFACE;
+ }
+};
+
+
+/**
+* A representation of the data in an HTTP request.
+*
+* @param port : uint
+* the port on which the server receiving this request runs
+*/
+function Request(port)
+{
+ /** Method of this request, e.g. GET or POST. */
+ this._method = "";
+
+ /** Path of the requested resource; empty paths are converted to '/'. */
+ this._path = "";
+
+ /** Query string, if any, associated with this request (not including '?'). */
+ this._queryString = "";
+
+ /** Scheme of requested resource, usually http, always lowercase. */
+ this._scheme = "http";
+
+ /** Hostname on which the requested resource resides. */
+ this._host = undefined;
+
+ /** Port number over which the request was received. */
+ this._port = port;
+
+ var bodyPipe = new Pipe(false, false, 0, PR_UINT32_MAX, null);
+
+ /** Stream from which data in this request's body may be read. */
+ this._bodyInputStream = bodyPipe.inputStream;
+
+ /** Stream to which data in this request's body is written. */
+ this._bodyOutputStream = bodyPipe.outputStream;
+
+ /**
+* The headers in this request.
+*/
+ this._headers = new nsHttpHeaders();
+
+ /**
+* For the addition of ad-hoc properties and new functionality without having
+* to change nsIHttpRequest every time; currently lazily created, as its only
+* use is in directory listings.
+*/
+ this._bag = null;
+}
+Request.prototype =
+{
+ // SERVER METADATA
+
+ //
+ // see nsIHttpRequest.scheme
+ //
+ get scheme()
+ {
+ return this._scheme;
+ },
+
+ //
+ // see nsIHttpRequest.host
+ //
+ get host()
+ {
+ return this._host;
+ },
+
+ //
+ // see nsIHttpRequest.port
+ //
+ get port()
+ {
+ return this._port;
+ },
+
+ // REQUEST LINE
+
+ //
+ // see nsIHttpRequest.method
+ //
+ get method()
+ {
+ return this._method;
+ },
+
+ //
+ // see nsIHttpRequest.httpVersion
+ //
+ get httpVersion()
+ {
+ return this._httpVersion.toString();
+ },
+
+ //
+ // see nsIHttpRequest.path
+ //
+ get path()
+ {
+ return this._path;
+ },
+
+ //
+ // see nsIHttpRequest.queryString
+ //
+ get queryString()
+ {
+ return this._queryString;
+ },
+
+ // HEADERS
+
+ //
+ // see nsIHttpRequest.getHeader
+ //
+ getHeader: function(name)
+ {
+ return this._headers.getHeader(name);
+ },
+
+ //
+ // see nsIHttpRequest.hasHeader
+ //
+ hasHeader: function(name)
+ {
+ return this._headers.hasHeader(name);
+ },
+
+ //
+ // see nsIHttpRequest.headers
+ //
+ get headers()
+ {
+ return this._headers.enumerator;
+ },
+
+ //
+ // see nsIPropertyBag.enumerator
+ //
+ get enumerator()
+ {
+ this._ensurePropertyBag();
+ return this._bag.enumerator;
+ },
+
+ //
+ // see nsIHttpRequest.headers
+ //
+ get bodyInputStream()
+ {
+ return this._bodyInputStream;
+ },
+
+ //
+ // see nsIPropertyBag.getProperty
+ //
+ getProperty: function(name)
+ {
+ this._ensurePropertyBag();
+ return this._bag.getProperty(name);
+ },
+
+
+ // NSISUPPORTS
+
+ //
+ // see nsISupports.QueryInterface
+ //
+ QueryInterface: function(iid)
+ {
+ if (iid.equals(Ci.nsIHttpRequest) || iid.equals(Ci.nsISupports))
+ return this;
+
+ throw Cr.NS_ERROR_NO_INTERFACE;
+ },
+
+
+ // PRIVATE IMPLEMENTATION
+
+ /** Ensures a property bag has been created for ad-hoc behaviors. */
+ _ensurePropertyBag: function()
+ {
+ if (!this._bag)
+ this._bag = new WritablePropertyBag();
+ }
+};
+
+
+// XPCOM trappings
+if ("XPCOMUtils" in this && // Firefox 3.6 doesn't load XPCOMUtils in this scope for some reason...
+ "generateNSGetFactory" in XPCOMUtils) {
+ var NSGetFactory = XPCOMUtils.generateNSGetFactory([nsHttpServer]);
+}
+
+
+
+/**
+* Creates a new HTTP server listening for loopback traffic on the given port,
+* starts it, and runs the server until the server processes a shutdown request,
+* spinning an event loop so that events posted by the server's socket are
+* processed.
+*
+* This method is primarily intended for use in running this script from within
+* xpcshell and running a functional HTTP server without having to deal with
+* non-essential details.
+*
+* Note that running multiple servers using variants of this method probably
+* doesn't work, simply due to how the internal event loop is spun and stopped.
+*
+* @note
+* This method only works with Mozilla 1.9 (i.e., Firefox 3 or trunk code);
+* you should use this server as a component in Mozilla 1.8.
+* @param port
+* the port on which the server will run, or -1 if there exists no preference
+* for a specific port; note that attempting to use some values for this
+* parameter (particularly those below 1024) may cause this method to throw or
+* may result in the server being prematurely shut down
+* @param basePath
+* a local directory from which requests will be served (i.e., if this is
+* "/home/jwalden/" then a request to /index.html will load
+* /home/jwalden/index.html); if this is omitted, only the default URLs in
+* this server implementation will be functional
+*/
+function server(port, basePath)
+{
+ if (basePath)
+ {
+ var lp = Cc["@mozilla.org/file/local;1"]
+ .createInstance(Ci.nsILocalFile);
+ lp.initWithPath(basePath);
+ }
+
+ // if you're running this, you probably want to see debugging info
+ DEBUG = true;
+
+ var srv = new nsHttpServer();
+ if (lp)
+ srv.registerDirectory("/", lp);
+ srv.registerContentType("sjs", SJS_TYPE);
+ srv.identity.setPrimary("http", "localhost", port);
+ srv.start(port);
+
+ var thread = gThreadManager.currentThread;
+ while (!srv.isStopped())
+ thread.processNextEvent(true);
+
+ // get rid of any pending requests
+ while (thread.hasPendingEvents())
+ thread.processNextEvent(true);
+
+ DEBUG = false;
+}
+
+function startServerAsync(port, basePath)
+{
+ if (basePath)
+ {
+ var lp = Cc["@mozilla.org/file/local;1"]
+ .createInstance(Ci.nsILocalFile);
+ lp.initWithPath(basePath);
+ }
+
+ var srv = new nsHttpServer();
+ if (lp)
+ srv.registerDirectory("/", lp);
+ srv.registerContentType("sjs", "sjs");
+ srv.identity.setPrimary("http", "localhost", port);
+ srv.start(port);
+ return srv;
+}
+
+exports.nsHttpServer = nsHttpServer;
+exports.ScriptableInputStream = ScriptableInputStream;
+exports.server = server;
+exports.startServerAsync = startServerAsync;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/keyboard/hotkeys.js b/tools/addon-sdk-1.7/packages/api-utils/lib/keyboard/hotkeys.js
new file mode 100644
index 0000000..bb296ed
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/keyboard/hotkeys.js
@@ -0,0 +1,107 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { observer: keyboardObserver } = require("./observer");
+const { getKeyForCode, normalize, isFunctionKey,
+ MODIFIERS } = require("./utils");
+
+/**
+ * Register a global `hotkey` that executes `listener` when the key combination
+ * in `hotkey` is pressed. If more then one `listener` is registered on the same
+ * key combination only last one will be executed.
+ *
+ * @param {string} hotkey
+ * Key combination in the format of 'modifier key'.
+ *
+ * Examples:
+ *
+ * "accel s"
+ * "meta shift i"
+ * "control alt d"
+ *
+ * Modifier keynames:
+ *
+ * - **shift**: The Shift key.
+ * - **alt**: The Alt key. On the Macintosh, this is the Option key. On
+ * Macintosh this can only be used in conjunction with another modifier,
+ * since `Alt+Letter` combinations are reserved for entering special
+ * characters in text.
+ * - **meta**: The Meta key. On the Macintosh, this is the Command key.
+ * - **control**: The Control key.
+ * - **accel**: The key used for keyboard shortcuts on the user's platform,
+ * which is Control on Windows and Linux, and Command on Mac. Usually, this
+ * would be the value you would use.
+ *
+ * @param {function} listener
+ * Function to execute when the `hotkey` is executed.
+ */
+exports.register = function register(hotkey, listener) {
+ hotkey = normalize(hotkey);
+ hotkeys[hotkey] = listener;
+};
+
+/**
+ * Unregister a global `hotkey`. If passed `listener` is not the one registered
+ * for the given `hotkey`, the call to this function will be ignored.
+ *
+ * @param {string} hotkey
+ * Key combination in the format of 'modifier key'.
+ * @param {function} listener
+ * Function that will be invoked when the `hotkey` is pressed.
+ */
+exports.unregister = function unregister(hotkey, listener) {
+ hotkey = normalize(hotkey);
+ if (hotkeys[hotkey] === listener)
+ delete hotkeys[hotkey];
+};
+
+/**
+ * Map of hotkeys and associated functions.
+ */
+const hotkeys = exports.hotkeys = {};
+
+keyboardObserver.on("keydown", function onKeypress(event, window) {
+ let key, modifiers = [];
+ let isChar = "isChar" in event && event.isChar;
+ let which = "which" in event ? event.which : null;
+ let keyCode = "keyCode" in event ? event.keyCode : null;
+
+ if ("shiftKey" in event && event.shiftKey)
+ modifiers.push("shift");
+ if ("altKey" in event && event.altKey)
+ modifiers.push("alt");
+ if ("ctrlKey" in event && event.ctrlKey)
+ modifiers.push("control");
+ if ("metaKey" in event && event.metaKey)
+ modifiers.push("meta");
+
+ // If it's not a printable character then we fall back to a human readable
+ // equivalent of one of the following constants.
+ // http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/events/nsIDOMKeyEvent.idl
+ key = getKeyForCode(keyCode);
+
+ // If only non-function (f1 - f24) key or only modifiers are pressed we don't
+ // have a valid combination so we return immediately (Also, sometimes
+ // `keyCode` may be one for the modifier which means we do not have a
+ // modifier).
+ if (!key || (!isFunctionKey(key) && !modifiers.length) || key in MODIFIERS)
+ return;
+
+ let combination = normalize({ key: key, modifiers: modifiers });
+ let hotkey = hotkeys[combination];
+
+ if (hotkey) {
+ try {
+ hotkey();
+ } catch (exception) {
+ console.exception(exception);
+ } finally {
+ // Work around bug 582052 by preventing the (nonexistent) default action.
+ event.preventDefault();
+ }
+ }
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/keyboard/observer.js b/tools/addon-sdk-1.7/packages/api-utils/lib/keyboard/observer.js
new file mode 100644
index 0000000..dd24865
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/keyboard/observer.js
@@ -0,0 +1,53 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Trait } = require("../light-traits");
+const { EventEmitterTrait: EventEmitter } = require("../events");
+const { DOMEventAssembler } = require("../events/assembler");
+const { browserWindowIterator, isBrowser } = require('../window-utils');
+const { observer: windowObserver } = require("../windows/observer");
+
+// Event emitter objects used to register listeners and emit events on them
+// when they occur.
+const observer = Trait.compose(DOMEventAssembler, EventEmitter).create({
+ /**
+ * Method is implemented by `EventEmitter` and is used just for emitting
+ * events on registered listeners.
+ */
+ _emit: Trait.required,
+ /**
+ * Events that are supported and emitted by the module.
+ */
+ supportedEventsTypes: [ "keydown", "keyup", "keypress" ],
+ /**
+ * Function handles all the supported events on all the windows that are
+ * observed. Method is used to proxy events to the listeners registered on
+ * this event emitter.
+ * @param {Event} event
+ * Keyboard event being emitted.
+ */
+ handleEvent: function handleEvent(event) {
+ this._emit(event.type, event, event.target.ownerDocument.defaultView);
+ }
+});
+
+// Adding each opened window to a list of observed windows.
+windowObserver.on("open", function onOpen(window) {
+ if (isBrowser(window))
+ observer.observe(window);
+});
+// Removing each closed window form the list of observed windows.
+windowObserver.on("close", function onClose(window) {
+ if (isBrowser(window))
+ observer.ignore(window);
+});
+
+// Making observer aware of already opened windows.
+for each (let window in browserWindowIterator())
+ observer.observe(window);
+
+exports.observer = observer;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/keyboard/utils.js b/tools/addon-sdk-1.7/packages/api-utils/lib/keyboard/utils.js
new file mode 100644
index 0000000..4693a12
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/keyboard/utils.js
@@ -0,0 +1,186 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Cc, Ci } = require("chrome");
+const runtime = require("../runtime");
+const { isString } = require("../type");
+const array = require("../array");
+
+
+const SWP = "{{SEPARATOR}}";
+const SEPARATOR = "-"
+const INVALID_COMBINATION = "Hotkey key combination must contain one or more " +
+ "modifiers and only one key";
+
+// Map of modifier key mappings.
+const MODIFIERS = exports.MODIFIERS = {
+ 'accel': runtime.OS === "Darwin" ? 'meta' : 'control',
+ 'meta': 'meta',
+ 'control': 'control',
+ 'ctrl': 'control',
+ 'option': 'alt',
+ 'command': 'meta',
+ 'alt': 'alt',
+ 'shift': 'shift'
+};
+
+// Hash of key:code pairs for all the chars supported by `nsIDOMKeyEvent`.
+// This is just a copy of the `nsIDOMKeyEvent` hash with normalized names.
+// @See: http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/events/nsIDOMKeyEvent.idl
+const CODES = exports.CODES = new function Codes() {
+ let nsIDOMKeyEvent = Ci.nsIDOMKeyEvent;
+ // Names that will be substituted with a shorter analogs.
+ let aliases = {
+ 'subtract': '-',
+ 'add': '+',
+ 'equals': '=',
+ 'slash': '/',
+ 'backslash': '\\',
+ 'openbracket': '[',
+ 'closebracket': ']',
+ 'quote': '\'',
+ 'backquote': '`',
+ 'period': '.',
+ 'semicolon': ';',
+ 'comma': ','
+ };
+
+ // Normalizing keys and copying values to `this` object.
+ Object.keys(nsIDOMKeyEvent).filter(function(key) {
+ // Filter out only key codes.
+ return key.indexOf('DOM_VK') === 0;
+ }).map(function(key) {
+ // Map to key:values
+ return [ key, nsIDOMKeyEvent[key] ];
+ }).map(function([key, value]) {
+ return [ key.replace('DOM_VK_', '').replace('_', '').toLowerCase(), value ];
+ }).forEach(function ([ key, value ]) {
+ this[aliases[key] || key] = value;
+ }, this);
+};
+
+// Inverted `CODES` hash of `code:key`.
+const KEYS = exports.KEYS = new function Keys() {
+ Object.keys(CODES).forEach(function(key) {
+ this[CODES[key]] = key;
+ }, this)
+}
+
+exports.getKeyForCode = function getKeyForCode(code) {
+ return (code in KEYS) && KEYS[code];
+};
+exports.getCodeForKey = function getCodeForKey(key) {
+ return (key in CODES) && CODES[key];
+};
+
+/**
+ * Utility function that takes string or JSON that defines a `hotkey` and
+ * returns normalized string version of it.
+ * @param {JSON|String} hotkey
+ * @param {String} [separator=" "]
+ * Optional string that represents separator used to concatenate keys in the
+ * given `hotkey`.
+ * @returns {String}
+ * @examples
+ *
+ * require("keyboard/hotkeys").normalize("b Shift accel");
+ * // 'control shift b' -> on windows & linux
+ * // 'meta shift b' -> on mac
+ * require("keyboard/hotkeys").normalize("alt-d-shift", "-");
+ * // 'alt shift d'
+ */
+var normalize = exports.normalize = function normalize(hotkey, separator) {
+ if (!isString(hotkey))
+ hotkey = toString(hotkey, separator);
+ return toString(toJSON(hotkey, separator), separator);
+};
+
+/*
+ * Utility function that splits a string of characters that defines a `hotkey`
+ * into modifier keys and the defining key.
+ * @param {String} hotkey
+ * @param {String} [separator=" "]
+ * Optional string that represents separator used to concatenate keys in the
+ * given `hotkey`.
+ * @returns {JSON}
+ * @examples
+ *
+ * require("keyboard/hotkeys").toJSON("accel shift b");
+ * // { key: 'b', modifiers: [ 'control', 'shift' ] } -> on windows & linux
+ * // { key: 'b', modifiers: [ 'meta', 'shift' ] } -> on mac
+ *
+ * require("keyboard/hotkeys").normalize("alt-d-shift", "-");
+ * // { key: 'd', modifiers: [ 'alt', 'shift' ] }
+ */
+var toJSON = exports.toJSON = function toJSON(hotkey, separator) {
+ separator = separator || SEPARATOR;
+ // Since default separator is `-`, combination may take form of `alt--`. To
+ // avoid misbehavior we replace `--` with `-{{SEPARATOR}}` where
+ // `{{SEPARATOR}}` can be swapped later.
+ hotkey = hotkey.toLowerCase().replace(separator + separator, separator + SWP);
+
+ let value = {};
+ let modifiers = [];
+ let keys = hotkey.split(separator);
+ keys.forEach(function(name) {
+ // If name is `SEPARATOR` than we swap it back.
+ if (name === SWP)
+ name = separator;
+ if (name in MODIFIERS) {
+ array.add(modifiers, MODIFIERS[name]);
+ } else {
+ if (!value.key)
+ value.key = name;
+ else
+ throw new TypeError(INVALID_COMBINATION);
+ }
+ });
+
+ if (!value.key)
+ throw new TypeError(INVALID_COMBINATION);
+
+ value.modifiers = modifiers.sort();
+ return value;
+};
+
+/**
+ * Utility function that takes object that defines a `hotkey` and returns
+ * string representation of it.
+ *
+ * _Please note that this function does not validates data neither it normalizes
+ * it, if you are unsure that data is well formed use `normalize` function
+ * instead.
+ *
+ * @param {JSON} hotkey
+ * @param {String} [separator=" "]
+ * Optional string that represents separator used to concatenate keys in the
+ * given `hotkey`.
+ * @returns {String}
+ * @examples
+ *
+ * require("keyboard/hotkeys").toString({
+ * key: 'b',
+ * modifiers: [ 'control', 'shift' ]
+ * }, '+');
+ * // 'control+shift+b
+ *
+ */
+var toString = exports.toString = function toString(hotkey, separator) {
+ let keys = hotkey.modifiers.slice();
+ keys.push(hotkey.key);
+ return keys.join(separator || SEPARATOR);
+};
+
+/**
+ * Utility function takes `key` name and returns `true` if it's function key
+ * (F1, ..., F24) and `false` if it's not.
+ */
+var isFunctionKey = exports.isFunctionKey = function isFunctionKey(key) {
+ var $
+ return key[0].toLowerCase() === 'f' &&
+ ($ = parseInt(key.substr(1)), 0 < $ && $ < 25);
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/l10n/locale.js b/tools/addon-sdk-1.7/packages/api-utils/lib/l10n/locale.js
new file mode 100644
index 0000000..ed82789
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/l10n/locale.js
@@ -0,0 +1,122 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const prefs = require("preferences-service");
+const { Cu, Cc, Ci } = require("chrome");
+const { Services } = Cu.import("resource://gre/modules/Services.jsm");
+
+
+/**
+ * Gets the currently selected locale for display.
+ * Gets all usable locale that we can use sorted by priority of relevance
+ * @return Array of locales, begins with highest priority
+ */
+const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS";
+const PREF_SELECTED_LOCALE = "general.useragent.locale";
+const PREF_ACCEPT_LANGUAGES = "intl.accept_languages";
+exports.getPreferedLocales = function getPreferedLocales() {
+ let locales = [];
+
+ function addLocale(locale) {
+ locale = locale.toLowerCase();
+ if (locales.indexOf(locale) === -1)
+ locales.push(locale);
+ }
+
+ // Most important locale is OS one. But we use it, only if
+ // "intl.locale.matchOS" pref is set to `true`.
+ // Currently only used for multi-locales mobile builds.
+ // http://mxr.mozilla.org/mozilla-central/source/mobile/android/installer/Makefile.in#46
+ if (prefs.get(PREF_MATCH_OS_LOCALE, false)) {
+ let localeService = Cc["@mozilla.org/intl/nslocaleservice;1"].
+ getService(Ci.nsILocaleService);
+ let osLocale = localeService.getLocaleComponentForUserAgent();
+ addLocale(osLocale);
+ }
+
+ // In some cases, mainly on Fennec and on Linux version,
+ // `general.useragent.locale` is a special 'localized' value, like:
+ // "chrome://global/locale/intl.properties"
+ let browserUiLocale = prefs.getLocalized(PREF_SELECTED_LOCALE, "") ||
+ prefs.get(PREF_SELECTED_LOCALE, "");
+ if (browserUiLocale)
+ addLocale(browserUiLocale);
+
+
+ // Third priority is the list of locales used for web content
+ let contentLocales = prefs.get(PREF_ACCEPT_LANGUAGES, "");
+ if (contentLocales) {
+ // This list is a string of locales seperated by commas.
+ // There is spaces after commas, so strip each item
+ for each(let locale in contentLocales.split(","))
+ addLocale(locale.replace(/(^\s+)|(\s+$)/g, ""));
+ }
+
+ // Finally, we ensure that en-US is the final fallback if it wasn't added
+ addLocale("en-US");
+
+ return locales;
+}
+
+/**
+ * Selects the closest matching locale from a list of locales.
+ *
+ * @param aLocales
+ * An array of available locales
+ * @param aMatchLocales
+ * An array of prefered locales, ordered by priority. Most wanted first.
+ * Locales have to be in lowercase.
+ * If null, uses getPreferedLocales() results
+ * @return the best match for the currently selected locale
+ *
+ * Stolen from http://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/extensions/XPIProvider.jsm
+ */
+exports.findClosestLocale = function findClosestLocale(aLocales, aMatchLocales) {
+
+ aMatchLocales = aMatchLocales || exports.getPreferedLocales();
+
+ // Holds the best matching localized resource
+ let bestmatch = null;
+ // The number of locale parts it matched with
+ let bestmatchcount = 0;
+ // The number of locale parts in the match
+ let bestpartcount = 0;
+
+ for each (let locale in aMatchLocales) {
+ let lparts = locale.split("-");
+ for each (let localized in aLocales) {
+ let found = localized.toLowerCase();
+ // Exact match is returned immediately
+ if (locale == found)
+ return localized;
+
+ let fparts = found.split("-");
+ /* If we have found a possible match and this one isn't any longer
+ then we dont need to check further. */
+ if (bestmatch && fparts.length < bestmatchcount)
+ continue;
+
+ // Count the number of parts that match
+ let maxmatchcount = Math.min(fparts.length, lparts.length);
+ let matchcount = 0;
+ while (matchcount < maxmatchcount &&
+ fparts[matchcount] == lparts[matchcount])
+ matchcount++;
+
+ /* If we matched more than the last best match or matched the same and
+ this locale is less specific than the last best match. */
+ if (matchcount > bestmatchcount ||
+ (matchcount == bestmatchcount && fparts.length < bestpartcount)) {
+ bestmatch = localized;
+ bestmatchcount = matchcount;
+ bestpartcount = fparts.length;
+ }
+ }
+ // If we found a valid match for this locale return it
+ if (bestmatch)
+ return bestmatch;
+ }
+ return null;
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/l10n/plural-rules.js b/tools/addon-sdk-1.7/packages/api-utils/lib/l10n/plural-rules.js
new file mode 100644
index 0000000..c891870
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/l10n/plural-rules.js
@@ -0,0 +1,387 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// This file is automatically generated with /python-lib/plural-rules-generator.py
+// Fetching data from: http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml
+
+// Mapping of short locale name == to == > rule index in following list
+const LOCALES_TO_RULES = {
+ "af": 2,
+ "ak": 3,
+ "am": 3,
+ "ar": 1,
+ "asa": 2,
+ "az": 0,
+ "be": 10,
+ "bem": 2,
+ "bez": 2,
+ "bg": 2,
+ "bh": 3,
+ "bm": 0,
+ "bn": 2,
+ "bo": 0,
+ "br": 19,
+ "brx": 2,
+ "bs": 10,
+ "ca": 2,
+ "cgg": 2,
+ "chr": 2,
+ "cs": 11,
+ "cy": 16,
+ "da": 2,
+ "de": 2,
+ "dv": 2,
+ "dz": 0,
+ "ee": 2,
+ "el": 2,
+ "en": 2,
+ "eo": 2,
+ "es": 2,
+ "et": 2,
+ "eu": 2,
+ "fa": 0,
+ "ff": 4,
+ "fi": 2,
+ "fil": 3,
+ "fo": 2,
+ "fr": 4,
+ "fur": 2,
+ "fy": 2,
+ "ga": 7,
+ "gd": 23,
+ "gl": 2,
+ "gsw": 2,
+ "gu": 2,
+ "guw": 3,
+ "gv": 22,
+ "ha": 2,
+ "haw": 2,
+ "he": 2,
+ "hi": 3,
+ "hr": 10,
+ "hu": 0,
+ "id": 0,
+ "ig": 0,
+ "ii": 0,
+ "is": 2,
+ "it": 2,
+ "iu": 6,
+ "ja": 0,
+ "jmc": 2,
+ "jv": 0,
+ "ka": 0,
+ "kab": 4,
+ "kaj": 2,
+ "kcg": 2,
+ "kde": 0,
+ "kea": 0,
+ "kk": 2,
+ "kl": 2,
+ "km": 0,
+ "kn": 0,
+ "ko": 0,
+ "ksb": 2,
+ "ksh": 20,
+ "ku": 2,
+ "kw": 6,
+ "lag": 17,
+ "lb": 2,
+ "lg": 2,
+ "ln": 3,
+ "lo": 0,
+ "lt": 9,
+ "lv": 5,
+ "mas": 2,
+ "mg": 3,
+ "mk": 15,
+ "ml": 2,
+ "mn": 2,
+ "mo": 8,
+ "mr": 2,
+ "ms": 0,
+ "mt": 14,
+ "my": 0,
+ "nah": 2,
+ "naq": 6,
+ "nb": 2,
+ "nd": 2,
+ "ne": 2,
+ "nl": 2,
+ "nn": 2,
+ "no": 2,
+ "nr": 2,
+ "nso": 3,
+ "ny": 2,
+ "nyn": 2,
+ "om": 2,
+ "or": 2,
+ "pa": 2,
+ "pap": 2,
+ "pl": 12,
+ "ps": 2,
+ "pt": 2,
+ "rm": 2,
+ "ro": 8,
+ "rof": 2,
+ "ru": 10,
+ "rwk": 2,
+ "sah": 0,
+ "saq": 2,
+ "se": 6,
+ "seh": 2,
+ "ses": 0,
+ "sg": 0,
+ "sh": 10,
+ "shi": 18,
+ "sk": 11,
+ "sl": 13,
+ "sma": 6,
+ "smi": 6,
+ "smj": 6,
+ "smn": 6,
+ "sms": 6,
+ "sn": 2,
+ "so": 2,
+ "sq": 2,
+ "sr": 10,
+ "ss": 2,
+ "ssy": 2,
+ "st": 2,
+ "sv": 2,
+ "sw": 2,
+ "syr": 2,
+ "ta": 2,
+ "te": 2,
+ "teo": 2,
+ "th": 0,
+ "ti": 3,
+ "tig": 2,
+ "tk": 2,
+ "tl": 3,
+ "tn": 2,
+ "to": 0,
+ "tr": 0,
+ "ts": 2,
+ "tzm": 21,
+ "uk": 10,
+ "ur": 2,
+ "ve": 2,
+ "vi": 0,
+ "vun": 2,
+ "wa": 3,
+ "wae": 2,
+ "wo": 0,
+ "xh": 2,
+ "xog": 2,
+ "yo": 0,
+ "zh": 0,
+ "zu": 2
+};
+
+// Utility functions for plural rules methods
+function isIn(n, list) list.indexOf(n) !== -1;
+function isBetween(n, start, end) start <= n && n <= end;
+
+// List of all plural rules methods, that maps an integer to the plural form name to use
+const RULES = {
+ "0": function (n) {
+
+ return "other"
+ },
+ "1": function (n) {
+ if ((isBetween((n % 100), 3, 10)))
+ return "few";
+ if (n == 0)
+ return "zero";
+ if ((isBetween((n % 100), 11, 99)))
+ return "many";
+ if (n == 2)
+ return "two";
+ if (n == 1)
+ return "one";
+ return "other"
+ },
+ "2": function (n) {
+ if (n == 1)
+ return "one";
+ return "other"
+ },
+ "3": function (n) {
+ if ((isBetween(n, 0, 1)))
+ return "one";
+ return "other"
+ },
+ "4": function (n) {
+ if ((isBetween(n, 0, 2)) && n != 2)
+ return "one";
+ return "other"
+ },
+ "5": function (n) {
+ if (n == 0)
+ return "zero";
+ if ((n % 10) == 1 && (n % 100) != 11)
+ return "one";
+ return "other"
+ },
+ "6": function (n) {
+ if (n == 2)
+ return "two";
+ if (n == 1)
+ return "one";
+ return "other"
+ },
+ "7": function (n) {
+ if ((isBetween(n, 3, 6)))
+ return "few";
+ if ((isBetween(n, 7, 10)))
+ return "many";
+ if (n == 2)
+ return "two";
+ if (n == 1)
+ return "one";
+ return "other"
+ },
+ "8": function (n) {
+ if (n == 0 || n != 1 && (isBetween((n % 100), 1, 19)))
+ return "few";
+ if (n == 1)
+ return "one";
+ return "other"
+ },
+ "9": function (n) {
+ if ((isBetween((n % 10), 2, 9)) && !(isBetween((n % 100), 11, 19)))
+ return "few";
+ if ((n % 10) == 1 && !(isBetween((n % 100), 11, 19)))
+ return "one";
+ return "other"
+ },
+ "10": function (n) {
+ if ((isBetween((n % 10), 2, 4)) && !(isBetween((n % 100), 12, 14)))
+ return "few";
+ if ((n % 10) == 0 || (isBetween((n % 10), 5, 9)) || (isBetween((n % 100), 11, 14)))
+ return "many";
+ if ((n % 10) == 1 && (n % 100) != 11)
+ return "one";
+ return "other"
+ },
+ "11": function (n) {
+ if ((isBetween(n, 2, 4)))
+ return "few";
+ if (n == 1)
+ return "one";
+ return "other"
+ },
+ "12": function (n) {
+ if ((isBetween((n % 10), 2, 4)) && !(isBetween((n % 100), 12, 14)))
+ return "few";
+ if (n != 1 && (isBetween((n % 10), 0, 1)) || (isBetween((n % 10), 5, 9)) || (isBetween((n % 100), 12, 14)))
+ return "many";
+ if (n == 1)
+ return "one";
+ return "other"
+ },
+ "13": function (n) {
+ if ((isBetween((n % 100), 3, 4)))
+ return "few";
+ if ((n % 100) == 2)
+ return "two";
+ if ((n % 100) == 1)
+ return "one";
+ return "other"
+ },
+ "14": function (n) {
+ if (n == 0 || (isBetween((n % 100), 2, 10)))
+ return "few";
+ if ((isBetween((n % 100), 11, 19)))
+ return "many";
+ if (n == 1)
+ return "one";
+ return "other"
+ },
+ "15": function (n) {
+ if ((n % 10) == 1 && n != 11)
+ return "one";
+ return "other"
+ },
+ "16": function (n) {
+ if (n == 3)
+ return "few";
+ if (n == 0)
+ return "zero";
+ if (n == 6)
+ return "many";
+ if (n == 2)
+ return "two";
+ if (n == 1)
+ return "one";
+ return "other"
+ },
+ "17": function (n) {
+ if (n == 0)
+ return "zero";
+ if ((isBetween(n, 0, 2)) && n != 0 && n != 2)
+ return "one";
+ return "other"
+ },
+ "18": function (n) {
+ if ((isBetween(n, 2, 10)))
+ return "few";
+ if ((isBetween(n, 0, 1)))
+ return "one";
+ return "other"
+ },
+ "19": function (n) {
+ if ((isBetween((n % 10), 3, 4) || ((n % 10) == 9)) && !(isBetween((n % 100), 10, 19) || isBetween((n % 100), 70, 79) || isBetween((n % 100), 90, 99)))
+ return "few";
+ if ((n % 1000000) == 0 && n != 0)
+ return "many";
+ if ((n % 10) == 2 && !isIn((n % 100), [12, 72, 92]))
+ return "two";
+ if ((n % 10) == 1 && !isIn((n % 100), [11, 71, 91]))
+ return "one";
+ return "other"
+ },
+ "20": function (n) {
+ if (n == 0)
+ return "zero";
+ if (n == 1)
+ return "one";
+ return "other"
+ },
+ "21": function (n) {
+ if ((isBetween(n, 0, 1)) || (isBetween(n, 11, 99)))
+ return "one";
+ return "other"
+ },
+ "22": function (n) {
+ if ((isBetween((n % 10), 1, 2)) || (n % 20) == 0)
+ return "one";
+ return "other"
+ },
+ "23": function (n) {
+ if ((isBetween(n, 3, 10) || isBetween(n, 13, 19)))
+ return "few";
+ if (isIn(n, [2, 12]))
+ return "two";
+ if (isIn(n, [1, 11]))
+ return "one";
+ return "other"
+ },
+};
+
+/**
+ * Return a function that gives the plural form name for a given integer
+ * for the specified `locale`
+ * let fun = getRulesForLocale('en');
+ * fun(1) -> 'one'
+ * fun(0) -> 'other'
+ * fun(1000) -> 'other'
+ */
+exports.getRulesForLocale = function getRulesForLocale(locale) {
+ let index = LOCALES_TO_RULES[locale];
+ if (!(index in RULES))
+ throw new Error('Plural form unknown for locale "' + locale + '"');
+ return RULES[index];
+}
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/light-traits.js b/tools/addon-sdk-1.7/packages/api-utils/lib/light-traits.js
new file mode 100644
index 0000000..954d093
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/light-traits.js
@@ -0,0 +1,596 @@
+/* vim:ts=2:sts=2:sw=2:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+// `var` is being used in the module in order to make it reusable in
+// environments in which `let` is not yet supported.
+
+// Shortcut to `Object.prototype.hasOwnProperty.call`.
+// owns(object, name) would be the same as
+// Object.prototype.hasOwnProperty.call(object, name);
+var owns = Function.prototype.call.bind(Object.prototype.hasOwnProperty);
+
+/**
+ * Whether or not given property descriptors are equivalent. They are
+ * equivalent either if both are marked as 'conflict' or 'required' property
+ * or if all the properties of descriptors are equal.
+ * @param {Object} actual
+ * @param {Object} expected
+ */
+function equivalentDescriptors(actual, expected) {
+ return (actual.conflict && expected.conflict) ||
+ (actual.required && expected.required) ||
+ equalDescriptors(actual, expected);
+}
+/**
+ * Whether or not given property descriptors define equal properties.
+ */
+function equalDescriptors(actual, expected) {
+ return actual.get === expected.get &&
+ actual.set === expected.set &&
+ actual.value === expected.value &&
+ !!actual.enumerable === !!expected.enumerable &&
+ !!actual.configurable === !!expected.configurable &&
+ !!actual.writable === !!expected.writable;
+}
+
+// Utilities that throwing exceptions for a properties that are marked
+// as "required" or "conflict" properties.
+function throwConflictPropertyError(name) {
+ throw new Error("Remaining conflicting property: `" + name + "`");
+}
+function throwRequiredPropertyError(name) {
+ throw new Error("Missing required property: `" + name + "`");
+}
+
+/**
+ * Generates custom **required** property descriptor. Descriptor contains
+ * non-standard property `required` that is equal to `true`.
+ * @param {String} name
+ * property name to generate descriptor for.
+ * @returns {Object}
+ * custom property descriptor
+ */
+function RequiredPropertyDescriptor(name) {
+ // Creating function by binding first argument to a property `name` on the
+ // `throwConflictPropertyError` function. Created function is used as a
+ // getter & setter of the created property descriptor. This way we ensure
+ // that we throw exception late (on property access) if object with
+ // `required` property was instantiated using built-in `Object.create`.
+ var accessor = throwRequiredPropertyError.bind(null, name);
+ return { get: accessor, set: accessor, required: true };
+}
+
+/**
+ * Generates custom **conflicting** property descriptor. Descriptor contains
+ * non-standard property `conflict` that is equal to `true`.
+ * @param {String} name
+ * property name to generate descriptor for.
+ * @returns {Object}
+ * custom property descriptor
+ */
+function ConflictPropertyDescriptor(name) {
+ // For details see `RequiredPropertyDescriptor` since idea is same.
+ var accessor = throwConflictPropertyError.bind(null, name);
+ return { get: accessor, set: accessor, conflict: true };
+}
+
+/**
+ * Tests if property is marked as `required` property.
+ */
+function isRequiredProperty(object, name) {
+ return !!object[name].required;
+}
+
+/**
+ * Tests if property is marked as `conflict` property.
+ */
+function isConflictProperty(object, name) {
+ return !!object[name].conflict;
+}
+
+/**
+ * Function tests whether or not method of the `source` object with a given
+ * `name` is inherited from `Object.prototype`.
+ */
+function isBuiltInMethod(name, source) {
+ var target = Object.prototype[name];
+
+ // If methods are equal then we know it's `true`.
+ return target == source ||
+ // If `source` object comes form a different sandbox `==` will evaluate
+ // to `false`, in that case we check if functions names and sources match.
+ (String(target) === String(source) && target.name === source.name);
+}
+
+/**
+ * Function overrides `toString` and `constructor` methods of a given `target`
+ * object with a same-named methods of a given `source` if methods of `target`
+ * object are inherited / copied from `Object.prototype`.
+ * @see create
+ */
+function overrideBuiltInMethods(target, source) {
+ if (isBuiltInMethod("toString", target.toString)) {
+ Object.defineProperty(target, "toString", {
+ value: source.toString,
+ configurable: true,
+ enumerable: false
+ });
+ }
+
+ if (isBuiltInMethod("constructor", target.constructor)) {
+ Object.defineProperty(target, "constructor", {
+ value: source.constructor,
+ configurable: true,
+ enumerable: false
+ });
+ }
+}
+
+/**
+ * Composes new trait with the same own properties as the original trait,
+ * except that all property names appearing in the first argument are replaced
+ * by "required" property descriptors.
+ * @param {String[]} keys
+ * Array of strings property names.
+ * @param {Object} trait
+ * A trait some properties of which should be excluded.
+ * @returns {Object}
+ * @example
+ * var newTrait = exclude(["name", ...], trait)
+ */
+function exclude(names, trait) {
+ var map = {};
+
+ Object.keys(trait).forEach(function(name) {
+
+ // If property is not excluded (the array of names does not contain it),
+ // or it is a "required" property, copy it to the property descriptor `map`
+ // that will be used for creation of resulting trait.
+ if (!~names.indexOf(name) || isRequiredProperty(trait, name))
+ map[name] = { value: trait[name], enumerable: true };
+
+ // For all the `names` in the exclude name array we create required
+ // property descriptors and copy them to the `map`.
+ else
+ map[name] = { value: RequiredPropertyDescriptor(name), enumerable: true };
+ });
+
+ return Object.create(Trait.prototype, map);
+}
+
+/**
+ * Composes new instance of `Trait` with a properties of a given `trait`,
+ * except that all properties whose name is an own property of `renames` will
+ * be renamed to `renames[name]` and a `"required"` property for name will be
+ * added instead.
+ *
+ * For each renamed property, a required property is generated. If
+ * the `renames` map two properties to the same name, a conflict is generated.
+ * If the `renames` map a property to an existing unrenamed property, a
+ * conflict is generated.
+ *
+ * @param {Object} renames
+ * An object whose own properties serve as a mapping from old names to new
+ * names.
+ * @param {Object} trait
+ * A new trait with renamed properties.
+ * @returns {Object}
+ * @example
+ *
+ * // Return trait with `bar` property equal to `trait.foo` and with
+ * // `foo` and `baz` "required" properties.
+ * var renamedTrait = rename({ foo: "bar", baz: null }), trait);
+ *
+ * // t1 and t2 are equivalent traits
+ * var t1 = rename({a: "b"}, t);
+ * var t2 = compose(exclude(["a"], t), { a: { required: true }, b: t[a] });
+ */
+function rename(renames, trait) {
+ var map = {};
+
+ // Loop over all the properties of the given `trait` and copy them to a
+ // property descriptor `map` that will be used for the creation of the
+ // resulting trait. Also, rename properties in the `map` as specified by
+ // `renames`.
+ Object.keys(trait).forEach(function(name) {
+ var alias;
+
+ // If the property is in the `renames` map, and it isn't a "required"
+ // property (which should never need to be aliased because "required"
+ // properties never conflict), then we must try to rename it.
+ if (owns(renames, name) && !isRequiredProperty(trait, name)) {
+ alias = renames[name];
+
+ // If the `map` already has the `alias`, and it isn't a "required"
+ // property, that means the `alias` conflicts with an existing name for a
+ // provided trait (that can happen if >=2 properties are aliased to the
+ // same name). In this case we mark it as a conflicting property.
+ // Otherwise, everything is fine, and we copy property with an `alias`
+ // name.
+ if (owns(map, alias) && !map[alias].value.required) {
+ map[alias] = {
+ value: ConflictPropertyDescriptor(alias),
+ enumerable: true
+ };
+ }
+ else {
+ map[alias] = {
+ value: trait[name],
+ enumerable: true
+ };
+ }
+
+ // Regardless of whether or not the rename was successful, we check to
+ // see if the original `name` exists in the map (such a property
+ // could exist if previous another property was aliased to this `name`).
+ // If it isn't, we mark it as "required", to make sure the caller
+ // provides another value for the old name, which methods of the trait
+ // might continue to reference.
+ if (!owns(map, name)) {
+ map[name] = {
+ value: RequiredPropertyDescriptor(name),
+ enumerable: true
+ };
+ }
+ }
+
+ // Otherwise, either the property isn't in the `renames` map (thus the
+ // caller is not trying to rename it) or it is a "required" property.
+ // Either way, we don't have to alias the property, we just have to copy it
+ // to the map.
+ else {
+ // The property isn't in the map yet, so we copy it over.
+ if (!owns(map, name)) {
+ map[name] = { value: trait[name], enumerable: true };
+ }
+
+ // The property is already in the map (that means another property was
+ // aliased with this `name`, which creates a conflict if the property is
+ // not marked as "required"), so we have to mark it as a "conflict"
+ // property.
+ else if (!isRequiredProperty(trait, name)) {
+ map[name] = {
+ value: ConflictPropertyDescriptor(name),
+ enumerable: true
+ };
+ }
+ }
+ });
+ return Object.create(Trait.prototype, map);
+}
+
+/**
+ * Composes new resolved trait, with all the same properties as the original
+ * `trait`, except that all properties whose name is an own property of
+ * `resolutions` will be renamed to `resolutions[name]`.
+ *
+ * If `resolutions[name]` is `null`, the value is mapped to a property
+ * descriptor that is marked as a "required" property.
+ */
+function resolve(resolutions, trait) {
+ var renames = {};
+ var exclusions = [];
+
+ // Go through each mapping in `resolutions` object and distribute it either
+ // to `renames` or `exclusions`.
+ Object.keys(resolutions).forEach(function(name) {
+
+ // If `resolutions[name]` is a truthy value then it's a mapping old -> new
+ // so we copy it to `renames` map.
+ if (resolutions[name])
+ renames[name] = resolutions[name];
+
+ // Otherwise it's not a mapping but an exclusion instead in which case we
+ // add it to the `exclusions` array.
+ else
+ exclusions.push(name);
+ });
+
+ // First `exclude` **then** `rename` and order is important since
+ // `exclude` and `rename` are not associative.
+ return rename(renames, exclude(exclusions, trait));
+}
+
+/**
+ * Create a Trait (a custom property descriptor map) that represents the given
+ * `object`'s own properties. Property descriptor map is a "custom", because it
+ * inherits from `Trait.prototype` and it's property descriptors may contain
+ * two attributes that is not part of the ES5 specification:
+ *
+ * - "required" (this property must be provided by another trait
+ * before an instance of this trait can be created)
+ * - "conflict" (when the trait is composed with another trait,
+ * a unique value for this property is provided by two or more traits)
+ *
+ * Data properties bound to the `Trait.required` singleton exported by
+ * this module will be marked as "required" properties.
+ *
+ * @param {Object} object
+ * Map of properties to compose trait from.
+ * @returns {Trait}
+ * Trait / Property descriptor map containing all the own properties of the
+ * given argument.
+ */
+function trait(object) {
+ var map;
+ var trait = object;
+
+ if (!(object instanceof Trait)) {
+ // If the passed `object` is not already an instance of `Trait`, we create
+ // a property descriptor `map` containing descriptors for the own properties
+ // of the given `object`. `map` is then used to create a `Trait` instance
+ // after all properties are mapped. Note that we can't create a trait and
+ // then just copy properties into it since that will fail for inherited
+ // read-only properties.
+ map = {};
+
+ // Each own property of the given `object` is mapped to a data property
+ // whose value is a property descriptor.
+ Object.keys(object).forEach(function (name) {
+
+ // If property of an `object` is equal to a `Trait.required`, it means
+ // that it was marked as "required" property, in which case we map it
+ // to "required" property.
+ if (Trait.required ==
+ Object.getOwnPropertyDescriptor(object, name).value) {
+ map[name] = {
+ value: RequiredPropertyDescriptor(name),
+ enumerable: true
+ };
+ }
+ // Otherwise property is mapped to it's property descriptor.
+ else {
+ map[name] = {
+ value: Object.getOwnPropertyDescriptor(object, name),
+ enumerable: true
+ };
+ }
+ });
+
+ trait = Object.create(Trait.prototype, map);
+ }
+ return trait;
+}
+
+/**
+ * Compose a property descriptor map that inherits from `Trait.prototype` and
+ * contains property descriptors for all the own properties of the passed
+ * traits.
+ *
+ * If two or more traits have own properties with the same name, the returned
+ * trait will contain a "conflict" property for that name. Composition is a
+ * commutative and associative operation, and the order of its arguments is
+ * irrelevant.
+ */
+function compose(trait1, trait2/*, ...*/) {
+ // Create a new property descriptor `map` to which all the own properties
+ // of the passed traits are copied. This map will be used to create a `Trait`
+ // instance that will be the result of this composition.
+ var map = {};
+
+ // Properties of each passed trait are copied to the composition.
+ Array.prototype.forEach.call(arguments, function(trait) {
+ // Copying each property of the given trait.
+ Object.keys(trait).forEach(function(name) {
+
+ // If `map` already owns a property with the `name` and it is not
+ // marked "required".
+ if (owns(map, name) && !map[name].value.required) {
+
+ // If the source trait's property with the `name` is marked as
+ // "required", we do nothing, as the requirement was already resolved
+ // by a property in the `map` (because it already contains a
+ // non-required property with that `name`). But if properties are just
+ // different, we have a name clash and we substitute it with a property
+ // that is marked "conflict".
+ if (!isRequiredProperty(trait, name) &&
+ !equivalentDescriptors(map[name].value, trait[name])
+ ) {
+ map[name] = {
+ value: ConflictPropertyDescriptor(name),
+ enumerable: true
+ };
+ }
+ }
+
+ // Otherwise, the `map` does not have an own property with the `name`, or
+ // it is marked "required". Either way, the trait's property is copied to
+ // the map (if the property of the `map` is marked "required", it is going
+ // to be resolved by the property that is being copied).
+ else {
+ map[name] = { value: trait[name], enumerable: true };
+ }
+ });
+ });
+
+ return Object.create(Trait.prototype, map);
+}
+
+/**
+ * `defineProperties` is like `Object.defineProperties`, except that it
+ * ensures that:
+ * - An exception is thrown if any property in a given `properties` map
+ * is marked as "required" property and same named property is not
+ * found in a given `prototype`.
+ * - An exception is thrown if any property in a given `properties` map
+ * is marked as "conflict" property.
+ * @param {Object} object
+ * Object to define properties on.
+ * @param {Object} properties
+ * Properties descriptor map.
+ * @returns {Object}
+ * `object` that was passed as a first argument.
+ */
+function defineProperties(object, properties) {
+
+ // Create a map into which we will copy each verified property from the given
+ // `properties` description map. We use it to verify that none of the
+ // provided properties is marked as a "conflict" property and that all
+ // "required" properties are resolved by a property of an `object`, so we
+ // can throw an exception before mutating object if that isn't the case.
+ var verifiedProperties = {};
+
+ // Coping each property from a given `properties` descriptor map to a
+ // verified map of property descriptors.
+ Object.keys(properties).forEach(function(name) {
+
+ // If property is marked as "required" property and we don't have a same
+ // named property in a given `object` we throw an exception. If `object`
+ // has same named property just skip this property since required property
+ // is was inherited and there for requirement was satisfied.
+ if (isRequiredProperty(properties, name)) {
+ if (!(name in object))
+ throwRequiredPropertyError(name);
+ }
+
+ // If property is marked as "conflict" property we throw an exception.
+ else if (isConflictProperty(properties, name)) {
+ throwConflictPropertyError(name);
+ }
+
+ // If property is not marked neither as "required" nor "conflict" property
+ // we copy it to verified properties map.
+ else {
+ verifiedProperties[name] = properties[name];
+ }
+ });
+
+ // If no exceptions were thrown yet, we know that our verified property
+ // descriptor map has no properties marked as "conflict" or "required",
+ // so we just delegate to the built-in `Object.defineProperties`.
+ return Object.defineProperties(object, verifiedProperties);
+}
+
+/**
+ * `create` is like `Object.create`, except that it ensures that:
+ * - An exception is thrown if any property in a given `properties` map
+ * is marked as "required" property and same named property is not
+ * found in a given `prototype`.
+ * - An exception is thrown if any property in a given `properties` map
+ * is marked as "conflict" property.
+ * @param {Object} prototype
+ * prototype of the composed object
+ * @param {Object} properties
+ * Properties descriptor map.
+ * @returns {Object}
+ * An object that inherits form a given `prototype` and implements all the
+ * properties defined by a given `properties` descriptor map.
+ */
+function create(prototype, properties) {
+
+ // Creating an instance of the given `prototype`.
+ var object = Object.create(prototype);
+
+ // Overriding `toString`, `constructor` methods if they are just inherited
+ // from `Object.prototype` with a same named methods of the `Trait.prototype`
+ // that will have more relevant behavior.
+ overrideBuiltInMethods(object, Trait.prototype);
+
+ // Trying to define given `properties` on the `object`. We use our custom
+ // `defineProperties` function instead of build-in `Object.defineProperties`
+ // that behaves exactly the same, except that it will throw if any
+ // property in the given `properties` descriptor is marked as "required" or
+ // "conflict" property.
+ return defineProperties(object, properties);
+}
+
+/**
+ * Composes new trait. If two or more traits have own properties with the
+ * same name, the new trait will contain a "conflict" property for that name.
+ * "compose" is a commutative and associative operation, and the order of its
+ * arguments is not significant.
+ *
+ * **Note:** Use `Trait.compose` instead of calling this function with more
+ * than one argument. The multiple-argument functionality is strictly for
+ * backward compatibility.
+ *
+ * @params {Object} trait
+ * Takes traits as an arguments
+ * @returns {Object}
+ * New trait containing the combined own properties of all the traits.
+ * @example
+ * var newTrait = compose(trait_1, trait_2, ..., trait_N)
+ */
+function Trait(trait1, trait2) {
+
+ // If the function was called with one argument, the argument should be
+ // an object whose properties are mapped to property descriptors on a new
+ // instance of Trait, so we delegate to the trait function.
+ // If the function was called with more than one argument, those arguments
+ // should be instances of Trait or plain property descriptor maps
+ // whose properties should be mixed into a new instance of Trait,
+ // so we delegate to the compose function.
+
+ return trait2 === undefined ? trait(trait1) : compose.apply(null, arguments);
+}
+
+Object.freeze(Object.defineProperties(Trait.prototype, {
+ toString: {
+ value: function toString() {
+ return "[object " + this.constructor.name + "]";
+ }
+ },
+
+ /**
+ * `create` is like `Object.create`, except that it ensures that:
+ * - An exception is thrown if this trait defines a property that is
+ * marked as required property and same named property is not
+ * found in a given `prototype`.
+ * - An exception is thrown if this trait contains property that is
+ * marked as "conflict" property.
+ * @param {Object}
+ * prototype of the compared object
+ * @returns {Object}
+ * An object with all of the properties described by the trait.
+ */
+ create: {
+ value: function createTrait(prototype) {
+ return create(undefined === prototype ? Object.prototype : prototype,
+ this);
+ },
+ enumerable: true
+ },
+
+ /**
+ * Composes a new resolved trait, with all the same properties as the original
+ * trait, except that all properties whose name is an own property of
+ * `resolutions` will be renamed to the value of `resolutions[name]`. If
+ * `resolutions[name]` is `null`, the property is marked as "required".
+ * @param {Object} resolutions
+ * An object whose own properties serve as a mapping from old names to new
+ * names, or to `null` if the property should be excluded.
+ * @returns {Object}
+ * New trait with the same own properties as the original trait but renamed.
+ */
+ resolve: {
+ value: function resolveTrait(resolutions) {
+ return resolve(resolutions, this);
+ },
+ enumerable: true
+ }
+}));
+
+/**
+ * @see compose
+ */
+Trait.compose = Object.freeze(compose);
+Object.freeze(compose.prototype);
+
+/**
+ * Constant singleton, representing placeholder for required properties.
+ * @type {Object}
+ */
+Trait.required = Object.freeze(Object.create(Object.prototype, {
+ toString: {
+ value: Object.freeze(function toString() {
+ return "<Trait.required>";
+ })
+ }
+}));
+Object.freeze(Trait.required.toString.prototype);
+
+exports.Trait = Object.freeze(Trait);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/list.js b/tools/addon-sdk-1.7/packages/api-utils/lib/list.js
new file mode 100644
index 0000000..4c6c126
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/list.js
@@ -0,0 +1,114 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const { Trait } = require('./traits');
+
+/**
+ * @see https://jetpack.mozillalabs.com/sdk/latest/docs/#module/api-utils/list
+ */
+const Iterable = Trait.compose({
+ /**
+ * Hash map of key-values to iterate over.
+ * Note: That this property can be a getter if you need dynamic behavior.
+ * @type {Object}
+ */
+ _keyValueMap: Trait.required,
+ /**
+ * Custom iterator providing `Iterable`s enumeration behavior.
+ * @param {Boolean} onKeys
+ */
+ __iterator__: function __iterator__(onKeys, onKeyValue) {
+ let map = this._keyValueMap;
+ for (let key in map)
+ yield onKeyValue ? [key, map[key]] : onKeys ? key : map[key];
+ }
+});
+exports.Iterable = Iterable;
+
+/**
+ * An ordered collection (also known as a sequence) disallowing duplicate
+ * elements. List is composed out of `Iterable` there for it provides custom
+ * enumeration behavior that is similar to array (enumerates only on the
+ * elements of the list). List is a base trait and is meant to be a part of
+ * composition, since all of it's API is private except length property.
+ */
+const List = Trait.resolve({ toString: null }).compose({
+ _keyValueMap: null,
+ /**
+ * List constructor can take any number of element to populate itself.
+ * @params {Object|String|Number} element
+ * @example
+ * List(1,2,3).length == 3 // true
+ */
+ constructor: function List() {
+ this._keyValueMap = [];
+ for (let i = 0, ii = arguments.length; i < ii; i++)
+ this._add(arguments[i]);
+ },
+ /**
+ * Number of elements in this list.
+ * @type {Number}
+ */
+ get length() this._keyValueMap.length,
+ /**
+ * Returns a string representing this list.
+ * @returns {String}
+ */
+ toString: function toString() 'List(' + this._keyValueMap + ')',
+ /**
+ * Returns `true` if this list contains the specified `element`.
+ * @param {Object|Number|String} element
+ * @returns {Boolean}
+ */
+ _has: function _has(element) 0 <= this._keyValueMap.indexOf(element),
+ /**
+ * Appends the specified `element` to the end of this list, if it doesn't
+ * contains it. Ignores the call if `element` is already contained.
+ * @param {Object|Number|String} element
+ */
+ _add: function _add(element) {
+ let list = this._keyValueMap,
+ index = list.indexOf(element);
+ if (0 > index)
+ list.push(this._public[list.length] = element);
+ },
+ /**
+ * Removes specified `element` from this list, if it contains it.
+ * Ignores the call if `element` is not contained.
+ * @param {Object|Number|String} element
+ */
+ _remove: function _remove(element) {
+ let list = this._keyValueMap,
+ index = list.indexOf(element);
+ if (0 <= index) {
+ delete this._public[list.length - 1];
+ list.splice(index, 1);
+ for (let length = list.length; index < length; index++)
+ this._public[index] = list[index];
+ }
+ },
+ /**
+ * Removes all of the elements from this list.
+ */
+ _clear: function _clear() {
+ for (let i = 0, ii = this._keyValueMap.length; i < ii; i ++)
+ delete this._public[i];
+ this._keyValueMap.splice(0);
+ },
+ /**
+ * Custom iterator providing `List`s enumeration behavior.
+ * We cant reuse `_iterator` that is defined by `Iterable` since it provides
+ * iteration in an arbitrary order.
+ * @see https://developer.mozilla.org/en/JavaScript/Reference/Statements/for...in
+ * @param {Boolean} onKeys
+ */
+ __iterator__: function __iterator__(onKeys, onKeyValue) {
+ let array = this._keyValueMap.slice(0),
+ i = -1;
+ for each(let element in array)
+ yield onKeyValue ? [++i, element] : onKeys ? ++i : element;
+ }
+});
+exports.List = List;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/match-pattern.js b/tools/addon-sdk-1.7/packages/api-utils/lib/match-pattern.js
new file mode 100644
index 0000000..60753d2
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/match-pattern.js
@@ -0,0 +1,103 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+const { URL } = require("./url");
+
+exports.MatchPattern = MatchPattern;
+
+function MatchPattern(pattern) {
+ if (typeof pattern.test == "function") {
+
+ // For compatibility with -moz-document rules, we require the RegExp's
+ // global, ignoreCase, and multiline flags to be set to false.
+ if (pattern.global) {
+ throw new Error("A RegExp match pattern cannot be set to `global` " +
+ "(i.e. //g).");
+ }
+ if (pattern.ignoreCase) {
+ throw new Error("A RegExp match pattern cannot be set to `ignoreCase` " +
+ "(i.e. //i).");
+ }
+ if (pattern.multiline) {
+ throw new Error("A RegExp match pattern cannot be set to `multiline` " +
+ "(i.e. //m).");
+ }
+
+ this.regexp = pattern;
+ }
+ else {
+ let firstWildcardPosition = pattern.indexOf("*");
+ let lastWildcardPosition = pattern.lastIndexOf("*");
+ if (firstWildcardPosition != lastWildcardPosition)
+ throw new Error("There can be at most one '*' character in a wildcard.");
+
+ if (firstWildcardPosition == 0) {
+ if (pattern.length == 1)
+ this.anyWebPage = true;
+ else if (pattern[1] != ".")
+ throw new Error("Expected a *.<domain name> string, got: " + pattern);
+ else
+ this.domain = pattern.substr(2);
+ }
+ else {
+ if (pattern.indexOf(":") == -1) {
+ throw new Error("When not using *.example.org wildcard, the string " +
+ "supplied is expected to be either an exact URL to " +
+ "match or a URL prefix. The provided string ('" +
+ pattern + "') is unlikely to match any pages.");
+ }
+
+ if (firstWildcardPosition == -1)
+ this.exactURL = pattern;
+ else if (firstWildcardPosition == pattern.length - 1)
+ this.urlPrefix = pattern.substr(0, pattern.length - 1);
+ else {
+ throw new Error("The provided wildcard ('" + pattern + "') has a '*' " +
+ "in an unexpected position. It is expected to be the " +
+ "first or the last character in the wildcard.");
+ }
+ }
+ }
+}
+
+MatchPattern.prototype = {
+
+ test: function MatchPattern_test(urlStr) {
+ try {
+ var url = URL(urlStr);
+ }
+ catch (err) {
+ return false;
+ }
+
+ // Test the URL against a RegExp pattern. For compatibility with
+ // -moz-document rules, we require the RegExp to match the entire URL,
+ // so we not only test for a match, we also make sure the matched string
+ // is the entire URL string.
+ //
+ // Assuming most URLs don't match most match patterns, we call `test` for
+ // speed when determining whether or not the URL matches, then call `exec`
+ // for the small subset that match to make sure the entire URL matches.
+ //
+ if (this.regexp && this.regexp.test(urlStr) &&
+ this.regexp.exec(urlStr)[0] == urlStr)
+ return true;
+
+ if (this.anyWebPage && /^(https?|ftp)$/.test(url.scheme))
+ return true;
+ if (this.exactURL && this.exactURL == urlStr)
+ return true;
+ if (this.domain && url.host &&
+ url.host.slice(-this.domain.length) == this.domain)
+ return true;
+ if (this.urlPrefix && 0 == urlStr.indexOf(this.urlPrefix))
+ return true;
+
+ return false;
+ }
+
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/memory.js b/tools/addon-sdk-1.7/packages/api-utils/lib/memory.js
new file mode 100644
index 0000000..be84969
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/memory.js
@@ -0,0 +1,114 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {Cc,Ci,Cu,components} = require("chrome");
+var trackedObjects = {};
+
+var Compacter = {
+ INTERVAL: 5000,
+ notify: function(timer) {
+ var newTrackedObjects = {};
+ for (let name in trackedObjects) {
+ var oldBin = trackedObjects[name];
+ var newBin = [];
+ var strongRefs = [];
+ for (var i = 0; i < oldBin.length; i++) {
+ var strongRef = oldBin[i].weakref.get();
+ if (strongRef && strongRefs.indexOf(strongRef) == -1) {
+ strongRefs.push(strongRef);
+ newBin.push(oldBin[i]);
+ }
+ }
+ if (newBin.length)
+ newTrackedObjects[name] = newBin;
+ }
+ trackedObjects = newTrackedObjects;
+ }
+};
+
+var timer = Cc["@mozilla.org/timer;1"]
+ .createInstance(Ci.nsITimer);
+
+timer.initWithCallback(Compacter,
+ Compacter.INTERVAL,
+ Ci.nsITimer.TYPE_REPEATING_SLACK);
+
+var track = exports.track = function track(object, bin, stackFrameNumber) {
+ var frame = components.stack.caller;
+ var weakref = Cu.getWeakReference(object);
+ if (!bin && 'constructor' in object)
+ bin = object.constructor.name;
+ if (bin == "Object")
+ bin = frame.name;
+ if (!bin)
+ bin = "generic";
+ if (!(bin in trackedObjects))
+ trackedObjects[bin] = [];
+
+ if (stackFrameNumber > 0)
+ for (var i = 0; i < stackFrameNumber; i++)
+ frame = frame.caller;
+
+ trackedObjects[bin].push({weakref: weakref,
+ created: new Date(),
+ filename: frame.filename,
+ lineNo: frame.lineNumber,
+ bin: bin});
+};
+
+var getBins = exports.getBins = function getBins() {
+ var names = [];
+ for (let name in trackedObjects)
+ names.push(name);
+ return names;
+};
+
+var getObjects = exports.getObjects = function getObjects(bin) {
+ function getLiveObjectsInBin(bin, array) {
+ for (var i = 0; i < bin.length; i++) {
+ var object = bin[i].weakref.get();
+ if (object)
+ array.push(bin[i]);
+ }
+ }
+
+ var results = [];
+ if (bin) {
+ if (bin in trackedObjects)
+ getLiveObjectsInBin(trackedObjects[bin], results);
+ } else
+ for (let name in trackedObjects)
+ getLiveObjectsInBin(trackedObjects[name], results);
+ return results;
+};
+
+var gc = exports.gc = function gc() {
+ // Components.utils.forceGC() doesn't currently perform
+ // cycle collection, which means that e.g. DOM elements
+ // won't be collected by it. Fortunately, there are
+ // other ways...
+
+ var window = Cc["@mozilla.org/appshell/appShellService;1"]
+ .getService(Ci.nsIAppShellService)
+ .hiddenDOMWindow;
+ var test_utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindowUtils);
+ test_utils.garbageCollect();
+ Compacter.notify();
+
+ // Not sure why, but sometimes it appears that we don't get
+ // them all with just one CC, so let's do it again.
+ test_utils.garbageCollect();
+};
+
+require("./unload").when(
+ function() {
+ trackedObjects = {};
+ if (timer) {
+ timer.cancel();
+ timer = null;
+ }
+ });
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/message-manager.js b/tools/addon-sdk-1.7/packages/api-utils/lib/message-manager.js
new file mode 100644
index 0000000..235586f
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/message-manager.js
@@ -0,0 +1,203 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const BAD_LISTENER = "The event listener must be a function.";
+
+const { Cc, Ci, Cu, CC } = require("chrome");
+const { setTimeout } = require("./timer");
+
+const { ns } = require("./namespace");
+
+const { curry, invoke } = require("./functional");
+
+const Sandbox = require("./sandbox");
+
+// JSON.stringify is buggy with cross-sandbox values,
+// it may return "{}" on functions. Use a replacer to match them correctly.
+const jsonFixer = function (k, v) typeof v === "function" ? undefined : v;
+
+/**
+ * Defers invoking the function until the current call stack has cleared.
+ *
+ * @param {Function} fn
+ * The function to defer.
+ *
+ * @returns {Function}
+ * The deferred function
+ */
+const defer = function(fn) function() {
+ setTimeout(invoke, 0, fn, arguments, this)
+};
+
+/**
+ * Adds a message listener.
+ * This listener will receive messages sent from the remote frame.
+ *
+ * @param {String} name
+ * The name of the message for which to add a listener.
+ * @param {Function} listener
+ * The listener function called when the message is received.
+ */
+function addMessageListener(name, listener) {
+ if (typeof listener !== "function")
+ throw new Error(BAD_LISTENER);
+
+ let listeners = frame(this).listeners;
+
+ if (name in listeners) {
+ if (~listeners[name].indexOf(listener))
+ return;
+ } else {
+ listeners[name] = [];
+ }
+
+ listeners[name].push(listener);
+}
+
+/**
+ * Removes a message listener previously added by calling addMessageListener.
+ *
+ * @param {String} name
+ * The name of the message for which to remove a listener.
+ * @param {Function} listener
+ * The listener function has to be removed.
+ */
+function removeMessageListener(name, listener) {
+ if (typeof listener !== "function")
+ throw new Error(BAD_LISTENER);
+
+ let listeners = frame(this).listeners;
+
+ if (!(name in listeners))
+ return;
+
+ let index = listeners[name].indexOf(listener);
+
+ if (~index) {
+ listeners[name].splice(index, 1);
+ }
+}
+
+/**
+ * Sends a message to the listeners.
+ *
+ * @param {Boolean} sync
+ * Indicates if the call is synchronous or asynchronous
+ * @param {String} name
+ * The name of the message to send to the listeners.
+ * @param {Object} [data=null]
+ * A JSON object containing data to be delivered to the listeners.
+ *
+ * @returns {Array|undefined}
+ * An array with the return values of the listeners if `sync` is `true`,
+ * otherwise `undefined`.
+ */
+function sendMessage(sync, name, data) {
+ typeof data === "undefined" && (data = null);
+
+ let listeners = frame(frame(this).receiver).listeners;
+
+ let responses = [];
+
+ let returnValue = sync ? responses : undefined;
+
+ if (!(name in listeners))
+ return returnValue;
+
+ let json = JSON.parse(JSON.stringify(data, jsonFixer));
+
+ for each(let listener in listeners[name]) {
+ try {
+ let response = listener.call(null, {
+ sync : sync,
+ name : name,
+ json : json,
+ target : null
+ });
+
+ if (sync) {
+ if (typeof response === "undefined")
+ responses.push(response);
+ else
+ responses.push(JSON.parse(JSON.stringify(response, jsonFixer)));
+ }
+
+ } catch (e) {
+ console.exception(e);
+ }
+ }
+ return returnValue;
+};
+
+let sendSyncMessage = curry(sendMessage, true);
+let sendAsyncMessage = curry(defer(sendMessage), false);
+
+let frame = ns({receiver: null, listeners: null});
+
+/**
+ * The MessageManager object emulates the Message Manager API, without creating
+ * new processes. It useful in mono process context, like Fennec.
+ *
+ * @see
+ * https://developer.mozilla.org/en/The_message_manager
+ */
+function MessageManager() {
+
+ let sandbox = Sandbox.sandbox(null, { wantXrays : false });
+
+ Object.defineProperties(sandbox, {
+ addMessageListener: {value: addMessageListener.bind(sandbox)},
+
+ removeMessageListener: { value: removeMessageListener.bind(sandbox)},
+
+ sendAsyncMessage: {value: sendAsyncMessage.bind(sandbox)},
+
+ sendSyncMessage: { value: sendSyncMessage.bind(sandbox) }
+ });
+
+ frame(this).receiver = sandbox;
+ frame(sandbox).receiver = this;
+
+ frame(this).listeners = {};
+ frame(sandbox).listeners = {};
+}
+
+MessageManager.prototype = {
+ constructor: MessageManager,
+
+ addMessageListener : addMessageListener,
+
+ removeMessageListener : removeMessageListener,
+
+ sendAsyncMessage : sendAsyncMessage,
+
+ /**
+ * Loads a script into the remote frame.
+ *
+ * @param {String} uri
+ * The URL of the script to load into the frame; this must be an absolute
+ * local URL, but data: URLs are supported.
+ * @param {Boolean} allowDelayedLoad
+ * Not used.
+ */
+ loadFrameScript: function loadFrameScript(uri, async) {
+ if (arguments.length < loadFrameScript.length)
+ throw new Error("Not enough arguments");
+
+ let sandbox = frame(this).receiver;
+
+ try {
+ Sandbox.load(sandbox, uri);
+ } catch (e) {
+ console.exception(e)
+ }
+ }
+}
+
+Object.freeze(MessageManager);
+Object.freeze(MessageManager.prototype);
+
+exports.MessageManager = MessageManager;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/namespace.js b/tools/addon-sdk-1.7/packages/api-utils/lib/namespace.js
new file mode 100644
index 0000000..612910d
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/namespace.js
@@ -0,0 +1,43 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+// This is a temporary workaround until bug 673468 is fixed, which causes
+// entries associated with `XPCWrappedNative` wrapped keys to be GC-ed. To
+// workaround that we create a cross reference with an object from the same
+// compartment as `WeakMap` and use that as a key. Cross reference prevents
+// wrapper to be GC-ed until reference to it's value is kept.
+function handle(target) {
+ return target[handle.key] || Object.defineProperty(target, handle.key, {
+ value: { '::': target },
+ enumerable: false,
+ configurable: false,
+ writable: false
+ })[handle.key];
+}
+handle.key = '::ns::' + Math.round(Math.random() * 100000000000000000);
+
+/**
+ * Function creates a new namespace. Optionally `prototype` object may be
+ * passed, in which case namespace objects will inherit from it. Returned value
+ * is a function that can be used to get access to the namespaced properties
+ * for the passed object.
+ * @examples
+ * const ns = Namespace();
+ * ns(myObject).secret = secret;
+ */
+exports.Namespace = function Namespace(prototype) {
+ prototype = prototype || Object.prototype;
+ const map = new WeakMap();
+ return function namespace(target) {
+ let key = handle(target);
+ return map.get(key) ||
+ map.set(key, Object.create(prototype)), map.get(key);
+ };
+};
+
+// `Namespace` is a e4x function in the scope, so we export the function also as
+// `ns` as alias to avoid clashing.
+exports.ns = exports.Namespace;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/observer-service.js b/tools/addon-sdk-1.7/packages/api-utils/lib/observer-service.js
new file mode 100644
index 0000000..04222c7
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/observer-service.js
@@ -0,0 +1,175 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Cc, Ci } = require("chrome");
+const { Unknown } = require("./xpcom");
+const { when: unload } = require("./unload");
+const memory = require("./memory");
+
+
+/**
+ * A service for adding, removing and notifying observers of notifications.
+ * Wraps the nsIObserverService interface.
+ *
+ * @version 0.2
+ */
+
+var service = Cc["@mozilla.org/observer-service;1"].
+ getService(Ci.nsIObserverService);
+
+/**
+ * A cache of observers that have been added.
+ *
+ * We use this to remove observers when a caller calls |Observers.remove|.
+ */
+var cache = [];
+
+/**
+ * Topics specifically available to Jetpack-generated extensions.
+ *
+ * Using these predefined consts instead of the platform strings is good:
+ * - allows us to scope topics specifically for Jetpacks
+ * - addons aren't dependent on strings nor behavior of core platform topics
+ * - the core platform topics are not clearly named
+ *
+ */
+exports.topics = {
+ /**
+ * A topic indicating that the application is in a state usable
+ * by add-ons.
+ */
+ get APPLICATION_READY() packaging.jetpackID + "_APPLICATION_READY"
+};
+
+/**
+ * Register the given callback as an observer of the given topic.
+ *
+ * @param topic {String}
+ * the topic to observe
+ *
+ * @param callback {Object}
+ * the callback; an Object that implements nsIObserver or a Function
+ * that gets called when the notification occurs
+ *
+ * @param target {Object} [optional]
+ * the object to use as |this| when calling a Function callback
+ *
+ * @returns the observer
+ */
+var add = exports.add = function add(topic, callback, target) {
+ var observer = Observer.new(topic, callback, target);
+ service.addObserver(observer, topic, true);
+ cache.push(observer);
+
+ return observer;
+};
+
+/**
+ * Unregister the given callback as an observer of the given topic.
+ *
+ * @param topic {String}
+ * the topic being observed
+ *
+ * @param callback {Object}
+ * the callback doing the observing
+ *
+ * @param target {Object} [optional]
+ * the object being used as |this| when calling a Function callback
+ */
+var remove = exports.remove = function remove(topic, callback, target) {
+ // This seems fairly inefficient, but I'm not sure how much better
+ // we can make it. We could index by topic, but we can't index by callback
+ // or target, as far as I know, since the keys to JavaScript hashes
+ // (a.k.a. objects) can apparently only be primitive values.
+ let observers = cache.filter(function(v) {
+ return (v.topic == topic &&
+ v.callback == callback &&
+ v.target == target);
+ });
+
+ if (observers.length) {
+ service.removeObserver(observers[0], topic);
+ cache.splice(cache.indexOf(observers[0]), 1);
+ }
+};
+
+/**
+ * Notify observers about something.
+ *
+ * @param topic {String}
+ * the topic to notify observers about
+ *
+ * @param subject {Object} [optional]
+ * some information about the topic; can be any JS object or primitive
+ *
+ * @param data {String} [optional] [deprecated]
+ * some more information about the topic; deprecated as the subject
+ * is sufficient to pass all needed information to the JS observers
+ * that this module targets; if you have multiple values to pass to
+ * the observer, wrap them in an object and pass them via the subject
+ * parameter (i.e.: { foo: 1, bar: "some string", baz: myObject })
+ */
+var notify = exports.notify = function notify(topic, subject, data) {
+ subject = (typeof subject == "undefined") ? null : Subject.new(subject);
+ data = (typeof data == "undefined") ? null : data;
+ service.notifyObservers(subject, topic, data);
+};
+
+const Observer = Unknown.extend({
+ initialize: function initialize(topic, callback, target) {
+ memory.track(this);
+ this.topic = topic;
+ this.callback = callback;
+ this.target = target;
+ },
+ interfaces: [ 'nsIObserver', 'nsISupportsWeakReference' ],
+ observe: function(subject, topic, data) {
+ // Extract the wrapped object for subjects that are one of our
+ // wrappers around a JS object. This way we support both wrapped
+ // subjects created using this module and those that are real
+ // XPCOM components.
+ if (subject && typeof subject == "object" &&
+ ("wrappedJSObject" in subject) &&
+ ("observersModuleSubjectWrapper" in subject.wrappedJSObject))
+ subject = subject.wrappedJSObject.object;
+
+ try {
+ if (typeof this.callback == "function") {
+ if (this.target)
+ this.callback.call(this.target, subject, data);
+ else
+ this.callback(subject, data);
+ } else // typeof this.callback == "object" (nsIObserver)
+ this.callback.observe(subject, topic, data);
+ } catch (e) {
+ console.exception(e);
+ }
+ }
+});
+
+const Subject = Unknown.extend({
+ initialize: function initialize(object) {
+ // Double-wrap the object and set a property identifying the
+ // wrappedJSObject as one of our wrappers to distinguish between
+ // subjects that are one of our wrappers (which we should unwrap
+ // when notifying our observers) and those that are real JS XPCOM
+ // components (which we should pass through unaltered).
+ this.wrappedJSObject = {
+ observersModuleSubjectWrapper: true,
+ object: object
+ };
+ },
+ getHelperForLanguage: function() {},
+ getInterfaces: function() {}
+});
+
+unload(function() {
+ // Make a copy of cache first, since cache will be changing as we
+ // iterate through it.
+ cache.slice().forEach(function({ topic, callback, target }) {
+ remove(topic, callback, target);
+ });
+})
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/passwords/utils.js b/tools/addon-sdk-1.7/packages/api-utils/lib/passwords/utils.js
new file mode 100644
index 0000000..5dc6098
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/passwords/utils.js
@@ -0,0 +1,101 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Cc, Ci, components: { Constructor: CConstructor } } = require("chrome");
+const { uri: ADDON_URI } = require("self");
+const loginManager = Cc["@mozilla.org/login-manager;1"].
+ getService(Ci.nsILoginManager);
+const { URL: parseURL } = require("../url");
+const LoginInfo = CConstructor("@mozilla.org/login-manager/loginInfo;1",
+ "nsILoginInfo", "init");
+
+function filterMatchingLogins(loginInfo)
+ Object.keys(this).every(function(key) loginInfo[key] === this[key], this);
+
+/**
+ * Removes `user`, `password` and `path` fields from the given `url` if it's
+ * 'http', 'https' or 'ftp'. All other URLs are returned unchanged.
+ * @example
+ * http://user:pass@www.site.com/foo/?bar=baz#bang -> http://www.site.com
+ */
+function normalizeURL(url) {
+ let { scheme, host, port } = parseURL(url);
+ // We normalize URL only if it's `http`, `https` or `ftp`. All other types of
+ // URLs (`resource`, `chrome`, etc..) should not be normalized as they are
+ // used with add-on associated credentials path.
+ return scheme === "http" || scheme === "https" || scheme === "ftp" ?
+ scheme + "://" + (host || "") + (port ? ":" + port : "") :
+ url
+}
+
+function Login(options) {
+ let login = Object.create(Login.prototype);
+ Object.keys(options || {}).forEach(function(key) {
+ if (key === 'url')
+ login.hostname = normalizeURL(options.url);
+ else if (key === 'formSubmitURL')
+ login.formSubmitURL = options.formSubmitURL ?
+ normalizeURL(options.formSubmitURL) : null;
+ else if (key === 'realm')
+ login.httpRealm = options.realm;
+ else
+ login[key] = options[key];
+ });
+
+ return login;
+}
+Login.prototype.toJSON = function toJSON() {
+ return {
+ url: this.hostname || ADDON_URI,
+ realm: this.httpRealm || null,
+ formSubmitURL: this.formSubmitURL || null,
+ username: this.username || null,
+ password: this.password || null,
+ usernameField: this.usernameField || '',
+ passwordField: this.passwordField || '',
+ }
+};
+Login.prototype.toLoginInfo = function toLoginInfo() {
+ let { url, realm, formSubmitURL, username, password, usernameField,
+ passwordField } = this.toJSON();
+
+ return new LoginInfo(url, formSubmitURL, realm, username, password,
+ usernameField, passwordField);
+};
+
+function loginToJSON(value) Login(value).toJSON()
+
+/**
+ * Returns array of `nsILoginInfo` objects that are stored in the login manager
+ * and have all the properties with matching values as a given `options` object.
+ * @param {Object} options
+ * @returns {nsILoginInfo[]}
+ */
+exports.search = function search(options) {
+ return loginManager.getAllLogins()
+ .filter(filterMatchingLogins, Login(options))
+ .map(loginToJSON);
+};
+
+/**
+ * Stores login info created from the given `options` to the applications
+ * built-in login management system.
+ * @param {Object} options.
+ */
+exports.store = function store(options) {
+ loginManager.addLogin(Login(options).toLoginInfo());
+};
+
+/**
+ * Removes login info from the applications built-in login management system.
+ * _Please note: When removing a login info the specified properties must
+ * exactly match to the one that is already stored or exception will be thrown._
+ * @param {Object} options.
+ */
+exports.remove = function remove(options) {
+ loginManager.removeLogin(Login(options).toLoginInfo());
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/plain-text-console.js b/tools/addon-sdk-1.7/packages/api-utils/lib/plain-text-console.js
new file mode 100644
index 0000000..d76fddb
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/plain-text-console.js
@@ -0,0 +1,82 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {Cc,Ci} = require("chrome");
+
+function stringify(arg) {
+ try {
+ return String(arg);
+ }
+ catch(ex) {
+ return "<toString() error>";
+ }
+}
+
+function stringifyArgs(args) {
+ return Array.map(args, stringify).join(" ");
+}
+
+function message(print, level, args) {
+ print(level + ": " + stringifyArgs(args) + "\n", level);
+}
+
+var Console = exports.PlainTextConsole = function PlainTextConsole(print) {
+ if (!print)
+ print = dump;
+ if (print === dump) {
+ // If we're just using dump(), auto-enable preferences so
+ // that the developer actually sees the console output.
+ var prefs = Cc["@mozilla.org/preferences-service;1"]
+ .getService(Ci.nsIPrefBranch);
+ prefs.setBoolPref("browser.dom.window.dump.enabled", true);
+ }
+ this.print = print;
+
+ // Binding all the public methods to an instance so that they can be used
+ // as callback / listener functions straightaway.
+ this.log = this.log.bind(this);
+ this.info = this.info.bind(this);
+ this.warn = this.warn.bind(this);
+ this.error = this.error.bind(this);
+ this.debug = this.debug.bind(this);
+ this.exception = this.exception.bind(this);
+ this.trace = this.trace.bind(this);
+};
+
+Console.prototype = {
+ log: function log() {
+ message(this.print, "info", arguments);
+ },
+
+ info: function info() {
+ message(this.print, "info", arguments);
+ },
+
+ warn: function warn() {
+ message(this.print, "warning", arguments);
+ },
+
+ error: function error() {
+ message(this.print, "error", arguments);
+ },
+
+ debug: function debug() {
+ message(this.print, "debug", arguments);
+ },
+
+ exception: function exception(e) {
+ var fullString = ("An exception occurred.\n" +
+ require("./traceback").format(e) + "\n" + e);
+ this.error(fullString);
+ },
+
+ trace: function trace() {
+ var traceback = require("./traceback");
+ var stack = traceback.get();
+ stack.splice(-1, 1);
+ message(this.print, "info", [traceback.format(stack)]);
+ }
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/preferences-service.js b/tools/addon-sdk-1.7/packages/api-utils/lib/preferences-service.js
new file mode 100644
index 0000000..c5ffb2a
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/preferences-service.js
@@ -0,0 +1,124 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+// The minimum and maximum integers that can be set as preferences.
+// The range of valid values is narrower than the range of valid JS values
+// because the native preferences code treats integers as NSPR PRInt32s,
+// which are 32-bit signed integers on all platforms.
+const MAX_INT = 0x7FFFFFFF;
+const MIN_INT = -0x80000000;
+
+const {Cc,Ci,Cr} = require("chrome");
+
+const prefService = Cc["@mozilla.org/preferences-service;1"].
+ getService(Ci.nsIPrefService);
+const prefSvc = prefService.getBranch(null);
+const defaultBranch = prefService.getDefaultBranch(null);
+
+var get = exports.get = function get(name, defaultValue) {
+ switch (prefSvc.getPrefType(name)) {
+ case Ci.nsIPrefBranch.PREF_STRING:
+ return prefSvc.getComplexValue(name, Ci.nsISupportsString).data;
+
+ case Ci.nsIPrefBranch.PREF_INT:
+ return prefSvc.getIntPref(name);
+
+ case Ci.nsIPrefBranch.PREF_BOOL:
+ return prefSvc.getBoolPref(name);
+
+ case Ci.nsIPrefBranch.PREF_INVALID:
+ return defaultValue;
+
+ default:
+ // This should never happen.
+ throw new Error("Error getting pref " + name +
+ "; its value's type is " +
+ prefSvc.getPrefType(name) +
+ ", which I don't know " +
+ "how to handle.");
+ }
+};
+
+var set = exports.set = function set(name, value) {
+ var prefType;
+ if (typeof value != "undefined" && value != null)
+ prefType = value.constructor.name;
+
+ switch (prefType) {
+ case "String":
+ {
+ var string = Cc["@mozilla.org/supports-string;1"].
+ createInstance(Ci.nsISupportsString);
+ string.data = value;
+ prefSvc.setComplexValue(name, Ci.nsISupportsString, string);
+ }
+ break;
+
+ case "Number":
+ // We throw if the number is outside the range or not an integer, since
+ // the result will not be what the consumer wanted to store.
+ if (value > MAX_INT || value < MIN_INT)
+ throw new Error("you cannot set the " + name +
+ " pref to the number " + value +
+ ", as number pref values must be in the signed " +
+ "32-bit integer range -(2^31) to 2^31-1. " +
+ "To store numbers outside that range, store " +
+ "them as strings.");
+ if (value % 1 != 0)
+ throw new Error("cannot store non-integer number: " + value);
+ prefSvc.setIntPref(name, value);
+ break;
+
+ case "Boolean":
+ prefSvc.setBoolPref(name, value);
+ break;
+
+ default:
+ throw new Error("can't set pref " + name + " to value '" + value +
+ "'; it isn't a string, integer, or boolean");
+ }
+};
+
+var has = exports.has = function has(name) {
+ return (prefSvc.getPrefType(name) != Ci.nsIPrefBranch.PREF_INVALID);
+};
+
+var isSet = exports.isSet = function isSet(name) {
+ return (has(name) && prefSvc.prefHasUserValue(name));
+};
+
+var reset = exports.reset = function reset(name) {
+ try {
+ prefSvc.clearUserPref(name);
+ } catch (e if e.result == Cr.NS_ERROR_UNEXPECTED) {
+ // The pref service throws NS_ERROR_UNEXPECTED when the caller tries
+ // to reset a pref that doesn't exist or is already set to its default
+ // value. This interface fails silently in those cases, so callers
+ // can unconditionally reset a pref without having to check if it needs
+ // resetting first or trap exceptions after the fact. It passes through
+ // other exceptions, however, so callers know about them, since we don't
+ // know what other exceptions might be thrown and what they might mean.
+ }
+};
+
+exports.getLocalized = function getLocalized(name, defaultValue) {
+ let value = null;
+ try {
+ value = prefSvc.getComplexValue(name, Ci.nsIPrefLocalizedString).data;
+ }
+ finally {
+ return value || defaultValue;
+ }
+}
+
+exports.setLocalized = function setLocalized(name, value) {
+ // We can't use `prefs.set` here as we have to use `getDefaultBranch`
+ // (instead of `getBranch`) in order to have `mIsDefault` set to true, here:
+ // http://mxr.mozilla.org/mozilla-central/source/modules/libpref/src/nsPrefBranch.cpp#233
+ // Otherwise, we do not enter into this expected condition:
+ // http://mxr.mozilla.org/mozilla-central/source/modules/libpref/src/nsPrefBranch.cpp#244
+ defaultBranch.setCharPref(name, value);
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/process.js b/tools/addon-sdk-1.7/packages/api-utils/lib/process.js
new file mode 100644
index 0000000..68ef2f9
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/process.js
@@ -0,0 +1,76 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Cc, Ci } = require("chrome");
+const { createRemoteBrowser } = require("api-utils/window-utils");
+const { channel } = require("./channel");
+const packaging = require('@packaging');
+const { when } = require('./unload');
+const { MessageManager } = require('./message-manager');
+
+const addonService = '@mozilla.org/addon/service;1' in Cc ?
+ Cc['@mozilla.org/addon/service;1'].getService(Ci.nsIAddonService) : null
+
+const ENABLE_E10S = packaging.enable_e10s;
+
+const isFennec = require("./xul-app").is("Fennec");
+
+function loadScript(target, uri, sync) {
+ return 'loadScript' in target ? target.loadScript(uri, sync)
+ : target.loadFrameScript(uri, sync)
+}
+
+function process(target, id, path, scope) {
+ // Please note that even though `loadScript`, is executed before channel is
+ // returned, users still are able to subscribe for messages before any message
+ // will be sent. That's because `loadScript` queues script execution on the
+ // other process, which means they will execute async (on the next turn of
+ // event loop), while the channel for messages is returned immediately (in
+ // the same turn of event loop).
+
+ let load = loadScript.bind(null, target);
+
+ load(packaging.uriPrefix + packaging.loader, false);
+ load('data:,' + encodeURIComponent(
+ 'let loader = Loader.new(' + JSON.stringify(packaging) + ');\n' +
+ 'loader.main("' + id + '", "' + path + '");'), false);
+
+ when(function (reason) {
+ // Please note that it's important to unload remote loader
+ // synchronously (using synchronous frame script), to make sure that we
+ // don't stop during unload.
+ // Bug 724433: Take care to nullify all globals set by `cuddlefish.js`
+ // otherwise, we will leak any still defined global.
+ // `dump` is set in Loader.new method, `dump = globals.dump;`
+ load('data:,loader.unload("' + reason + '");' +
+ 'loader = null; Loader = null; dump = null;', true);
+ });
+
+ return {
+ channel: channel.bind(null, scope, target),
+ loadScript: load
+ };
+}
+
+exports.spawn = function spawn(id, path) {
+ return function promise(deliver) {
+ // If `nsIAddonService` is available we use it to create an add-on process,
+ // otherwise we fallback to the remote browser's message manager.
+ if (ENABLE_E10S && addonService) {
+ console.log('!!!!!!!!!!!!!!!!!!!! Using addon process !!!!!!!!!!!!!!!!!!');
+ deliver(process(addonService.createAddon(), id, path));
+ } else if (isFennec) {
+ deliver(process(new MessageManager(), id, path));
+ } else {
+ createRemoteBrowser(ENABLE_E10S)(function(browser) {
+ let messageManager = browser.QueryInterface(Ci.nsIFrameLoaderOwner).
+ frameLoader.messageManager
+ let window = browser.ownerDocument.defaultView;
+ deliver(process(messageManager, id, path, window));
+ });
+ }
+ };
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/promise.js b/tools/addon-sdk-1.7/packages/api-utils/lib/promise.js
new file mode 100644
index 0000000..7c8d7a5
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/promise.js
@@ -0,0 +1,219 @@
+/* vim:set ts=2 sw=2 sts=2 expandtab */
+/*jshint asi: true undef: true es5: true node: true devel: true
+ forin: true latedef: false supernew: true */
+/*global define: true */
+!function(factory) {
+ if (typeof(define) === 'function') { // RequireJS
+ define(factory)
+ } else if (typeof(exports) === 'object') { // CommonJS
+ factory(require, exports)
+ } else if (~String(this).indexOf('BackstagePass')) { // JSM
+ factory(undefined, this)
+ this.EXPORTED_SYMBOLS = Object.keys(this)
+ } else {
+ factory(undefined, (this.promise = {}))
+ }
+}.call(this, function(require, exports) {
+
+'use strict';
+
+function resolution(value) {
+ /**
+ Returns non-standard compliant (`then` does not returns a promise) promise
+ that resolves to a given `value`. Used just internally only.
+ **/
+ return { then: function then(resolve) { resolve(value) } }
+}
+
+function rejection(reason) {
+ /**
+ Returns non-standard compliant promise (`then` does not returns a promise)
+ that rejects with a given `reason`. This is used internally only.
+ **/
+ return { then: function then(resolve, reject) { reject(reason) } }
+}
+
+function attempt(f) {
+ /**
+ Returns wrapper function that delegates to `f`. If `f` throws then captures
+ error and returns promise that rejects with a thrown error. Otherwise returns
+ return value. (Internal utility)
+ **/
+ return function effort(options) {
+ try { return f(options) }
+ catch(error) { return rejection(error) }
+ }
+}
+
+function isPromise(value) {
+ /**
+ Returns true if given `value` is promise. Value is assumed to be promise if
+ it implements `then` method.
+ **/
+ return value && typeof(value.then) === 'function'
+}
+
+function defer(prototype) {
+ /**
+ Returns object containing following properties:
+ - `promise` Eventual value representation implementing CommonJS [Promises/A]
+ (http://wiki.commonjs.org/wiki/Promises/A) API.
+ - `resolve` Single shot function that resolves returned `promise` with a given
+ `value` argument.
+ - `reject` Single shot function that rejects returned `promise` with a given
+ `reason` argument.
+
+ Given `prototype` argument is used as a prototype of the returned `promise`
+ allowing one to implement additional API. If prototype is not passed then
+ it falls back to `Object.prototype`.
+
+ ## Examples
+
+ // Simple usage.
+ var deferred = defer()
+ deferred.promise.then(console.log, console.error)
+ deferred.resolve(value)
+
+ // Advanced usage
+ var prototype = {
+ get: function get(name) {
+ return this.then(function(value) {
+ return value[name];
+ })
+ }
+ }
+
+ var foo = defer(prototype)
+ deferred.promise.get('name').then(console.log)
+ deferred.resolve({ name: 'Foo' })
+ //=> 'Foo'
+ */
+ var pending = [], result
+ prototype = (prototype || prototype === null) ? prototype : Object.prototype
+
+ // Create an object implementing promise API.
+ var promise = Object.create(prototype, {
+ then: { value: function then(resolve, reject) {
+ // create a new deferred using a same `prototype`.
+ var deferred = defer(prototype)
+ // If `resolve / reject` callbacks are not provided.
+ resolve = resolve ? attempt(resolve) : resolution
+ reject = reject ? attempt(reject) : rejection
+
+ // Create a listeners for a enclosed promise resolution / rejection that
+ // delegate to an actual callbacks and resolve / reject returned promise.
+ function resolved(value) { deferred.resolve(resolve(value)) }
+ function rejected(reason) { deferred.resolve(reject(reason)) }
+
+ // If promise is pending register listeners. Otherwise forward them to
+ // resulting resolution.
+ if (pending) pending.push([ resolved, rejected ])
+ else result.then(resolved, rejected)
+
+ return deferred.promise
+ }}
+ })
+
+ var deferred = {
+ promise: promise,
+ resolve: function resolve(value) {
+ /**
+ Resolves associated `promise` to a given `value`, unless it's already
+ resolved or rejected.
+ **/
+ if (pending) {
+ // store resolution `value` as a promise (`value` itself may be a
+ // promise), so that all subsequent listeners can be forwarded to it,
+ // which either resolves immediately or forwards if `value` is
+ // a promise.
+ result = isPromise(value) ? value : resolution(value)
+ // forward all pending observers.
+ while (pending.length) result.then.apply(result, pending.shift())
+ // mark promise as resolved.
+ pending = null
+ }
+ },
+ reject: function reject(reason) {
+ /**
+ Rejects associated `promise` with a given `reason`, unless it's already
+ resolved / rejected.
+ **/
+ deferred.resolve(rejection(reason))
+ }
+ }
+
+ return deferred
+}
+exports.defer = defer
+
+function resolve(value, prototype) {
+ /**
+ Returns a promise resolved to a given `value`. Optionally second `prototype`
+ arguments my be provided to be used as a prototype for a returned promise.
+ **/
+ var deferred = defer(prototype)
+ deferred.resolve(value)
+ return deferred.promise
+}
+exports.resolve = resolve
+
+function reject(reason, prototype) {
+ /**
+ Returns a promise that is rejected with a given `reason`. Optionally second
+ `prototype` arguments my be provided to be used as a prototype for a returned
+ promise.
+ **/
+ var deferred = defer(prototype)
+ deferred.reject(reason)
+ return deferred.promise
+}
+exports.reject = reject
+
+var promised = (function() {
+ // Note: Define shortcuts and utility functions here in order to avoid
+ // slower property accesses and unnecessary closure creations on each
+ // call of this popular function.
+
+ var call = Function.call
+ var concat = Array.prototype.concat
+
+ // Utility function that does following:
+ // execute([ f, self, args...]) => f.apply(self, args)
+ function execute(args) { return call.apply(call, args) }
+
+ // Utility function that takes promise of `a` array and maybe promise `b`
+ // as arguments and returns promise for `a.concat(b)`.
+ function promisedConcat(promises, unknown) {
+ return promises.then(function(values) {
+ return resolve(unknown).then(function(value) {
+ return values.concat(value)
+ })
+ })
+ }
+
+ return function promised(f, prototype) {
+ /**
+ Returns a wrapped `f`, which when called returns a promise that resolves to
+ `f(...)` passing all the given arguments to it, which by the way may be
+ promises. Optionally second `prototype` argument may be provided to be used
+ a prototype for a returned promise.
+
+ ## Example
+
+ var promise = promised(Array)(1, promise(2), promise(3))
+ promise.then(console.log) // => [ 1, 2, 3 ]
+ **/
+
+ return function promised() {
+ // create array of [ f, this, args... ]
+ return concat.apply([ f, this ], arguments).
+ // reduce it via `promisedConcat` to get promised array of fulfillments
+ reduce(promisedConcat, resolve([], prototype)).
+ // finally map that to promise of `f.apply(this, args...)`
+ then(execute)
+ }
+ }
+})()
+exports.promised = promised
+
+})
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/querystring.js b/tools/addon-sdk-1.7/packages/api-utils/lib/querystring.js
new file mode 100644
index 0000000..9e29515
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/querystring.js
@@ -0,0 +1,117 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+let unescape = decodeURIComponent;
+exports.unescape = unescape;
+
+// encodes a string safely for application/x-www-form-urlencoded
+// adheres to RFC 3986
+// see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeURIComponent
+function escape(query) {
+ return encodeURIComponent(query).
+ replace(/%20/g, '+').
+ replace(/!/g, '%21').
+ replace(/'/g, '%27').
+ replace(/\(/g, '%28').
+ replace(/\)/g, '%29').
+ replace(/\*/g, '%2A');
+}
+exports.escape = escape;
+
+// Converts an object of unordered key-vals to a string that can be passed
+// as part of a request
+function stringify(options, separator, assigner) {
+ separator = separator || '&';
+ assigner = assigner || '=';
+ // Explicitly return null if we have null, and empty string, or empty object.
+ if (!options)
+ return '';
+
+ // If content is already a string, just return it as is.
+ if (typeof(options) == 'string')
+ return options;
+
+ // At this point we have a k:v object. Iterate over it and encode each value.
+ // Arrays and nested objects will get encoded as needed. For example...
+ //
+ // { foo: [1, 2, { omg: 'bbq', 'all your base!': 'are belong to us' }], bar: 'baz' }
+ //
+ // will be encoded as
+ //
+ // foo[0]=1&foo[1]=2&foo[2][omg]=bbq&foo[2][all+your+base!]=are+belong+to+us&bar=baz
+ //
+ // Keys (including '[' and ']') and values will be encoded with
+ // `escape` before returning.
+ //
+ // Execution was inspired by jQuery, but some details have changed and numeric
+ // array keys are included (whereas they are not in jQuery).
+
+ let encodedContent = [];
+ function add(key, val) {
+ encodedContent.push(escape(key) + assigner + escape(val));
+ }
+
+ function make(key, value) {
+ if (value && typeof(value) === 'object')
+ Object.keys(value).forEach(function(name) {
+ make(key + '[' + name + ']', value[name]);
+ });
+ else
+ add(key, value);
+ }
+
+ Object.keys(options).forEach(function(name) { make(name, options[name]); });
+ return encodedContent.join(separator);
+
+ //XXXzpao In theory, we can just use a FormData object on 1.9.3, but I had
+ // trouble getting that working. It would also be nice to stay
+ // backwards-compat as long as possible. Keeping this in for now...
+ // let formData = Cc['@mozilla.org/files/formdata;1'].
+ // createInstance(Ci.nsIDOMFormData);
+ // for ([k, v] in Iterator(content)) {
+ // formData.append(k, v);
+ // }
+ // return formData;
+}
+exports.stringify = stringify;
+
+// Exporting aliases that nodejs implements just for the sake of
+// interoperability.
+exports.encode = stringify;
+exports.serialize = stringify;
+
+// Note: That `stringify` and `parse` aren't bijective as we use `stringify`
+// as it was implement in request module, but implement `parse` to match nodejs
+// behavior.
+// TODO: Make `stringify` implement API as in nodejs and figure out backwards
+// compatibility.
+function parse(query, separator, assigner) {
+ separator = separator || '&';
+ assigner = assigner || '=';
+ let result = {};
+
+ if (typeof query !== 'string' || query.length === 0)
+ return result;
+
+ query.split(separator).forEach(function(chunk) {
+ let pair = chunk.split(assigner);
+ let key = unescape(pair[0]);
+ let value = unescape(pair.slice(1).join(assigner));
+
+ if (!(key in result))
+ result[key] = value;
+ else if (Array.isArray(result[key]))
+ result[key].push(value);
+ else
+ result[key] = [result[key], value];
+ });
+
+ return result;
+};
+exports.parse = parse;
+// Exporting aliases that nodejs implements just for the sake of
+// interoperability.
+exports.decode = parse;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/runtime.js b/tools/addon-sdk-1.7/packages/api-utils/lib/runtime.js
new file mode 100644
index 0000000..845d146
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/runtime.js
@@ -0,0 +1,15 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Cc, Ci } = require("chrome");
+const runtime = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime);
+
+exports.inSafeMode = runtime.inSafeMode;
+exports.OS = runtime.OS;
+exports.processType = runtime.processType;
+exports.widgetToolkit = runtime.widgetToolkit;
+exports.XPCOMABI = runtime.XPCOMABI;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/sandbox.js b/tools/addon-sdk-1.7/packages/api-utils/lib/sandbox.js
new file mode 100644
index 0000000..6130637
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/sandbox.js
@@ -0,0 +1,46 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const { Cc, Ci, CC, Cu } = require('chrome');
+const systemPrincipal = CC('@mozilla.org/systemprincipal;1', 'nsIPrincipal')();
+const scriptLoader = Cc['@mozilla.org/moz/jssubscript-loader;1'].
+ getService(Ci.mozIJSSubScriptLoader);
+
+/**
+ * Make a new sandbox that inherits given `source`'s principals. Source can be
+ * URI string, DOMWindow or `null` for system principals.
+ */
+function sandbox(target, options) {
+ return Cu.Sandbox(target || systemPrincipal, options || {});
+}
+exports.sandbox = sandbox
+
+/**
+ * Evaluates given `source` in a given `sandbox` and returns result.
+ */
+function evaluate(sandbox, code, uri, line, version) {
+ return Cu.evalInSandbox(code, sandbox, version || '1.8', uri || '', line || 1);
+}
+exports.evaluate = evaluate;
+
+/**
+ * Evaluates code under the given `uri` in the given `sandbox`.
+ *
+ * @param {String} uri
+ * The URL pointing to the script to load.
+ * It must be a local chrome:, resource:, file: or data: URL.
+ */
+function load(sandbox, uri) {
+ if (uri.indexOf('data:') === 0) {
+ let source = uri.substr(uri.indexOf(',') + 1);
+
+ return evaluate(sandbox, decodeURIComponent(source), '1.8', uri, 0);
+ } else {
+ return scriptLoader.loadSubScript(uri, sandbox, 'UTF-8');
+ }
+}
+exports.load = load; \ No newline at end of file
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/self!.js b/tools/addon-sdk-1.7/packages/api-utils/lib/self!.js
new file mode 100644
index 0000000..fd69f9a
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/self!.js
@@ -0,0 +1,48 @@
+/* vim:st=2:sts=2:sw=2:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { CC } = require('chrome');
+const { jetpackID, name, manifest, metadata, uriPrefix } = require('@packaging');
+
+const XMLHttpRequest = CC('@mozilla.org/xmlextras/xmlhttprequest;1',
+ 'nsIXMLHttpRequest');
+
+// Utility function that synchronously reads local resource from the given
+// `uri` and returns content string.
+function readURI(uri) {
+ let request = XMLHttpRequest();
+ request.open('GET', uri, false);
+ request.overrideMimeType('text/plain');
+ request.send();
+ return request.responseText;
+}
+
+// Some XPCOM APIs require valid URIs as an argument for certain operations (see
+// `nsILoginManager` for example). This property represents add-on associated
+// unique URI string that can be used for that.
+const uri = 'addon:' + jetpackID
+
+function url(root, path) root + (path || "")
+function read(root, path) readURI(url(root, path))
+
+exports.create = function create(base) {
+ let moduleData = manifest[base] && manifest[base].requirements['self'];
+ let root = uriPrefix + moduleData.dataURIPrefix;
+ return Object.freeze({
+ id: 'self',
+ exports: Object.freeze({
+ id: jetpackID,
+ uri: uri,
+ name: name,
+ version: metadata[name].version,
+ data: {
+ url: url.bind(null, root),
+ load: read.bind(null, root)
+ }
+ })
+ });
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/system.js b/tools/addon-sdk-1.7/packages/api-utils/lib/system.js
new file mode 100644
index 0000000..3986645
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/system.js
@@ -0,0 +1,120 @@
+/* vim:set ts=2 sw=2 sts=2 expandtab */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+const { Cc, Ci, CC } = require('chrome');
+const options = require('@packaging');
+const file = require('./file');
+const runtime = require("./runtime.js");
+
+const appStartup = Cc['@mozilla.org/toolkit/app-startup;1'].
+ getService(Ci.nsIAppStartup);
+const appInfo = Cc["@mozilla.org/xre/app-info;1"].
+ getService(Ci.nsIXULAppInfo);
+const directoryService = Cc['@mozilla.org/file/directory_service;1'].
+ getService(Ci.nsIProperties);
+
+
+const { eAttemptQuit: E_ATTEMPT, eForceQuit: E_FORCE } = appStartup;
+
+/**
+ * Parsed JSON object that was passed via `cfx --static-args "{ foo: 'bar' }"`
+ */
+exports.staticArgs = options.staticArgs;
+
+/**
+ * Environment variables. Environment variables are non-enumerable properties
+ * of this object (key is name and value is value).
+ */
+exports.env = require('./environment').env;
+
+/**
+ * Ends the process with the specified `code`. If omitted, exit uses the
+ * 'success' code 0. To exit with failure use `1`.
+ * TODO: Improve platform to actually quit with an exit code.
+ */
+exports.exit = function exit(code) {
+ // This is used by 'cfx' to find out exit code.
+ if ('resultFile' in options) {
+ let stream = file.open(options.resultFile, 'w');
+ stream.write(code ? 'FAIL' : 'OK');
+ stream.close();
+ }
+
+ appStartup.quit(code ? E_ATTEMPT : E_FORCE);
+};
+
+/**
+ * Returns a path of the system's or application's special directory / file
+ * associated with a given `id`. For list of possible `id`s please see:
+ * https://developer.mozilla.org/en/Code_snippets/File_I%2F%2FO#Getting_special_files
+ * http://mxr.mozilla.org/mozilla-central/source/xpcom/io/nsAppDirectoryServiceDefs.h
+ * @example
+ *
+ * // get firefox profile path
+ * let profilePath = require('system').pathFor('ProfD');
+ * // get OS temp files directory (/tmp)
+ * let temps = require('system').pathFor('TmpD');
+ * // get OS desktop path for an active user (~/Desktop on linux
+ * // or C:\Documents and Settings\username\Desktop on windows).
+ * let desktopPath = require('system').pathFor('Desk');
+ */
+exports.pathFor = function pathFor(id) {
+ return directoryService.get(id, Ci.nsIFile).path;
+};
+
+/**
+ * What platform you're running on (all lower case string).
+ * For possible values see:
+ * https://developer.mozilla.org/en/OS_TARGET
+ */
+exports.platform = runtime.OS.toLowerCase();
+
+/**
+ * What processor architecture you're running on:
+ * `'arm', 'ia32', or 'x64'`.
+ */
+exports.architecture = runtime.XPCOMABI.split('_')[0];
+
+/**
+ * What compiler used for build:
+ * `'msvc', 'n32', 'gcc2', 'gcc3', 'sunc', 'ibmc'...`
+ */
+exports.compiler = runtime.XPCOMABI.split('_')[1];
+
+/**
+ * The application's build ID/date, for example "2004051604".
+ */
+exports.build = appInfo.appBuildID;
+
+/**
+ * The XUL application's UUID.
+ * This has traditionally been in the form
+ * `{AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE}` but for some applications it may
+ * be: "appname@vendor.tld".
+ */
+exports.id = appInfo.ID;
+
+/**
+ * The name of the application.
+ */
+exports.name = appInfo.name;
+
+/**
+ * The XUL application's version, for example "0.8.0+" or "3.7a1pre".
+ */
+exports.version = appInfo.version;
+
+/**
+ * XULRunner version.
+ */
+exports.platformVersion = appInfo.platformVersion;
+
+
+/**
+ * The name of the application vendor, for example "Mozilla".
+ */
+exports.vendor = appInfo.vendor;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/tab-browser.js b/tools/addon-sdk-1.7/packages/api-utils/lib/tab-browser.js
new file mode 100644
index 0000000..13d365a
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/tab-browser.js
@@ -0,0 +1,727 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+const {Cc,Ci,Cu} = require("chrome");
+var NetUtil = {};
+Cu.import("resource://gre/modules/NetUtil.jsm", NetUtil);
+NetUtil = NetUtil.NetUtil;
+const errors = require("./errors");
+const windowUtils = require("./window-utils");
+const apiUtils = require("./api-utils");
+const collection = require("./collection");
+
+// TODO: The hard-coding of app-specific info here isn't very nice;
+// ideally such app-specific info should be more decoupled, and the
+// module should be extensible, allowing for support of new apps at
+// runtime, perhaps by inspecting supported packages (e.g. via
+// dynamically-named modules or package-defined extension points).
+
+if (!require("./xul-app").is("Firefox")) {
+ throw new Error([
+ "The tab-browser module currently supports only Firefox. In the future ",
+ "it will support other applications. Please see ",
+ "https://bugzilla.mozilla.org/show_bug.cgi?id=560716 for more information."
+ ].join(""));
+}
+
+function onBrowserLoad(callback, event) {
+ if (event.target && event.target.defaultView == this) {
+ this.removeEventListener("load", onBrowserLoad, true);
+ try {
+ require("timer").setTimeout(function () {
+ callback(event);
+ }, 10);
+ } catch (e) { console.exception(e); }
+ }
+}
+
+// Utility function to open a new browser window.
+function openBrowserWindow(callback, url) {
+ let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
+ getService(Ci.nsIWindowWatcher);
+ let urlString = Cc["@mozilla.org/supports-string;1"].
+ createInstance(Ci.nsISupportsString);
+ urlString.data = url;
+ let window = ww.openWindow(null, "chrome://browser/content/browser.xul",
+ "_blank", "chrome,all,dialog=no", urlString);
+ if (callback)
+ window.addEventListener("load", onBrowserLoad.bind(window, callback), true);
+
+ return window;
+}
+
+// Open a URL in a new tab
+exports.addTab = function addTab(url, options) {
+ if (!options)
+ options = {};
+ options.url = url;
+
+ options = apiUtils.validateOptions(options, {
+ // TODO: take URL object instead of string (bug 564524)
+ url: {
+ is: ["string"],
+ ok: function (v) !!v,
+ msg: "The url parameter must have be a non-empty string."
+ },
+ inNewWindow: {
+ is: ["undefined", "null", "boolean"]
+ },
+ inBackground: {
+ is: ["undefined", "null", "boolean"]
+ },
+ onLoad: {
+ is: ["undefined", "null", "function"]
+ },
+ isPinned: {
+ is: ["undefined", "boolean"]
+ }
+ });
+
+ var wm = Cc["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Ci.nsIWindowMediator);
+ var win = wm.getMostRecentWindow("navigator:browser");
+ if (!win || options.inNewWindow) {
+ openBrowserWindow(function(e) {
+ if(options.isPinned) {
+ //get the active tab in the recently created window
+ let mainWindow = e.target.defaultView;
+ mainWindow.gBrowser.pinTab(mainWindow.gBrowser.selectedTab);
+ }
+ require("./errors").catchAndLog(function(e) options.onLoad(e))(e);
+ }, options.url);
+ } else {
+ let tab = win.gBrowser.addTab(options.url);
+ if (!options.inBackground)
+ win.gBrowser.selectedTab = tab;
+ if (options.onLoad) {
+ let tabBrowser = win.gBrowser.getBrowserForTab(tab);
+ tabBrowser.addEventListener("load", function onLoad(e) {
+ if (e.target.defaultView.content.location == "about:blank")
+ return;
+ // remove event handler from addTab - don't want notified
+ // for subsequent loads in same tab.
+ tabBrowser.removeEventListener("load", onLoad, true);
+ require("./errors").catchAndLog(function(e) options.onLoad(e))(e);
+ }, true);
+ }
+ }
+}
+
+// Iterate over a window's tabbrowsers
+function tabBrowserIterator(window) {
+ var browsers = window.document.querySelectorAll("tabbrowser");
+ for (var i = 0; i < browsers.length; i++)
+ yield browsers[i];
+}
+
+// Iterate over a tabbrowser's tabs
+function tabIterator(tabbrowser) {
+ var tabs = tabbrowser.tabContainer;
+ for (var i = 0; i < tabs.children.length; i++) {
+ yield tabs.children[i];
+ }
+}
+
+// Tracker for all tabbrowsers across all windows,
+// or a single tabbrowser if the window is given.
+function Tracker(delegate, window) {
+ this._delegate = delegate;
+ this._browsers = [];
+ this._window = window;
+ this._windowTracker = windowUtils.WindowTracker(this);
+
+ require("./unload").ensure(this);
+}
+Tracker.prototype = {
+ __iterator__: function __iterator__() {
+ for (var i = 0; i < this._browsers.length; i++)
+ yield this._browsers[i];
+ },
+ get: function get(index) {
+ return this._browsers[index];
+ },
+ onTrack: function onTrack(window) {
+ if (this._window && window != this._window)
+ return;
+
+ for (let browser in tabBrowserIterator(window))
+ this._browsers.push(browser);
+ if (this._delegate)
+ for (let browser in tabBrowserIterator(window))
+ this._delegate.onTrack(browser);
+ },
+ onUntrack: function onUntrack(window) {
+ if (this._window && window != this._window)
+ return;
+
+ for (let browser in tabBrowserIterator(window)) {
+ let index = this._browsers.indexOf(browser);
+ if (index != -1)
+ this._browsers.splice(index, 1);
+ else
+ console.error("internal error: browser tab not found");
+ }
+ if (this._delegate)
+ for (let browser in tabBrowserIterator(window))
+ this._delegate.onUntrack(browser);
+ },
+ get length() {
+ return this._browsers.length;
+ },
+ unload: function unload() {
+ this._windowTracker.unload();
+ }
+};
+exports.Tracker = apiUtils.publicConstructor(Tracker);
+
+// Tracker for all tabs across all windows,
+// or a single window if it's given.
+function TabTracker(delegate, window) {
+ this._delegate = delegate;
+ this._tabs = [];
+ this._tracker = new Tracker(this, window);
+ require("./unload").ensure(this);
+}
+TabTracker.prototype = {
+ _TAB_EVENTS: ["TabOpen", "TabClose"],
+ _safeTrackTab: function safeTrackTab(tab) {
+ this._tabs.push(tab);
+ try {
+ this._delegate.onTrack(tab);
+ } catch (e) {
+ console.exception(e);
+ }
+ },
+ _safeUntrackTab: function safeUntrackTab(tab) {
+ var index = this._tabs.indexOf(tab);
+ if (index == -1)
+ console.error("internal error: tab not found");
+ this._tabs.splice(index, 1);
+ try {
+ this._delegate.onUntrack(tab);
+ } catch (e) {
+ console.exception(e);
+ }
+ },
+ handleEvent: function handleEvent(event) {
+ switch (event.type) {
+ case "TabOpen":
+ this._safeTrackTab(event.target);
+ break;
+ case "TabClose":
+ this._safeUntrackTab(event.target);
+ break;
+ default:
+ throw new Error("internal error: unknown event type: " +
+ event.type);
+ }
+ },
+ onTrack: function onTrack(tabbrowser) {
+ for (let tab in tabIterator(tabbrowser))
+ this._safeTrackTab(tab);
+ var self = this;
+ this._TAB_EVENTS.forEach(
+ function(eventName) {
+ tabbrowser.tabContainer.addEventListener(eventName, self, true);
+ });
+ },
+ onUntrack: function onUntrack(tabbrowser) {
+ for (let tab in tabIterator(tabbrowser))
+ this._safeUntrackTab(tab);
+ var self = this;
+ this._TAB_EVENTS.forEach(
+ function(eventName) {
+ tabbrowser.tabContainer.removeEventListener(eventName, self, true);
+ });
+ },
+ unload: function unload() {
+ this._tracker.unload();
+ }
+};
+exports.TabTracker = apiUtils.publicConstructor(TabTracker);
+
+exports.whenContentLoaded = function whenContentLoaded(callback) {
+ var cb = require("./errors").catchAndLog(function eventHandler(event) {
+ if (event.target && event.target.defaultView)
+ callback(event.target.defaultView);
+ });
+
+ var tracker = new Tracker({
+ onTrack: function(tabBrowser) {
+ tabBrowser.addEventListener("DOMContentLoaded", cb, false);
+ },
+ onUntrack: function(tabBrowser) {
+ tabBrowser.removeEventListener("DOMContentLoaded", cb, false);
+ }
+ });
+
+ return tracker;
+};
+
+exports.__defineGetter__("activeTab", function() {
+ const wm = Cc["@mozilla.org/appshell/window-mediator;1"].
+ getService(Ci.nsIWindowMediator);
+ let mainWindow = wm.getMostRecentWindow("navigator:browser");
+ return mainWindow.gBrowser.selectedTab;
+});
+
+/******************* TabModule *********************/
+
+// Supported tab events
+const events = [
+ "onActivate",
+ "onDeactivate",
+ "onOpen",
+ "onClose",
+ "onReady",
+ "onLoad",
+ "onPaint"
+];
+exports.tabEvents = events;
+
+/**
+ * TabModule
+ *
+ * Constructor for a module that implements the tabs API
+ */
+let TabModule = exports.TabModule = function TabModule(window) {
+ let self = this;
+ /**
+ * Tab
+ *
+ * Safe object representing a tab.
+ */
+ let tabConstructor = apiUtils.publicConstructor(function(element) {
+ if (!element)
+ throw new Error("no tab element.");
+ let win = element.ownerDocument.defaultView;
+ if (!win)
+ throw new Error("element has no window.");
+ if (window && win != window)
+ throw new Error("module's window and element's window don't match.");
+ let browser = win.gBrowser.getBrowserForTab(element);
+
+ this.__defineGetter__("title", function() browser.contentDocument.title);
+ this.__defineGetter__("location", function() browser.contentDocument.location);
+ this.__defineSetter__("location", function(val) browser.contentDocument.location = val);
+ this.__defineGetter__("contentWindow", function() browser.contentWindow);
+ this.__defineGetter__("contentDocument", function() browser.contentDocument);
+ this.__defineGetter__("favicon", function() {
+ let pageURI = NetUtil.newURI(browser.contentDocument.location);
+ let fs = Cc["@mozilla.org/browser/favicon-service;1"].
+ getService(Ci.nsIFaviconService);
+ let faviconURL;
+ try {
+ let faviconURI = fs.getFaviconForPage(pageURI);
+ faviconURL = fs.getFaviconDataAsDataURL(faviconURI);
+ } catch(ex) {
+ let data = getChromeURLContents("chrome://mozapps/skin/places/defaultFavicon.png");
+ let encoded = browser.contentWindow.btoa(data);
+ faviconURL = "data:image/png;base64," + encoded;
+ }
+ return faviconURL;
+ });
+ this.__defineGetter__("style", function() null); // TODO
+ this.__defineGetter__("index", function() win.gBrowser.getBrowserIndexForDocument(browser.contentDocument));
+ this.__defineGetter__("thumbnail", function() getThumbnailCanvasForTab(element, browser.contentWindow));
+
+ this.close = function() win.gBrowser.removeTab(element);
+ this.move = function(index) {
+ win.gBrowser.moveTabTo(element, index);
+ };
+
+ this.__defineGetter__("isPinned", function() element.pinned);
+ this.pin = function() win.gBrowser.pinTab(element);
+ this.unpin = function() win.gBrowser.unpinTab(element);
+
+ // Set up the event handlers
+ let tab = this;
+ events.filter(function(e) e != "onOpen").forEach(function(e) {
+ // create a collection for each event
+ collection.addCollectionProperty(tab, e);
+ // make tabs setter for each event, for adding via property assignment
+ tab.__defineSetter__(e, function(val) tab[e].add(val));
+ });
+
+ // listen for events, filtered on this tab
+ eventsTabDelegate.addTabDelegate(this);
+ });
+
+ /**
+ * tabs.activeTab
+ */
+ this.__defineGetter__("activeTab", function() {
+ try {
+ return window ? tabConstructor(window.gBrowser.selectedTab)
+ : tabConstructor(exports.activeTab);
+ }
+ catch (e) { }
+ return null;
+ });
+ this.__defineSetter__("activeTab", function(tab) {
+ let [tabElement, win] = getElementAndWindowForTab(tab, window);
+ if (tabElement) {
+ // set as active tab
+ win.gBrowser.selectedTab = tabElement;
+ // focus the window
+ win.focus();
+ }
+ });
+
+ this.open = function TM_open(options) {
+ open(options, tabConstructor, window);
+ }
+
+ // Set up the event handlers
+ events.forEach(function(eventHandler) {
+ // create a collection for each event
+ collection.addCollectionProperty(self, eventHandler);
+ // make tabs setter for each event, for adding via property assignment
+ self.__defineSetter__(eventHandler, function(val) self[eventHandler].add(val));
+ });
+
+ // Tracker that listens for tab events, and proxies
+ // them to registered event listeners.
+ let eventsTabDelegate = {
+ selectedTab: null,
+ tabs: [],
+ addTabDelegate: function TETT_addTabDelegate(tabObj) {
+ this.tabs.push(tabObj);
+ },
+ pushTabEvent: function TETT_pushTabEvent(event, tab) {
+ for (let callback in self[event]) {
+ require("./errors").catchAndLog(function(tab) {
+ callback(new tabConstructor(tab));
+ })(tab);
+ }
+
+ if (event != "onOpen") {
+ this.tabs.forEach(function(tabObj) {
+ if (tabObj[event].length) {
+ let [tabEl,] = getElementAndWindowForTab(tabObj, window);
+ if (tabEl == tab) {
+ for (let callback in tabObj[event])
+ require("./errors").catchAndLog(function() callback())();
+ }
+ }
+ // if being closed, remove the tab object from the cache
+ // of tabs to notify about events.
+ if (event == "onClose")
+ this.tabs.splice(this.tabs.indexOf(tabObj), 1);
+ }, this);
+ }
+ },
+ unload: function() {
+ this.selectedTab = null;
+ this.tabs.splice(0);
+ }
+ };
+ require("./unload").ensure(eventsTabDelegate);
+
+ let eventsTabTracker = new ModuleTabTracker({
+ onTrack: function TETT_onTrack(tab) {
+ eventsTabDelegate.pushTabEvent("onOpen", tab);
+ },
+ onUntrack: function TETT_onUntrack(tab) {
+ eventsTabDelegate.pushTabEvent("onClose", tab);
+ },
+ onSelect: function TETT_onSelect(tab) {
+ if (eventsTabDelegate.selectedTab)
+ eventsTabDelegate.pushTabEvent("onDeactivate", tab);
+
+ eventsTabDelegate.selectedTab = new tabConstructor(tab);
+
+ eventsTabDelegate.pushTabEvent("onActivate", tab);
+ },
+ onReady: function TETT_onReady(tab) {
+ eventsTabDelegate.pushTabEvent("onReady", tab);
+ },
+ onLoad: function TETT_onLoad(tab) {
+ eventsTabDelegate.pushTabEvent("onLoad", tab);
+ },
+ onPaint: function TETT_onPaint(tab) {
+ eventsTabDelegate.pushTabEvent("onPaint", tab);
+ }
+ }, window);
+ require("./unload").ensure(eventsTabTracker);
+
+ // Iterator for all tabs
+ this.__iterator__ = function tabsIterator() {
+ for (let i = 0; i < eventsTabTracker._tabs.length; i++)
+ yield tabConstructor(eventsTabTracker._tabs[i]);
+ }
+
+ this.__defineGetter__("length", function() eventsTabTracker._tabs.length);
+
+ // Cleanup when unloaded
+ this.unload = function TM_unload() {
+ // Unregister tabs event listeners
+ events.forEach(function(e) self[e] = []);
+ }
+ require("./unload").ensure(this);
+
+} // End of TabModule constructor
+
+/**
+ * tabs.open - open a URL in a new tab
+ */
+function open(options, tabConstructor, window) {
+ if (typeof options === "string")
+ options = { url: options };
+
+ options = apiUtils.validateOptions(options, {
+ url: {
+ is: ["string"]
+ },
+ inNewWindow: {
+ is: ["undefined", "boolean"]
+ },
+ inBackground: {
+ is: ["undefined", "boolean"]
+ },
+ isPinned: {
+ is: ["undefined", "boolean"]
+ },
+ onOpen: {
+ is: ["undefined", "function"]
+ }
+ });
+
+ if (window)
+ options.inNewWindow = false;
+
+ let win = window || require("./window-utils").activeBrowserWindow;
+
+ if (!win || options.inNewWindow)
+ openURLInNewWindow(options, tabConstructor);
+ else
+ openURLInNewTab(options, win, tabConstructor);
+}
+
+function openURLInNewWindow(options, tabConstructor) {
+ let addTabOptions = {
+ inNewWindow: true
+ };
+ if (options.onOpen) {
+ addTabOptions.onLoad = function(e) {
+ let win = e.target.defaultView;
+ let tabEl = win.gBrowser.tabContainer.childNodes[0];
+ let tabBrowser = win.gBrowser.getBrowserForTab(tabEl);
+ tabBrowser.addEventListener("load", function onLoad(e) {
+ tabBrowser.removeEventListener("load", onLoad, true);
+ let tab = tabConstructor(tabEl);
+ require("./errors").catchAndLog(function(e) options.onOpen(e))(tab);
+ }, true);
+ };
+ }
+ if (options.isPinned) {
+ addTabOptions.isPinned = true;
+ }
+ exports.addTab(options.url.toString(), addTabOptions);
+}
+
+function openURLInNewTab(options, window, tabConstructor) {
+ window.focus();
+ let tabEl = window.gBrowser.addTab(options.url.toString());
+ if (!options.inBackground)
+ window.gBrowser.selectedTab = tabEl;
+ if (options.isPinned)
+ window.gBrowser.pinTab(tabEl);
+ if (options.onOpen) {
+ let tabBrowser = window.gBrowser.getBrowserForTab(tabEl);
+ tabBrowser.addEventListener("load", function onLoad(e) {
+ // remove event handler from addTab - don't want to be notified
+ // for subsequent loads in same tab.
+ tabBrowser.removeEventListener("load", onLoad, true);
+ let tab = tabConstructor(tabEl);
+ require("./timer").setTimeout(function() {
+ require("./errors").catchAndLog(function(tab) options.onOpen(tab))(tab);
+ }, 10);
+ }, true);
+ }
+}
+
+function getElementAndWindowForTab(tabObj, window) {
+ // iterate over open windows, or use single window if provided
+ let windowIterator = window ? function() { yield window; }
+ : require("./window-utils").windowIterator;
+ for (let win in windowIterator()) {
+ if (win.gBrowser) {
+ // find the tab element at tab.index
+ let index = win.gBrowser.getBrowserIndexForDocument(tabObj.contentDocument);
+ if (index > -1)
+ return [win.gBrowser.tabContainer.getItemAtIndex(index), win];
+ }
+ }
+ return [null, null];
+}
+
+// Tracker for all tabs across all windows
+// This is tab-browser.TabTracker, but with
+// support for additional events added.
+function ModuleTabTracker(delegate, window) {
+ this._delegate = delegate;
+ this._tabs = [];
+ this._tracker = new Tracker(this, window);
+ require("./unload").ensure(this);
+}
+ModuleTabTracker.prototype = {
+ _TAB_EVENTS: ["TabOpen", "TabClose", "TabSelect", "DOMContentLoaded",
+ "load", "MozAfterPaint"],
+ _safeTrackTab: function safeTrackTab(tab) {
+ tab.addEventListener("load", this, false);
+ tab.linkedBrowser.addEventListener("MozAfterPaint", this, false);
+ this._tabs.push(tab);
+ try {
+ this._delegate.onTrack(tab);
+ } catch (e) {
+ console.exception(e);
+ }
+ },
+ _safeUntrackTab: function safeUntrackTab(tab) {
+ tab.removeEventListener("load", this, false);
+ tab.linkedBrowser.removeEventListener("MozAfterPaint", this, false);
+ var index = this._tabs.indexOf(tab);
+ if (index == -1)
+ throw new Error("internal error: tab not found");
+ this._tabs.splice(index, 1);
+ try {
+ this._delegate.onUntrack(tab);
+ } catch (e) {
+ console.exception(e);
+ }
+ },
+ _safeSelectTab: function safeSelectTab(tab) {
+ var index = this._tabs.indexOf(tab);
+ if (index == -1)
+ console.error("internal error: tab not found");
+ try {
+ if (this._delegate.onSelect)
+ this._delegate.onSelect(tab);
+ } catch (e) {
+ console.exception(e);
+ }
+ },
+ _safeDOMContentLoaded: function safeDOMContentLoaded(event) {
+ let tabBrowser = event.currentTarget;
+ let tabBrowserIndex = tabBrowser.getBrowserIndexForDocument(event.target);
+ // TODO: I'm seeing this when loading data url images
+ if (tabBrowserIndex == -1)
+ return;
+ let tab = tabBrowser.tabContainer.getItemAtIndex(tabBrowserIndex);
+ let index = this._tabs.indexOf(tab);
+ if (index == -1)
+ console.error("internal error: tab not found");
+ try {
+ if (this._delegate.onReady)
+ this._delegate.onReady(tab);
+ } catch (e) {
+ console.exception(e);
+ }
+ },
+ _safeLoad: function safeLoad(event) {
+ let tab = event.target;
+ let index = this._tabs.indexOf(tab);
+ if (index == -1)
+ console.error("internal error: tab not found");
+ try {
+ if (this._delegate.onLoad)
+ this._delegate.onLoad(tab);
+ } catch (e) {
+ console.exception(e);
+ }
+ },
+ _safeMozAfterPaint: function safeMozAfterPaint(event) {
+ let win = event.currentTarget.ownerDocument.defaultView;
+ let tabIndex = win.gBrowser.getBrowserIndexForDocument(event.target.document);
+ if (tabIndex == -1)
+ return;
+ let tab = win.gBrowser.tabContainer.getItemAtIndex(tabIndex);
+ let index = this._tabs.indexOf(tab);
+ if (index == -1)
+ console.error("internal error: tab not found");
+ try {
+ if (this._delegate.onPaint)
+ this._delegate.onPaint(tab);
+ } catch (e) {
+ console.exception(e);
+ }
+ },
+ handleEvent: function handleEvent(event) {
+ switch (event.type) {
+ case "TabOpen":
+ this._safeTrackTab(event.target);
+ break;
+ case "TabClose":
+ this._safeUntrackTab(event.target);
+ break;
+ case "TabSelect":
+ this._safeSelectTab(event.target);
+ break;
+ case "DOMContentLoaded":
+ this._safeDOMContentLoaded(event);
+ break;
+ case "load":
+ this._safeLoad(event);
+ break;
+ case "MozAfterPaint":
+ this._safeMozAfterPaint(event);
+ break;
+ default:
+ throw new Error("internal error: unknown event type: " +
+ event.type);
+ }
+ },
+ onTrack: function onTrack(tabbrowser) {
+ for (let tab in tabIterator(tabbrowser))
+ this._safeTrackTab(tab);
+ tabbrowser.tabContainer.addEventListener("TabOpen", this, false);
+ tabbrowser.tabContainer.addEventListener("TabClose", this, false);
+ tabbrowser.tabContainer.addEventListener("TabSelect", this, false);
+ tabbrowser.ownerDocument.defaultView.gBrowser.addEventListener("DOMContentLoaded", this, false);
+ },
+ onUntrack: function onUntrack(tabbrowser) {
+ for (let tab in tabIterator(tabbrowser))
+ this._safeUntrackTab(tab);
+ tabbrowser.tabContainer.removeEventListener("TabOpen", this, false);
+ tabbrowser.tabContainer.removeEventListener("TabClose", this, false);
+ tabbrowser.tabContainer.removeEventListener("TabSelect", this, false);
+ tabbrowser.ownerDocument.defaultView.gBrowser.removeEventListener("DOMContentLoaded", this, false);
+ },
+ unload: function unload() {
+ this._tracker.unload();
+ }
+};
+
+// Utility to get a thumbnail canvas from a tab object
+function getThumbnailCanvasForTab(tabEl, window) {
+ var thumbnail = window.document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
+ thumbnail.mozOpaque = true;
+ window = tabEl.linkedBrowser.contentWindow;
+ thumbnail.width = Math.ceil(window.screen.availWidth / 5.75);
+ var aspectRatio = 0.5625; // 16:9
+ thumbnail.height = Math.round(thumbnail.width * aspectRatio);
+ var ctx = thumbnail.getContext("2d");
+ var snippetWidth = window.innerWidth * .6;
+ var scale = thumbnail.width / snippetWidth;
+ ctx.scale(scale, scale);
+ ctx.drawWindow(window, window.scrollX, window.scrollY, snippetWidth, snippetWidth * aspectRatio, "rgb(255,255,255)");
+ return thumbnail;
+}
+
+// Utility to return the contents of the target of a chrome URL
+function getChromeURLContents(chromeURL) {
+ let io = Cc["@mozilla.org/network/io-service;1"].
+ getService(Ci.nsIIOService);
+ let channel = io.newChannel(chromeURL, null, null);
+ let input = channel.open();
+ let stream = Cc["@mozilla.org/binaryinputstream;1"].
+ createInstance(Ci.nsIBinaryInputStream);
+ stream.setInputStream(input);
+ let str = stream.readBytes(input.available());
+ stream.close();
+ input.close();
+ return str;
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/tabs/events.js b/tools/addon-sdk-1.7/packages/api-utils/lib/tabs/events.js
new file mode 100644
index 0000000..efb8b45
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/tabs/events.js
@@ -0,0 +1,26 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const ON_PREFIX = "on";
+const TAB_PREFIX = "Tab";
+
+const EVENTS = {
+ ready: "DOMContentLoaded",
+ open: "TabOpen",
+ close: "TabClose",
+ activate: "TabSelect",
+ deactivate: null,
+ pinned: "TabPinned",
+ unpinned: "TabUnpinned"
+}
+exports.EVENTS = EVENTS;
+
+Object.keys(EVENTS).forEach(function(name) {
+ EVENTS[name] = {
+ name: name,
+ listener: ON_PREFIX + name.charAt(0).toUpperCase() + name.substr(1),
+ dom: EVENTS[name]
+ }
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/tabs/observer.js b/tools/addon-sdk-1.7/packages/api-utils/lib/tabs/observer.js
new file mode 100644
index 0000000..e3854cb
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/tabs/observer.js
@@ -0,0 +1,93 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { EventEmitterTrait: EventEmitter } = require("../events");
+const { DOMEventAssembler } = require("../events/assembler");
+const { Trait } = require("../light-traits");
+const { getActiveTab, getTabs, getTabContainers } = require("./utils");
+const { browserWindowIterator, isBrowser } = require("../window-utils");
+const { observer: windowObserver } = require("../windows/observer");
+
+const EVENTS = {
+ "TabOpen": "open",
+ "TabClose": "close",
+ "TabSelect": "select",
+ "TabMove": "move",
+ "TabPinned": "pinned",
+ "TabUnpinned": "unpinned"
+};
+
+
+// Event emitter objects used to register listeners and emit events on them
+// when they occur.
+const observer = Trait.compose(DOMEventAssembler, EventEmitter).create({
+ /**
+ * Method is implemented by `EventEmitter` and is used just for emitting
+ * events on registered listeners.
+ */
+ _emit: Trait.required,
+ /**
+ * Events that are supported and emitted by the module.
+ */
+ supportedEventsTypes: Object.keys(EVENTS),
+ /**
+ * Function handles all the supported events on all the windows that are
+ * observed. Method is used to proxy events to the listeners registered on
+ * this event emitter.
+ * @param {Event} event
+ * Keyboard event being emitted.
+ */
+ handleEvent: function handleEvent(event) {
+ this._emit(EVENTS[event.type], event.target, event);
+ }
+});
+
+// Currently gecko does not dispatches any event on the previously selected
+// tab before / after "TabSelect" is dispatched. In order to work around this
+// limitation we keep track of selected tab and emit "deactivate" event with
+// that before emitting "activate" on selected tab.
+var selectedTab = null;
+function onTabSelect(tab) {
+ if (selectedTab !== tab) {
+ if (selectedTab) observer._emit("deactivate", selectedTab);
+ if (tab) observer._emit("activate", selectedTab = tab);
+ }
+};
+observer.on("select", onTabSelect);
+
+// We also observe opening / closing windows in order to add / remove it's
+// containers to the observed list.
+function onWindowOpen(chromeWindow) {
+ if (!isBrowser(chromeWindow)) return; // Ignore if it's not a browser window.
+ getTabContainers(chromeWindow).forEach(function (container) {
+ observer.observe(container);
+ });
+}
+windowObserver.on("open", onWindowOpen);
+
+function onWindowClose(chromeWindow) {
+ if (!isBrowser(chromeWindow)) return; // Ignore if it's not a browser window.
+ getTabContainers(chromeWindow).forEach(function (container) {
+ observer.ignore(container);
+ });
+}
+windowObserver.on("close", onWindowClose);
+
+
+// Currently gecko does not dispatches "TabSelect" events when different
+// window gets activated. To work around this limitation we emulate "select"
+// event for this case.
+windowObserver.on("activate", function onWindowActivate(chromeWindow) {
+ if (!isBrowser(chromeWindow)) return; // Ignore if it's not a browser window.
+ observer._emit("select", getActiveTab(chromeWindow));
+});
+
+// We should synchronize state, since probably we already have at least one
+// window open.
+for each (let window in browserWindowIterator()) onWindowOpen(window);
+
+exports.observer = observer;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/tabs/tab.js b/tools/addon-sdk-1.7/packages/api-utils/lib/tabs/tab.js
new file mode 100644
index 0000000..246834f
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/tabs/tab.js
@@ -0,0 +1,264 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const { Ci } = require('chrome');
+const { Trait } = require("../traits");
+const { EventEmitter } = require("../events");
+const { validateOptions } = require("../api-utils");
+const { defer } = require("../functional");
+const { EVENTS } = require("./events");
+const { getThumbnailURIForWindow } = require("../utils/thumbnail");
+const { getFaviconURIForLocation } = require("../utils/data");
+
+
+
+// Array of the inner instances of all the wrapped tabs.
+const TABS = [];
+
+/**
+ * Trait used to create tab wrappers.
+ */
+const TabTrait = Trait.compose(EventEmitter, {
+ on: Trait.required,
+ _emit: Trait.required,
+ /**
+ * Tab DOM element that is being wrapped.
+ */
+ _tab: null,
+ /**
+ * Window wrapper whose tab this object represents.
+ */
+ window: null,
+ constructor: function Tab(options) {
+ this._onReady = this._onReady.bind(this);
+ this._tab = options.tab;
+ let window = this.window = options.window;
+ // Setting event listener if was passed.
+ for each (let type in EVENTS) {
+ let listener = options[type.listener];
+ if (listener)
+ this.on(type.name, options[type.listener]);
+ if ('ready' != type.name) // window spreads this event.
+ window.tabs.on(type.name, this._onEvent.bind(this, type.name));
+ }
+
+ this.on(EVENTS.close.name, this.destroy.bind(this));
+ this._browser.addEventListener(EVENTS.ready.dom, this._onReady, true);
+
+ if (options.isPinned)
+ this.pin();
+
+ // Since we will have to identify tabs by a DOM elements facade function
+ // is used as constructor that collects all the instances and makes sure
+ // that they more then one wrapper is not created per tab.
+ return this;
+ },
+ destroy: function destroy() {
+ this._removeAllListeners();
+ this._browser.removeEventListener(EVENTS.ready.dom, this._onReady,
+ true);
+ },
+
+ /**
+ * Internal listener that emits public event 'ready' when the page of this
+ * tab is loaded.
+ */
+ _onReady: function _onReady(event) {
+ // IFrames events will bubble so we need to ignore those.
+ if (event.target == this._contentDocument)
+ this._emit(EVENTS.ready.name, this._public);
+ },
+ /**
+ * Internal tab event router. Window will emit tab related events for all it's
+ * tabs, this listener will propagate all the events for this tab to it's
+ * listeners.
+ */
+ _onEvent: function _onEvent(type, tab) {
+ if (tab == this._public)
+ this._emit(type, tab);
+ },
+ /**
+ * Browser DOM element where page of this tab is currently loaded.
+ */
+ get _browser() this._window.gBrowser.getBrowserForTab(this._tab),
+ /**
+ * Window DOM element containing this tab.
+ */
+ get _window() this._tab.ownerDocument.defaultView,
+ /**
+ * Document object of the page that is currently loaded in this tab.
+ */
+ get _contentDocument() this._browser.contentDocument,
+ /**
+ * Window object of the page that is currently loaded in this tab.
+ */
+ get _contentWindow() this._browser.contentWindow,
+
+ /**
+ * The title of the page currently loaded in the tab.
+ * Changing this property changes an actual title.
+ * @type {String}
+ */
+ get title() this._contentDocument.title,
+ set title(value) this._contentDocument.title = String(value),
+ /**
+ * Location of the page currently loaded in this tab.
+ * Changing this property will loads page under under the specified location.
+ * @type {String}
+ */
+ get url() String(this._browser.currentURI.spec),
+ set url(value) this._changeLocation(String(value)),
+ // "TabOpen" event is fired when it's still "about:blank" is loaded in the
+ // changing `location` property of the `contentDocument` has no effect since
+ // seems to be either ignored or overridden by internal listener, there for
+ // location change is enqueued for the next turn of event loop.
+ _changeLocation: defer(function(url) this._browser.loadURI(url)),
+ /**
+ * URI of the favicon for the page currently loaded in this tab.
+ * @type {String}
+ */
+ get favicon() getFaviconURIForLocation(this.url),
+ /**
+ * The CSS style for the tab
+ */
+ get style() null, // TODO
+ /**
+ * The index of the tab relative to other tabs in the application window.
+ * Changing this property will change order of the actual position of the tab.
+ * @type {Number}
+ */
+ get index()
+ this._window.gBrowser.getBrowserIndexForDocument(this._contentDocument),
+ set index(value) this._window.gBrowser.moveTabTo(this._tab, value),
+ /**
+ * Thumbnail data URI of the page currently loaded in this tab.
+ * @type {String}
+ */
+ getThumbnail: function getThumbnail()
+ getThumbnailURIForWindow(this._contentWindow),
+ /**
+ * Whether or not tab is pinned (Is an app-tab).
+ * @type {Boolean}
+ */
+ get isPinned() this._tab.pinned,
+ pin: function pin() {
+ this._window.gBrowser.pinTab(this._tab);
+ },
+ unpin: function unpin() {
+ this._window.gBrowser.unpinTab(this._tab);
+ },
+
+ /**
+ * Create a worker for this tab, first argument is options given to Worker.
+ * @type {Worker}
+ */
+ attach: function attach(options) {
+ let { Worker } = require("../content/worker");
+ options.window = this._contentWindow;
+ let worker = Worker(options);
+ worker.once("detach", function detach() {
+ worker.destroy();
+ });
+ return worker;
+ },
+
+ /**
+ * Make this tab active.
+ * Please note: That this function is called synchronous since in E10S that
+ * will be the case. Besides this function is called from a constructor where
+ * we would like to return instance before firing a 'TabActivated' event.
+ */
+ activate: defer(function activate() {
+ if (this._window) // Ignore if window is closed by the time this is invoked.
+ this._window.gBrowser.selectedTab = this._tab;
+ }),
+ /**
+ * Close the tab
+ */
+ close: function close(callback) {
+ if (callback)
+ this.once(EVENTS.close.name, callback);
+ this._window.gBrowser.removeTab(this._tab);
+ },
+ /**
+ * Reload the tab
+ */
+ reload: function reload() {
+ this._window.gBrowser.reloadTab(this._tab);
+ }
+});
+
+function Tab(options) {
+ let chromeTab = options.tab;
+ for each (let tab in TABS) {
+ if (chromeTab == tab._tab)
+ return tab._public;
+ }
+ let tab = TabTrait(options);
+ TABS.push(tab);
+ return tab._public;
+}
+Tab.prototype = TabTrait.prototype;
+exports.Tab = Tab;
+
+function Options(options) {
+ if ("string" === typeof options)
+ options = { url: options };
+
+ return validateOptions(options, {
+ url: { is: ["string"] },
+ inBackground: { is: ["undefined", "boolean"] },
+ isPinned: { is: ["undefined", "boolean"] },
+ onOpen: { is: ["undefined", "function"] },
+ onClose: { is: ["undefined", "function"] },
+ onReady: { is: ["undefined", "function"] },
+ onActivate: { is: ["undefined", "function"] },
+ onDeactivate: { is: ["undefined", "function"] }
+ });
+}
+exports.Options = Options;
+
+
+exports.getTabForWindow = function (win) {
+ // Get browser window
+ let topWindow = win.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIWebNavigation)
+ .QueryInterface(Ci.nsIDocShellTreeItem)
+ .rootTreeItem
+ .QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindow);
+ if (!topWindow.gBrowser) return null;
+
+ // Get top window object, in case we are in a content iframe
+ let topContentWindow;
+ try {
+ topContentWindow = win.top;
+ } catch(e) {
+ // It may throw if win is not a valid content window
+ return null;
+ }
+
+ function getWindowID(obj) {
+ return obj.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindowUtils)
+ .currentInnerWindowID;
+ }
+
+ // Search for related Tab
+ let topWindowId = getWindowID(topContentWindow);
+ for (let i = 0; i < topWindow.gBrowser.browsers.length; i++) {
+ let w = topWindow.gBrowser.browsers[i].contentWindow;
+ if (getWindowID(w) == topWindowId) {
+ return Tab({
+ // TODO: api-utils should not depend on addon-kit!
+ window: require("addon-kit/windows").BrowserWindow({ window: topWindow }),
+ tab: topWindow.gBrowser.tabs[i]
+ });
+ }
+ }
+
+ // We were unable to find the related tab!
+ return null;
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/tabs/utils.js b/tools/addon-sdk-1.7/packages/api-utils/lib/tabs/utils.js
new file mode 100644
index 0000000..1c411dc
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/tabs/utils.js
@@ -0,0 +1,59 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+function getTabContainer(tabBrowser) {
+ return tabBrowser.tabContainer;
+}
+exports.getTabContainer = getTabContainer;
+
+function getTabBrowsers(window) {
+ return Array.slice(window.document.getElementsByTagName("tabbrowser"));
+}
+exports.getTabBrowsers = getTabBrowsers;
+
+function getTabContainers(window) {
+ return getTabBrowsers(window).map(getTabContainer);
+}
+exports.getTabContainers = getTabContainers;
+
+function getTabs(window) {
+ return getTabContainers(window).reduce(function (tabs, container) {
+ tabs.push.apply(tabs, container.children);
+ return tabs;
+ }, []);
+}
+exports.getTabs = getTabs;
+
+function getActiveTab(window) {
+ return window.gBrowser.selectedTab;
+}
+exports.getActiveTab = getActiveTab;
+
+function getOwnerWindow(tab) {
+ return tab.ownerDocument.defaultView;
+}
+exports.getOwnerWindow = getOwnerWindow;
+
+function openTab(window, url) {
+ return window.gBrowser.addTab(url);
+}
+exports.openTab = openTab;
+
+function isTabOpen(tab) {
+ return !!tab.linkedBrowser;
+}
+exports.isTabOpen = isTabOpen;
+
+function closeTab(tab) {
+ return getOwnerWindow(tab).gBrowser.removeTab(tab);
+}
+exports.closeTab = closeTab;
+
+function activateTab(tab) {
+ getOwnerWindow(tab).gBrowser.selectedTab = tab;
+}
+exports.activateTab = activateTab;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/test.js b/tools/addon-sdk-1.7/packages/api-utils/lib/test.js
new file mode 100644
index 0000000..e69a2f4
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/test.js
@@ -0,0 +1,108 @@
+/* vim:ts=2:sts=2:sw=2:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const BaseAssert = require("./test/assert").Assert;
+const { isFunction, isObject } = require("./type");
+
+function extend(target) {
+ let descriptor = {}
+ Array.slice(arguments, 1).forEach(function(source) {
+ Object.getOwnPropertyNames(source).forEach(function onEach(name) {
+ descriptor[name] = Object.getOwnPropertyDescriptor(source, name);
+ });
+ });
+ return Object.create(target, descriptor);
+}
+
+/**
+ * Function takes test `suite` object in CommonJS format and defines all of the
+ * tests from that suite and nested suites in a jetpack format on a given
+ * `target` object. Optionally third argument `prefix` can be passed to prefix
+ * all the test names.
+ */
+function defineTestSuite(target, suite, prefix) {
+ prefix = prefix || "";
+ // If suite defines `Assert` that's what `assert` object have to be created
+ // from and passed to a test function (This allows custom assertion functions)
+ // See for details: http://wiki.commonjs.org/wiki/Unit_Testing/1.1
+ let Assert = suite.Assert || BaseAssert;
+ // Going through each item in the test suite and wrapping it into a
+ // Jetpack test format.
+ Object.keys(suite).forEach(function(key) {
+ // If name starts with test then it's a test function or suite.
+ if (key.indexOf("test") === 0) {
+ let test = suite[key];
+
+ // For each test function so we create a wrapper test function in a
+ // jetpack format and copy that to a `target` exports.
+ if (isFunction(test)) {
+
+ // Since names of the test may match across suites we use full object
+ // path as a name to avoid overriding same function.
+ target[prefix + key] = function(options) {
+
+ // Creating `assert` functions for this test.
+ let assert = Assert(options);
+
+ // If CommonJS test function expects more than one argument
+ // it means that test is async and second argument is a callback
+ // to notify that test is finished.
+ if (1 < test.length) {
+
+ // Letting test runner know that test is executed async and
+ // creating a callback function that CommonJS tests will call
+ // once it's done.
+ options.waitUntilDone();
+ test(assert, function() {
+ options.done();
+ });
+ }
+
+ // Otherwise CommonJS test is synchronous so we call it only with
+ // one argument.
+ else {
+ test(assert);
+ }
+ }
+ }
+
+ // If it's an object then it's a test suite containing test function
+ // and / or nested test suites. In that case we just extend prefix used
+ // and call this function to copy and wrap tests from nested suite.
+ else if (isObject(test)) {
+ // We need to clone `tests` instead of modifying it, since it's very
+ // likely that it is frozen (usually test suites imported modules).
+ test = extend(Object.prototype, test, {
+ Assert: test.Assert || Assert
+ });
+ defineTestSuite(target, test, prefix + key + ".");
+ }
+ }
+ });
+}
+
+/**
+ * This function is a CommonJS test runner function, but since Jetpack test
+ * runner and test format is different from CommonJS this function shims given
+ * `exports` with all its tests into a Jetpack test format so that the built-in
+ * test runner will be able to run CommonJS test without manual changes.
+ */
+exports.run = function run(exports) {
+
+ // We can't leave old properties on exports since those are test in a CommonJS
+ // format that why we move everything to a new `suite` object.
+ let suite = {};
+ Object.keys(exports).forEach(function(key) {
+ suite[key] = exports[key];
+ delete exports[key];
+ });
+
+ // Now we wrap all the CommonJS tests to a Jetpack format and define
+ // those to a given `exports` object since that where jetpack test runner
+ // will look for them.
+ defineTestSuite(exports, suite);
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/test/assert.js b/tools/addon-sdk-1.7/packages/api-utils/lib/test/assert.js
new file mode 100644
index 0000000..fa40807
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/test/assert.js
@@ -0,0 +1,331 @@
+/* vim:ts=2:sts=2:sw=2:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const { isFunction, isNull, isObject, isString, isRegExp, isArray, isDate,
+ isPrimitive, isUndefined, instanceOf, source } = require("../type");
+
+/**
+ * The `AssertionError` is defined in assert.
+ * @extends Error
+ * @example
+ * new assert.AssertionError({
+ * message: message,
+ * actual: actual,
+ * expected: expected
+ * })
+ */
+function AssertionError(options) {
+ let assertionError = Object.create(AssertionError.prototype);
+
+ if (isString(options))
+ options = { message: options };
+ if ("actual" in options)
+ assertionError.actual = options.actual;
+ if ("expected" in options)
+ assertionError.expected = options.expected;
+ if ("operator" in options)
+ assertionError.operator = options.operator;
+
+ assertionError.message = options.message;
+ assertionError.stack = new Error().stack;
+ return assertionError;
+}
+AssertionError.prototype = Object.create(Error.prototype, {
+ constructor: { value: AssertionError },
+ name: { value: "AssertionError", enumerable: true },
+ toString: { value: function toString() {
+ let value;
+ if (this.message) {
+ value = this.name + " : " + this.message;
+ }
+ else {
+ value = [
+ this.name + " : ",
+ source(this.expected),
+ this.operator,
+ source(this.actual)
+ ].join(" ");
+ }
+ return value;
+ }}
+});
+exports.AssertionError = AssertionError;
+
+function Assert(logger) {
+ return Object.create(Assert.prototype, { _log: { value: logger }});
+}
+Assert.prototype = {
+ fail: function fail(e) {
+ this._log.fail(e.message);
+ },
+ pass: function pass(message) {
+ this._log.pass(message);
+ },
+ error: function error(e) {
+ this._log.exception(e);
+ },
+ ok: function ok(value, message) {
+ if (!!!value) {
+ this.fail({
+ actual: value,
+ expected: true,
+ message: message,
+ operator: "=="
+ });
+ }
+ else {
+ this.pass(message);
+ }
+ },
+
+ /**
+ * The equality assertion tests shallow, coercive equality with `==`.
+ * @example
+ * assert.equal(1, 1, "one is one");
+ */
+ equal: function equal(actual, expected, message) {
+ if (actual == expected) {
+ this.pass(message);
+ }
+ else {
+ this.fail({
+ actual: actual,
+ expected: expected,
+ message: message,
+ operator: "=="
+ });
+ }
+ },
+
+ /**
+ * The non-equality assertion tests for whether two objects are not equal
+ * with `!=`.
+ * @example
+ * assert.notEqual(1, 2, "one is not two");
+ */
+ notEqual: function notEqual(actual, expected, message) {
+ if (actual != expected) {
+ this.pass(message);
+ }
+ else {
+ this.fail({
+ actual: actual,
+ expected: expected,
+ message: message,
+ operator: "!=",
+ });
+ }
+ },
+
+ /**
+ * The equivalence assertion tests a deep (with `===`) equality relation.
+ * @example
+ * assert.deepEqual({ a: "foo" }, { a: "foo" }, "equivalent objects")
+ */
+ deepEqual: function deepEqual(actual, expected, message) {
+ if (isDeepEqual(actual, expected)) {
+ this.pass(message);
+ }
+ else {
+ this.fail({
+ actual: actual,
+ expected: expected,
+ message: message,
+ operator: "deepEqual"
+ });
+ }
+ },
+
+ /**
+ * The non-equivalence assertion tests for any deep (with `===`) inequality.
+ * @example
+ * assert.notDeepEqual({ a: "foo" }, Object.create({ a: "foo" }),
+ * "object's inherit from different prototypes");
+ */
+ notDeepEqual: function notDeepEqual(actual, expected, message) {
+ if (!isDeepEqual(actual, expected)) {
+ this.pass(message);
+ }
+ else {
+ this.fail({
+ actual: actual,
+ expected: expected,
+ message: message,
+ operator: "notDeepEqual"
+ });
+ }
+ },
+
+ /**
+ * The strict equality assertion tests strict equality, as determined by
+ * `===`.
+ * @example
+ * assert.strictEqual(null, null, "`null` is `null`")
+ */
+ strictEqual: function strictEqual(actual, expected, message) {
+ if (actual === expected) {
+ this.pass(message);
+ }
+ else {
+ this.fail({
+ actual: actual,
+ expected: expected,
+ message: message,
+ operator: "==="
+ });
+ }
+ },
+
+ /**
+ * The strict non-equality assertion tests for strict inequality, as
+ * determined by `!==`.
+ * @example
+ * assert.notStrictEqual(null, undefined, "`null` is not `undefined`");
+ */
+ notStrictEqual: function notStrictEqual(actual, expected, message) {
+ if (actual !== expected) {
+ this.pass(message);
+ }
+ else {
+ this.fail({
+ actual: actual,
+ expected: expected,
+ message: message,
+ operator: "!=="
+ })
+ }
+ },
+
+ /**
+ * The assertion whether or not given `block` throws an exception. If optional
+ * `Error` argument is provided and it's type of function thrown error is
+ * asserted to be an instance of it, if type of `Error` is string then message
+ * of throw exception is asserted to contain it.
+ * @param {Function} block
+ * Function that is expected to throw.
+ * @param {Error|RegExp} [Error]
+ * Error constructor that is expected to be thrown or a string that
+ * must be contained by a message of the thrown exception, or a RegExp
+ * matching a message of the thrown exception.
+ * @param {String} message
+ * Description message
+ *
+ * @examples
+ *
+ * assert.throws(function block() {
+ * doSomething(4)
+ * }, "Object is expected", "Incorrect argument is passed");
+ *
+ * assert.throws(function block() {
+ * Object.create(5)
+ * }, TypeError, "TypeError is thrown");
+ */
+ throws: function throws(block, Error, message) {
+ let threw = false;
+ let exception = null;
+
+ // If third argument is not provided and second argument is a string it
+ // means that optional `Error` argument was not passed, so we shift
+ // arguments.
+ if (isString(Error) && isUndefined(message)) {
+ message = Error;
+ Error = undefined;
+ }
+
+ // Executing given `block`.
+ try {
+ block();
+ }
+ catch (e) {
+ threw = true;
+ exception = e;
+ }
+
+ // If exception was thrown and `Error` argument was not passed assert is
+ // passed.
+ if (threw && (isUndefined(Error) ||
+ // If passed `Error` is RegExp using it's test method to
+ // assert thrown exception message.
+ (isRegExp(Error) && Error.test(exception.message)) ||
+ // If passed `Error` is a constructor function testing if
+ // thrown exception is an instance of it.
+ (isFunction(Error) && instanceOf(exception, Error))))
+ {
+ this.pass(message);
+ }
+
+ // Otherwise we report assertion failure.
+ else {
+ let failure = {
+ message: message,
+ operator: "throws"
+ };
+
+ if (exception)
+ failure.actual = exception;
+
+ if (Error)
+ failure.expected = Error;
+
+ this.fail(failure);
+ }
+ }
+};
+exports.Assert = Assert;
+
+function isDeepEqual(actual, expected) {
+
+ // 7.1. All identical values are equivalent, as determined by ===.
+ if (actual === expected) {
+ return true;
+ }
+
+ // 7.2. If the expected value is a Date object, the actual value is
+ // equivalent if it is also a Date object that refers to the same time.
+ else if (isDate(actual) && isDate(expected)) {
+ return actual.getTime() === expected.getTime();
+ }
+
+ // XXX specification bug: this should be specified
+ else if (isPrimitive(actual) || isPrimitive(expected)) {
+ return expected === actual;
+ }
+
+ // 7.3. Other pairs that do not both pass typeof value == "object",
+ // equivalence is determined by ==.
+ else if (!isObject(actual) && !isObject(expected)) {
+ return actual == expected;
+ }
+
+ // 7.4. For all other Object pairs, including Array objects, equivalence is
+ // determined by having the same number of owned properties (as verified
+ // with Object.prototype.hasOwnProperty.call), the same set of keys
+ // (although not necessarily the same order), equivalent values for every
+ // corresponding key, and an identical "prototype" property. Note: this
+ // accounts for both named and indexed properties on Arrays.
+ else {
+ return actual.prototype === expected.prototype &&
+ isEquivalent(actual, expected);
+ }
+}
+
+function isEquivalent(a, b, stack) {
+ let aKeys = Object.keys(a);
+ let bKeys = Object.keys(b);
+
+ return aKeys.length === bKeys.length &&
+ isArrayEquivalent(aKeys.sort(), bKeys.sort()) &&
+ aKeys.every(function(key) {
+ return isDeepEqual(a[key], b[key], stack)
+ });
+}
+
+function isArrayEquivalent(a, b, stack) {
+ return isArray(a) && isArray(b) &&
+ a.every(function(value, index) {
+ return isDeepEqual(value, b[index]);
+ });
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/text-streams.js b/tools/addon-sdk-1.7/packages/api-utils/lib/text-streams.js
new file mode 100644
index 0000000..96217eb
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/text-streams.js
@@ -0,0 +1,240 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim:set ts=2 sw=2 sts=2 et filetype=javascript
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {Cc,Ci,Cu,components} = require("chrome");
+var NetUtil = {};
+Cu.import("resource://gre/modules/NetUtil.jsm", NetUtil);
+NetUtil = NetUtil.NetUtil;
+
+// NetUtil.asyncCopy() uses this buffer length, and since we call it, for best
+// performance we use it, too.
+const BUFFER_BYTE_LEN = 0x8000;
+const PR_UINT32_MAX = 0xffffffff;
+const DEFAULT_CHARSET = "UTF-8";
+
+exports.TextReader = TextReader;
+exports.TextWriter = TextWriter;
+
+/**
+ * An input stream that reads text from a backing stream using a given text
+ * encoding.
+ *
+ * @param inputStream
+ * The stream is backed by this nsIInputStream. It must already be
+ * opened.
+ * @param charset
+ * Text in inputStream is expected to be in this character encoding. If
+ * not given, "UTF-8" is assumed. See nsICharsetConverterManager.idl for
+ * documentation on how to determine other valid values for this.
+ */
+function TextReader(inputStream, charset) {
+ const self = this;
+ charset = checkCharset(charset);
+
+ let stream = Cc["@mozilla.org/intl/converter-input-stream;1"].
+ createInstance(Ci.nsIConverterInputStream);
+ stream.init(inputStream, charset, BUFFER_BYTE_LEN,
+ Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
+
+ let manager = new StreamManager(this, stream);
+
+ /**
+ * Reads a string from the stream. If the stream is closed, an exception is
+ * thrown.
+ *
+ * @param numChars
+ * The number of characters to read. If not given, the remainder of
+ * the stream is read.
+ * @return The string read. If the stream is already at EOS, returns the
+ * empty string.
+ */
+ this.read = function TextReader_read(numChars) {
+ manager.ensureOpened();
+
+ let readAll = false;
+ if (typeof(numChars) === "number")
+ numChars = Math.max(numChars, 0);
+ else
+ readAll = true;
+
+ let str = "";
+ let totalRead = 0;
+ let chunkRead = 1;
+
+ // Read in numChars or until EOS, whichever comes first. Note that the
+ // units here are characters, not bytes.
+ while (true) {
+ let chunk = {};
+ let toRead = readAll ?
+ PR_UINT32_MAX :
+ Math.min(numChars - totalRead, PR_UINT32_MAX);
+ if (toRead <= 0 || chunkRead <= 0)
+ break;
+
+ // The converter stream reads in at most BUFFER_BYTE_LEN bytes in a call
+ // to readString, enough to fill its byte buffer. chunkRead will be the
+ // number of characters encoded by the bytes in that buffer.
+ chunkRead = stream.readString(toRead, chunk);
+ str += chunk.value;
+ totalRead += chunkRead;
+ }
+
+ return str;
+ };
+}
+
+/**
+ * A buffered output stream that writes text to a backing stream using a given
+ * text encoding.
+ *
+ * @param outputStream
+ * The stream is backed by this nsIOutputStream. It must already be
+ * opened.
+ * @param charset
+ * Text will be written to outputStream using this character encoding.
+ * If not given, "UTF-8" is assumed. See nsICharsetConverterManager.idl
+ * for documentation on how to determine other valid values for this.
+ */
+function TextWriter(outputStream, charset) {
+ const self = this;
+ charset = checkCharset(charset);
+
+ let stream = outputStream;
+
+ // Buffer outputStream if it's not already.
+ let ioUtils = Cc["@mozilla.org/io-util;1"].getService(Ci.nsIIOUtil);
+ if (!ioUtils.outputStreamIsBuffered(outputStream)) {
+ stream = Cc["@mozilla.org/network/buffered-output-stream;1"].
+ createInstance(Ci.nsIBufferedOutputStream);
+ stream.init(outputStream, BUFFER_BYTE_LEN);
+ }
+
+ // I'd like to use nsIConverterOutputStream. But NetUtil.asyncCopy(), which
+ // we use below in writeAsync(), naturally expects its sink to be an instance
+ // of nsIOutputStream, which nsIConverterOutputStream's only implementation is
+ // not. So we use uconv and manually convert all strings before writing to
+ // outputStream.
+ let uconv = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
+ createInstance(Ci.nsIScriptableUnicodeConverter);
+ uconv.charset = charset;
+
+ let manager = new StreamManager(this, stream);
+
+ /**
+ * Flushes the backing stream's buffer.
+ */
+ this.flush = function TextWriter_flush() {
+ manager.ensureOpened();
+ stream.flush();
+ };
+
+ /**
+ * Writes a string to the stream. If the stream is closed, an exception is
+ * thrown.
+ *
+ * @param str
+ * The string to write.
+ */
+ this.write = function TextWriter_write(str) {
+ manager.ensureOpened();
+ let istream = uconv.convertToInputStream(str);
+ let len = istream.available();
+ while (len > 0) {
+ stream.writeFrom(istream, len);
+ len = istream.available();
+ }
+ istream.close();
+ };
+
+ /**
+ * Writes a string on a background thread. After the write completes, the
+ * backing stream's buffer is flushed, and both the stream and the backing
+ * stream are closed, also on the background thread. If the stream is already
+ * closed, an exception is thrown immediately.
+ *
+ * @param str
+ * The string to write.
+ * @param callback
+ * An optional function. If given, it's called as callback(error) when
+ * the write completes. error is an Error object or undefined if there
+ * was no error. Inside callback, |this| is the stream object.
+ */
+ this.writeAsync = function TextWriter_writeAsync(str, callback) {
+ manager.ensureOpened();
+ let istream = uconv.convertToInputStream(str);
+ NetUtil.asyncCopy(istream, stream, function (result) {
+ let err = components.isSuccessCode(result) ? undefined :
+ new Error("An error occured while writing to the stream: " + result);
+ if (err)
+ console.error(err);
+
+ // asyncCopy() closes its output (and input) stream.
+ manager.opened = false;
+
+ if (typeof(callback) === "function") {
+ try {
+ callback.call(self, err);
+ }
+ catch (exc) {
+ console.exception(exc);
+ }
+ }
+ });
+ };
+}
+
+// This manages the lifetime of stream, a TextReader or TextWriter. It defines
+// closed and close() on stream and registers an unload listener that closes
+// rawStream if it's still opened. It also provides ensureOpened(), which
+// throws an exception if the stream is closed.
+function StreamManager(stream, rawStream) {
+ const self = this;
+ this.rawStream = rawStream;
+ this.opened = true;
+
+ /**
+ * True iff the stream is closed.
+ */
+ stream.__defineGetter__("closed", function stream_closed() {
+ return !self.opened;
+ });
+
+ /**
+ * Closes both the stream and its backing stream. If the stream is already
+ * closed, an exception is thrown. For TextWriters, this first flushes the
+ * backing stream's buffer.
+ */
+ stream.close = function stream_close() {
+ self.ensureOpened();
+ self.unload();
+ };
+
+ require("./unload").ensure(this);
+}
+
+StreamManager.prototype = {
+ ensureOpened: function StreamManager_ensureOpened() {
+ if (!this.opened)
+ throw new Error("The stream is closed and cannot be used.");
+ },
+ unload: function StreamManager_unload() {
+ // TextWriter.writeAsync() causes rawStream to close and therefore sets
+ // opened to false, so check that we're still opened.
+ if (this.opened) {
+ // Calling close() on both an nsIUnicharInputStream and
+ // nsIBufferedOutputStream closes their backing streams. It also forces
+ // nsIOutputStreams to flush first.
+ this.rawStream.close();
+ this.opened = false;
+ }
+ }
+};
+
+function checkCharset(charset) {
+ return typeof(charset) === "string" ? charset : DEFAULT_CHARSET;
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/timer.js b/tools/addon-sdk-1.7/packages/api-utils/lib/timer.js
new file mode 100644
index 0000000..55654a8
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/timer.js
@@ -0,0 +1,78 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { CC } = require("chrome");
+const { Unknown } = require("./xpcom");
+const { when: unload } = require("./unload");
+
+const Timer = CC('@mozilla.org/timer;1', 'nsITimer');
+
+// Registry for all timers.
+const timers = (function(map, id) {
+ return Object.defineProperties(function registry(key, fallback) {
+ return key in map ? map[key] : fallback;
+ }, {
+ register: { value: function(value) (map[++id] = value, id) },
+ unregister: { value: function(key) delete map[key] },
+ forEach: { value: function(callback) Object.keys(map).forEach(callback) }
+ });
+})(Object.create(null), 0);
+
+const TimerCallback = Unknown.extend({
+ interfaces: [ 'nsITimerCallback' ],
+ initialize: function initialize(id, callback, rest) {
+ this.id = id;
+ this.callback = callback;
+ this.arguments = rest;
+ }
+});
+
+const TimeoutCallback = TimerCallback.extend({
+ type: 0, // nsITimer.TYPE_ONE_SHOT
+ notify: function notify() {
+ try {
+ timers.unregister(this.id);
+ this.callback.apply(null, this.arguments);
+ }
+ catch (error) {
+ console.exception(error);
+ }
+ }
+});
+
+const IntervalCallback = TimerCallback.extend({
+ type: 1, // nsITimer.TYPE_REPEATING_SLACK
+ notify: function notify() {
+ try {
+ this.callback.apply(null, this.arguments);
+ }
+ catch (error) {
+ console.exception(error);
+ }
+ }
+});
+
+function setTimer(TimerCallback, listener, delay) {
+ let timer = Timer();
+ let id = timers.register(timer);
+ let callback = TimerCallback.new(id, listener, Array.slice(arguments, 3));
+ timer.initWithCallback(callback, delay || 0, TimerCallback.type);
+ return id;
+}
+
+function unsetTimer(id) {
+ let timer = timers(id);
+ timers.unregister(id);
+ if (timer)
+ timer.cancel();
+}
+
+exports.setTimeout = setTimer.bind(null, TimeoutCallback);
+exports.setInterval = setTimer.bind(null, IntervalCallback);
+exports.clearTimeout = unsetTimer;
+exports.clearInterval = unsetTimer;
+
+unload(function() { timers.forEach(unsetTimer); });
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/traceback.js b/tools/addon-sdk-1.7/packages/api-utils/lib/traceback.js
new file mode 100644
index 0000000..c55fd9d
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/traceback.js
@@ -0,0 +1,123 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {Cc,Ci,components} = require("chrome");
+
+// Undo the auto-parentification of URLs done in bug 418356.
+function deParentifyURL(url) {
+ return url ? url.split(" -> ").slice(-1)[0] : url;
+}
+
+// TODO: We might want to move this function to url or some similar
+// module.
+function getLocalFile(path) {
+ var ios = Cc['@mozilla.org/network/io-service;1']
+ .getService(Ci.nsIIOService);
+ var channel = ios.newChannel(path, null, null);
+ var iStream = channel.open();
+ var siStream = Cc['@mozilla.org/scriptableinputstream;1']
+ .createInstance(Ci.nsIScriptableInputStream);
+ siStream.init(iStream);
+ var data = new String();
+ data += siStream.read(-1);
+ siStream.close();
+ iStream.close();
+ return data;
+}
+
+function safeGetFileLine(path, line) {
+ try {
+ var scheme = require("./url").URL(path).scheme;
+ // TODO: There should be an easier, more accurate way to figure out
+ // what's the case here.
+ if (!(scheme == "http" || scheme == "https"))
+ return getLocalFile(path).split("\n")[line - 1];
+ } catch (e) {}
+ return null;
+}
+
+function errorStackToJSON(stack) {
+ var lines = stack.split("\n");
+
+ var frames = [];
+ lines.forEach(
+ function(line) {
+ if (!line)
+ return;
+ var atIndex = line.indexOf("@");
+ var colonIndex = line.lastIndexOf(":");
+ var filename = deParentifyURL(line.slice(atIndex + 1, colonIndex));
+ var lineNo = parseInt(line.slice(colonIndex + 1));
+ var funcSig = line.slice(0, atIndex);
+ var funcName = funcSig.slice(0, funcSig.indexOf("("));
+ frames.unshift({filename: filename,
+ funcName: funcName,
+ lineNo: lineNo});
+ });
+
+ return frames;
+};
+
+function nsIStackFramesToJSON(frame) {
+ var stack = [];
+
+ while (frame) {
+ if (frame.filename) {
+ var filename = deParentifyURL(frame.filename);
+ stack.splice(0, 0, {filename: filename,
+ lineNo: frame.lineNumber,
+ funcName: frame.name});
+ }
+ frame = frame.caller;
+ }
+
+ return stack;
+};
+
+var fromException = exports.fromException = function fromException(e) {
+ if (e instanceof Ci.nsIException)
+ return nsIStackFramesToJSON(e.location);
+ if (e.stack && e.stack.length)
+ return errorStackToJSON(e.stack);
+ if (e.fileName && typeof(e.lineNumber == "number"))
+ return [{filename: deParentifyURL(e.fileName),
+ lineNo: e.lineNumber,
+ funcName: null}];
+ return [];
+};
+
+var get = exports.get = function get() {
+ return nsIStackFramesToJSON(components.stack.caller);
+};
+
+var format = exports.format = function format(tbOrException) {
+ if (tbOrException === undefined) {
+ tbOrException = get();
+ tbOrException.splice(-1, 1);
+ }
+
+ var tb;
+ if (typeof(tbOrException) == "object" &&
+ tbOrException.constructor.name == "Array")
+ tb = tbOrException;
+ else
+ tb = fromException(tbOrException);
+
+ var lines = ["Traceback (most recent call last):"];
+
+ tb.forEach(
+ function(frame) {
+ if (!(frame.filename || frame.lineNo || frame.funcName))
+ return;
+ lines.push(' File "' + frame.filename + '", line ' +
+ frame.lineNo + ', in ' + frame.funcName);
+ var sourceLine = safeGetFileLine(frame.filename, frame.lineNo);
+ if (sourceLine)
+ lines.push(' ' + sourceLine.trim());
+ });
+
+ return lines.join("\n");
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/traits.js b/tools/addon-sdk-1.7/packages/api-utils/lib/traits.js
new file mode 100644
index 0000000..7c1c4ec
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/traits.js
@@ -0,0 +1,183 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {
+ compose: _compose,
+ override: _override,
+ resolve: _resolve,
+ trait: _trait,
+ //create: _create,
+ required,
+} = require('./traits/core');
+
+const defineProperties = Object.defineProperties,
+ freeze = Object.freeze,
+ create = Object.create;
+
+/**
+ * Work around bug 608959 by defining the _create function here instead of
+ * importing it from traits/core. For docs on this function, see the create
+ * function in that module.
+ *
+ * FIXME: remove this workaround in favor of importing the function once that
+ * bug has been fixed.
+ */
+function _create(proto, trait) {
+ let properties = {},
+ keys = Object.getOwnPropertyNames(trait);
+ for each(let key in keys) {
+ let descriptor = trait[key];
+ if (descriptor.required &&
+ !Object.prototype.hasOwnProperty.call(proto, key))
+ throw new Error('Missing required property: ' + key);
+ else if (descriptor.conflict)
+ throw new Error('Remaining conflicting property: ' + key);
+ else
+ properties[key] = descriptor;
+ }
+ return Object.create(proto, properties);
+}
+
+/**
+ * Placeholder for `Trait.prototype`
+ */
+let TraitProto = Object.prototype;
+
+function Get(key) this[key]
+function Set(key, value) this[key] = value
+
+/**
+ * Creates anonymous trait descriptor from the passed argument, unless argument
+ * is a trait constructor. In later case trait's already existing properties
+ * descriptor is returned.
+ * This is module's internal function and is used as a gateway to a trait's
+ * internal properties descriptor.
+ * @param {Function} $
+ * Composed trait's constructor.
+ * @returns {Object}
+ * Private trait property of the composition.
+ */
+function TraitDescriptor(object)
+ (
+ 'function' == typeof object &&
+ (object.prototype == TraitProto || object.prototype instanceof Trait)
+ ) ? object._trait(TraitDescriptor) : _trait(object)
+
+function Public(instance, trait) {
+ let result = {},
+ keys = Object.getOwnPropertyNames(trait);
+ for each (let key in keys) {
+ if ('_' === key.charAt(0) && '__iterator__' !== key )
+ continue;
+ let property = trait[key],
+ descriptor = {
+ configurable: property.configurable,
+ enumerable: property.enumerable
+ };
+ if (property.get)
+ descriptor.get = property.get.bind(instance);
+ if (property.set)
+ descriptor.set = property.set.bind(instance);
+ if ('value' in property) {
+ let value = property.value;
+ if ('function' === typeof value) {
+ descriptor.value = property.value.bind(instance);
+ descriptor.writable = property.writable;
+ } else {
+ descriptor.get = Get.bind(instance, key);
+ descriptor.set = Set.bind(instance, key);
+ }
+ }
+ result[key] = descriptor;
+ }
+ return result;
+}
+
+/**
+ * This is private function that composes new trait with privates.
+ */
+function Composition(trait) {
+ function Trait() {
+ let self = _create({}, trait);
+ self._public = create(Trait.prototype, Public(self, trait));
+ delete self._public.constructor;
+ if (Object === self.constructor)
+ self.constructor = Trait;
+ else
+ return self.constructor.apply(self, arguments) || self._public;
+ return self._public;
+ }
+ defineProperties(Trait, {
+ prototype: { value: freeze(create(TraitProto, {
+ constructor: { value: constructor, writable: true }
+ }))}, // writable is `true` to avoid getters in custom ES5
+ displayName: { value: (trait.constructor || constructor).name },
+ compose: { value: compose, enumerable: true },
+ override: { value: override, enumerable: true },
+ resolve: { value: resolve, enumerable: true },
+ required: { value: required, enumerable: true },
+ _trait: { value: function _trait(caller)
+ caller === TraitDescriptor ? trait : undefined
+ }
+ });
+ return freeze(Trait);
+}
+
+/**
+ * Composes new trait out of itself and traits / property maps passed as an
+ * arguments. If two or more traits / property maps have properties with the
+ * same name, the new trait will contain a "conflict" property for that name.
+ * This is a commutative and associative operation, and the order of its
+ * arguments is not significant.
+ * @params {Object|Function}
+ * List of Traits or property maps to create traits from.
+ * @returns {Function}
+ * New trait containing the combined properties of all the traits.
+ */
+function compose() {
+ let traits = Array.slice(arguments, 0);
+ traits.push(this);
+ return Composition(_compose.apply(null, traits.map(TraitDescriptor)));
+}
+
+/**
+ * Composes a new trait with all of the combined properties of `this` and the
+ * argument traits. In contrast to `compose`, `override` immediately resolves
+ * all conflicts resulting from this composition by overriding the properties of
+ * later traits. Trait priority is from left to right. I.e. the properties of
+ * the leftmost trait are never overridden.
+ * @params {Object} trait
+ * @returns {Object}
+ */
+function override() {
+ let traits = Array.slice(arguments, 0);
+ traits.push(this);
+ return Composition(_override.apply(null, traits.map(TraitDescriptor)));
+}
+
+/**
+ * Composes new resolved trait, with all the same properties as this
+ * trait, except that all properties whose name is an own property of
+ * `resolutions` will be renamed to `resolutions[name]`. If it is
+ * `resolutions[name]` is `null` value is changed into a required property
+ * descriptor.
+ */
+function resolve(resolutions)
+ Composition(_resolve(resolutions, TraitDescriptor(this)))
+
+/**
+ * Base Trait, that all the traits are composed of.
+ */
+const Trait = Composition({
+ /**
+ * Internal property holding public API of this instance.
+ */
+ _public: { value: null, configurable: true, writable: true },
+ toString: { value: function() '[object ' + this.constructor.name + ']' }
+});
+TraitProto = Trait.prototype;
+exports.Trait = Trait;
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/traits/core.js b/tools/addon-sdk-1.7/packages/api-utils/lib/traits/core.js
new file mode 100644
index 0000000..6e802c7
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/traits/core.js
@@ -0,0 +1,317 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+// Design inspired by: http://www.traitsjs.org/
+
+// shortcuts
+const getOwnPropertyNames = Object.getOwnPropertyNames,
+ getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor,
+ hasOwn = Object.prototype.hasOwnProperty,
+ _create = Object.create;
+
+function doPropertiesMatch(object1, object2, name) {
+ // If `object1` has property with the given `name`
+ return name in object1 ?
+ // then `object2` should have it with the same value.
+ name in object2 && object1[name] === object2[name] :
+ // otherwise `object2` should not have property with the given `name`.
+ !(name in object2);
+}
+
+/**
+ * Compares two trait custom property descriptors if they are the same. If
+ * both are `conflict` or all the properties of descriptor are equal returned
+ * value will be `true`, otherwise it will be `false`.
+ * @param {Object} desc1
+ * @param {Object} desc2
+ */
+function areSame(desc1, desc2) {
+ return ('conflict' in desc1 && desc1.conflict &&
+ 'conflict' in desc2 && desc2.conflict) ||
+ (doPropertiesMatch(desc1, desc2, 'get') &&
+ doPropertiesMatch(desc1, desc2, 'set') &&
+ doPropertiesMatch(desc1, desc2, 'value') &&
+ doPropertiesMatch(desc1, desc2, 'enumerable') &&
+ doPropertiesMatch(desc1, desc2, 'required') &&
+ doPropertiesMatch(desc1, desc2, 'conflict'));
+}
+
+/**
+ * Converts array to an object whose own property names represent
+ * values of array.
+ * @param {String[]} names
+ * @returns {Object}
+ * @example
+ * Map(['foo', ...]) => { foo: true, ...}
+ */
+function Map(names) {
+ let map = {};
+ for each (let name in names)
+ map[name] = true;
+ return map;
+}
+
+
+const ERR_CONFLICT = 'Remaining conflicting property: ',
+ ERR_REQUIRED = 'Missing required property: ';
+/**
+ * Constant singleton, representing placeholder for required properties.
+ * @type {Object}
+ */
+const required = { toString: function()'<Trait.required>' };
+exports.required = required;
+
+/**
+ * Generates custom **required** property descriptor. Descriptor contains
+ * non-standard property `required` that is equal to `true`.
+ * @param {String} name
+ * property name to generate descriptor for.
+ * @returns {Object}
+ * custom property descriptor
+ */
+function Required(name) {
+ function required() { throw new Error(ERR_REQUIRED + name) }
+ return {
+ get: required,
+ set: required,
+ required: true
+ };
+}
+
+/**
+ * Generates custom **conflicting** property descriptor. Descriptor contains
+ * non-standard property `conflict` that is equal to `true`.
+ * @param {String} name
+ * property name to generate descriptor for.
+ * @returns {Object}
+ * custom property descriptor
+ */
+function Conflict(name) {
+ function conflict() { throw new Error(ERR_CONFLICT + name) }
+ return {
+ get: conflict,
+ set: conflict,
+ conflict: true
+ };
+}
+
+/**
+ * Function generates custom properties descriptor of the `object`s own
+ * properties. All the inherited properties are going to be ignored.
+ * Properties with values matching `required` singleton will be marked as
+ * 'required' properties.
+ * @param {Object} object
+ * Set of properties to generate trait from.
+ * @returns {Object}
+ * Properties descriptor of all of the `object`'s own properties.
+ */
+function trait(properties) {
+ let result = {},
+ keys = getOwnPropertyNames(properties);
+ for each (let key in keys) {
+ let descriptor = getOwnPropertyDescriptor(properties, key);
+ result[key] = (required === descriptor.value) ? Required(key) : descriptor;
+ }
+ return result;
+}
+exports.Trait = exports.trait = trait;
+
+/**
+ * Composes new trait. If two or more traits have own properties with the
+ * same name, the new trait will contain a 'conflict' property for that name.
+ * 'compose' is a commutative and associative operation, and the order of its
+ * arguments is not significant.
+ *
+ * @params {Object} trait
+ * Takes traits as an arguments
+ * @returns {Object}
+ * New trait containing the combined own properties of all the traits.
+ * @example
+ * var newTrait = compose(trait_1, trait_2, ..., trait_N);
+ */
+function compose(trait1, trait2) {
+ let traits = Array.slice(arguments, 0),
+ result = {};
+ for each (let trait in traits) {
+ let keys = getOwnPropertyNames(trait);
+ for each (let key in keys) {
+ let descriptor = trait[key];
+ // if property already exists and it's not a requirement
+ if (hasOwn.call(result, key) && !result[key].required) {
+ if (descriptor.required)
+ continue;
+ if (!areSame(descriptor, result[key]))
+ result[key] = Conflict(key);
+ } else {
+ result[key] = descriptor;
+ }
+ }
+ }
+ return result;
+}
+exports.compose = compose;
+
+/**
+ * Composes new trait with the same own properties as the original trait,
+ * except that all property names appearing in the first argument are replaced
+ * by 'required' property descriptors.
+ * @param {String[]} keys
+ * Array of strings property names.
+ * @param {Object} trait
+ * A trait some properties of which should be excluded.
+ * @returns {Object}
+ * @example
+ * var newTrait = exclude(['name', ...], trait)
+ */
+function exclude(keys, trait) {
+ let exclusions = Map(keys),
+ result = {};
+
+ keys = getOwnPropertyNames(trait);
+
+ for each (let key in keys) {
+ if (!hasOwn.call(exclusions, key) || trait[key].required)
+ result[key] = trait[key];
+ else
+ result[key] = Required(key);
+ }
+ return result;
+}
+
+/**
+ * Composes a new trait with all of the combined properties of the argument
+ * traits. In contrast to `compose`, `override` immediately resolves all
+ * conflicts resulting from this composition by overriding the properties of
+ * later traits. Trait priority is from left to right. I.e. the properties of
+ * the leftmost trait are never overridden.
+ * @params {Object} trait
+ * @returns {Object}
+ * @examples
+ * // override is associative:
+ * override(t1,t2,t3)
+ * // is equivalent to
+ * override(t1, override(t2, t3))
+ * // or
+ * to override(override(t1, t2), t3)
+ *
+ * // override is not commutative:
+ * override(t1,t2)
+ * // is not equivalent to
+ * override(t2,t1)
+ */
+function override() {
+ let traits = Array.slice(arguments, 0),
+ result = {};
+ for each (let trait in traits) {
+ let keys = getOwnPropertyNames(trait);
+ for each(let key in keys) {
+ let descriptor = trait[key];
+ if (!hasOwn.call(result, key) || result[key].required)
+ result[key] = descriptor;
+ }
+ }
+ return result;
+}
+exports.override = override;
+
+/**
+ * Composes a new trait with the same properties as the original trait, except
+ * that all properties whose name is an own property of map will be renamed to
+ * map[name], and a 'required' property for name will be added instead.
+ * @param {Object} map
+ * An object whose own properties serve as a mapping from old names to new
+ * names.
+ * @param {Object} trait
+ * A trait object
+ * @returns {Object}
+ * @example
+ * var newTrait = rename(map, trait);
+ */
+function rename(map, trait) {
+ let result = {},
+ keys = getOwnPropertyNames(trait);
+ for each(let key in keys) {
+ // must be renamed & it's not requirement
+ if (hasOwn.call(map, key) && !trait[key].required) {
+ let alias = map[key];
+ if (hasOwn.call(result, alias) && !result[alias].required)
+ result[alias] = Conflict(alias);
+ else
+ result[alias] = trait[key];
+ if (!hasOwn.call(result, key))
+ result[key] = Required(key);
+ } else { // must not be renamed or its a requirement
+ // property is not in result trait yet
+ if (!hasOwn.call(result, key))
+ result[key] = trait[key];
+ // property is already in resulted trait & it's not requirement
+ else if (!trait[key].required)
+ result[key] = Conflict(key);
+ }
+ }
+ return result;
+}
+
+/**
+* Composes new resolved trait, with all the same properties as the original
+* trait, except that all properties whose name is an own property of
+* resolutions will be renamed to `resolutions[name]`. If it is
+* `resolutions[name]` is `null` value is changed into a required property
+* descriptor.
+* function can be implemented as `rename(map,exclude(exclusions, trait))`
+* where map is the subset of mappings from oldName to newName and exclusions
+* is an array of all the keys that map to `null`.
+* Note: it's important to **first** `exclude`, **then** `rename`, since
+* `exclude` and rename are not associative.
+* @param {Object} resolutions
+* An object whose own properties serve as a mapping from old names to new
+* names, or to `null` if the property should be excluded.
+* @param {Object} trait
+* A trait object
+* @returns {Object}
+* Resolved trait with the same own properties as the original trait.
+*/
+function resolve(resolutions, trait) {
+ let renames = {},
+ exclusions = [],
+ keys = getOwnPropertyNames(resolutions);
+ for each (let key in keys) { // pre-process renamed and excluded properties
+ if (resolutions[key]) // old name -> new name
+ renames[key] = resolutions[key];
+ else // name -> undefined
+ exclusions.push(key);
+ }
+ return rename(renames, exclude(exclusions, trait));
+}
+exports.resolve = resolve;
+
+/**
+ * `create` is like `Object.create`, except that it ensures that:
+ * - an exception is thrown if 'trait' still contains required properties
+ * - an exception is thrown if 'trait' still contains conflicting
+ * properties
+ * @param {Object}
+ * prototype of the completed object
+ * @param {Object} trait
+ * trait object to be turned into a complete object
+ * @returns {Object}
+ * An object with all of the properties described by the trait.
+ */
+function create(proto, trait) {
+ let properties = {},
+ keys = getOwnPropertyNames(trait);
+ for each(let key in keys) {
+ let descriptor = trait[key];
+ if (descriptor.required && !hasOwn.call(proto, key))
+ throw new Error(ERR_REQUIRED + key);
+ else if (descriptor.conflict)
+ throw new Error(ERR_CONFLICT + key);
+ else
+ properties[key] = descriptor;
+ }
+ return _create(proto, properties);
+}
+exports.create = create;
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/type.js b/tools/addon-sdk-1.7/packages/api-utils/lib/type.js
new file mode 100644
index 0000000..56df14e
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/type.js
@@ -0,0 +1,340 @@
+/* vim:ts=2:sts=2:sw=2:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+/**
+ * Returns `true` if `value` is `undefined`.
+ * @examples
+ * var foo; isUndefined(foo); // true
+ * isUndefined(0); // false
+ */
+function isUndefined(value) {
+ return value === undefined;
+}
+exports.isUndefined = isUndefined;
+
+/**
+ * Returns `true` if value is `null`.
+ * @examples
+ * isNull(null); // true
+ * isNull(undefined); // false
+ */
+function isNull(value) {
+ return value === null;
+}
+exports.isNull = isNull;
+
+/**
+ * Returns `true` if value is a string.
+ * @examples
+ * isString("moe"); // true
+ */
+function isString(value) {
+ return typeof value === "string";
+}
+exports.isString = isString;
+
+/**
+ * Returns `true` if `value` is a number.
+ * @examples
+ * isNumber(8.4 * 5); // true
+ */
+function isNumber(value) {
+ return typeof value === "number";
+}
+exports.isNumber = isNumber;
+
+/**
+ * Returns `true` if `value` is a `RegExp`.
+ * @examples
+ * isRegExp(/moe/); // true
+ */
+function isRegExp(value) {
+ return isObject(value) && instanceOf(value, RegExp);
+}
+exports.isRegExp = isRegExp;
+
+/**
+ * Returns true if `value` is a `Date`.
+ * @examples
+ * isDate(new Date()); // true
+ */
+function isDate(value) {
+ return isObject(value) && instanceOf(value, Date);
+}
+exports.isDate = isDate;
+
+/**
+ * Returns true if object is a Function.
+ * @examples
+ * isFunction(function foo(){}) // true
+ */
+function isFunction(value) {
+ return typeof value === "function";
+}
+exports.isFunction = isFunction;
+
+/**
+ * Returns `true` if `value` is an object (please note that `null` is considered
+ * to be an atom and not an object).
+ * @examples
+ * isObject({}) // true
+ * isObject(null) // false
+ */
+function isObject(value) {
+ return typeof value === "object" && value !== null;
+}
+exports.isObject = isObject;
+
+/**
+ * Returns true if `value` is an Array.
+ * @examples
+ * isArray([1, 2, 3]) // true
+ * isArray({ 0: 'foo', length: 1 }) // false
+ */
+var isArray = Array.isArray || function isArray(value) {
+ Object.prototype.toString.call(value) === "[object Array]";
+}
+exports.isArray = isArray;
+
+/**
+ * Returns `true` if `value` is an Arguments object.
+ * @examples
+ * (function(){ return isArguments(arguments); })(1, 2, 3); // true
+ * isArguments([1,2,3]); // false
+ */
+function isArguments(value) {
+ Object.prototype.toString.call(value) === "[object Arguments]";
+}
+exports.isArguments = isArguments;
+
+/**
+ * Returns true if it is a primitive `value`. (null, undefined, number,
+ * boolean, string)
+ * @examples
+ * isPrimitive(3) // true
+ * isPrimitive('foo') // true
+ * isPrimitive({ bar: 3 }) // false
+ */
+function isPrimitive(value) {
+ return !isFunction(value) && !isObject(value);
+}
+exports.isPrimitive = isPrimitive;
+
+/**
+ * Returns `true` if given `object` is flat (it is direct decedent of
+ * `Object.prototype` or `null`).
+ * @examples
+ * isFlat({}) // true
+ * isFlat(new Type()) // false
+ */
+function isFlat(object) {
+ return isObject(object) && (isNull(Object.getPrototypeOf(object)) ||
+ isNull(Object.getPrototypeOf(
+ Object.getPrototypeOf(object))));
+}
+exports.isFlat = isFlat;
+
+/**
+ * Returns `true` if object contains no values.
+ */
+function isEmpty(object) {
+ if (isObject(object)) {
+ for (var key in object)
+ return false;
+ return true;
+ }
+ return false;
+}
+exports.isEmpty = isEmpty;
+
+/**
+ * Returns `true` if `value` is an array / flat object containing only atomic
+ * values and other flat objects.
+ */
+function isJSON(value, visited) {
+ // Adding value to array of visited values.
+ (visited || (visited = [])).push(value);
+ // If `value` is an atom return `true` cause it's valid JSON.
+ return isPrimitive(value) ||
+ // If `value` is an array of JSON values that has not been visited
+ // yet.
+ (isArray(value) && value.every(function(element) {
+ return isJSON(element, visited);
+ })) ||
+ // If `value` is a plain object containing properties with a JSON
+ // values it's a valid JSON.
+ (isFlat(value) && Object.keys(value).every(function(key) {
+ var $ = Object.getOwnPropertyDescriptor(value, key);
+ // Check every proprety of a plain object to verify that
+ // it's neither getter nor setter, but a JSON value, that
+ // has not been visited yet.
+ return ((!isObject($.value) || !~visited.indexOf($.value)) &&
+ !('get' in $) && !('set' in $) &&
+ isJSON($.value, visited));
+ }));
+}
+exports.isJSON = function (value) {
+ return isJSON(value);
+};
+
+/**
+ * Returns if `value` is an instance of a given `Type`. This is exactly same as
+ * `value instanceof Type` with a difference that `Type` can be from a scope
+ * that has a different top level object. (Like in case where `Type` is a
+ * function from different iframe / jetpack module / sandbox).
+ */
+function instanceOf(value, Type) {
+ var isConstructorNameSame;
+ var isConstructorSourceSame;
+
+ // If `instanceof` returned `true` we know result right away.
+ var isInstanceOf = value instanceof Type;
+
+ // If `instanceof` returned `false` we do ducktype check since `Type` may be
+ // from a different sandbox. If a constructor of the `value` or a constructor
+ // of the value's prototype has same name and source we assume that it's an
+ // instance of the Type.
+ if (!isInstanceOf && value) {
+ isConstructorNameSame = value.constructor.name === Type.name;
+ isConstructorSourceSame = String(value.constructor) == String(Type);
+ isInstanceOf = (isConstructorNameSame && isConstructorSourceSame) ||
+ instanceOf(Object.getPrototypeOf(value), Type);
+ }
+ return isInstanceOf;
+}
+exports.instanceOf = instanceOf;
+
+/**
+ * Function returns textual representation of a value passed to it. Function
+ * takes additional `indent` argument that is used for indentation. Also
+ * optional `limit` argument may be passed to limit amount of detail returned.
+ * @param {Object} value
+ * @param {String} [indent=" "]
+ * @param {Number} [limit]
+ */
+function source(value, indent, limit, offset, visited) {
+ var result;
+ var names;
+ var nestingIndex;
+ var isCompact = !isUndefined(limit);
+
+ indent = indent || " ";
+ offset = (offset || "");
+ result = "";
+ visited = visited || [];
+
+ if (isUndefined(value)) {
+ result += "undefined";
+ }
+ else if (isNull(value)) {
+ result += "null";
+ }
+ else if (isString(value)) {
+ result += '"' + value + '"';
+ }
+ else if (isFunction(value)) {
+ value = String(value).split("\n");
+ if (isCompact && value.length > 2) {
+ value = value.splice(0, 2);
+ value.push("...}");
+ }
+ result += value.join("\n" + offset);
+ }
+ else if (isArray(value)) {
+ if ((nestingIndex = (visited.indexOf(value) + 1))) {
+ result = "#" + nestingIndex + "#";
+ }
+ else {
+ visited.push(value);
+
+ if (isCompact)
+ value = value.slice(0, limit);
+
+ result += "[\n";
+ result += value.map(function(value) {
+ return offset + indent + source(value, indent, limit, offset + indent,
+ visited);
+ }).join(",\n");
+ result += isCompact && value.length > limit ?
+ ",\n" + offset + "...]" : "\n" + offset + "]";
+ }
+ }
+ else if (isObject(value)) {
+ if ((nestingIndex = (visited.indexOf(value) + 1))) {
+ result = "#" + nestingIndex + "#"
+ }
+ else {
+ visited.push(value)
+
+ names = Object.keys(value);
+
+ result += "{ // " + value + "\n";
+ result += (isCompact ? names.slice(0, limit) : names).map(function(name) {
+ var _limit = isCompact ? limit - 1 : limit;
+ var descriptor = Object.getOwnPropertyDescriptor(value, name);
+ var result = offset + indent + "// ";
+ var accessor;
+ if (0 <= name.indexOf(" "))
+ name = '"' + name + '"';
+
+ if (descriptor.writable)
+ result += "writable ";
+ if (descriptor.configurable)
+ result += "configurable ";
+ if (descriptor.enumerable)
+ result += "enumerable ";
+
+ result += "\n";
+ if ("value" in descriptor) {
+ result += offset + indent + name + ": ";
+ result += source(descriptor.value, indent, _limit, indent + offset,
+ visited);
+ }
+ else {
+
+ if (descriptor.get) {
+ result += offset + indent + "get " + name + " ";
+ accessor = source(descriptor.get, indent, _limit, indent + offset,
+ visited);
+ result += accessor.substr(accessor.indexOf("{"));
+ }
+
+ if (descriptor.set) {
+ result += offset + indent + "set " + name + " ";
+ accessor = source(descriptor.set, indent, _limit, indent + offset,
+ visited);
+ result += accessor.substr(accessor.indexOf("{"));
+ }
+ }
+ return result;
+ }).join(",\n");
+
+ if (isCompact) {
+ if (names.length > limit && limit > 0) {
+ result += ",\n" + offset + indent + "//...";
+ }
+ }
+ else {
+ if (names.length)
+ result += ",";
+
+ result += "\n" + offset + indent + '"__proto__": ';
+ result += source(Object.getPrototypeOf(value), indent, 0,
+ offset + indent);
+ }
+
+ result += "\n" + offset + "}";
+ }
+ }
+ else {
+ result += String(value);
+ }
+ return result;
+}
+exports.source = function (value, indentation, limit) {
+ return source(value, indentation, limit);
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/unit-test-finder.js b/tools/addon-sdk-1.7/packages/api-utils/lib/unit-test-finder.js
new file mode 100644
index 0000000..993749b
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/unit-test-finder.js
@@ -0,0 +1,76 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const file = require("./file");
+const packaging = require('@packaging');
+const memory = require('api-utils/memory');
+const suites = packaging.allTestModules;
+
+
+const NOT_TESTS = ['setup', 'teardown'];
+
+var TestFinder = exports.TestFinder = function TestFinder(options) {
+ memory.track(this);
+ this.filter = options.filter;
+ this.testInProcess = options.testInProcess === false ? false : true;
+ this.testOutOfProcess = options.testOutOfProcess === true ? true : false;
+};
+
+TestFinder.prototype = {
+ _makeTest: function _makeTest(suite, name, test) {
+ function runTest(runner) {
+ console.info("executing '" + suite + "." + name + "'");
+ test(runner);
+ }
+ return runTest;
+ },
+
+ findTests: function findTests(cb) {
+ var self = this;
+ var tests = [];
+ var filter;
+ // A filter string is {fileNameRegex}[:{testNameRegex}] - ie, a colon
+ // optionally separates a regex for the test fileName from a regex for the
+ // testName.
+ if (this.filter) {
+ var colonPos = this.filter.indexOf(':');
+ var filterFileRegex, filterNameRegex;
+ if (colonPos === -1) {
+ filterFileRegex = new RegExp(self.filter);
+ } else {
+ filterFileRegex = new RegExp(self.filter.substr(0, colonPos));
+ filterNameRegex = new RegExp(self.filter.substr(colonPos + 1));
+ }
+ // This function will first be called with just the filename; if
+ // it returns true the module will be loaded then the function
+ // called again with both the filename and the testname.
+ filter = function(filename, testname) {
+ return filterFileRegex.test(filename) &&
+ ((testname && filterNameRegex) ? filterNameRegex.test(testname)
+ : true);
+ };
+ } else
+ filter = function() {return true};
+
+ suites.forEach(
+ function(suite) {
+ var module = require(suite);
+ if (self.testInProcess)
+ for each (let name in Object.keys(module).sort()) {
+ if(NOT_TESTS.indexOf(name) === -1 && filter(suite, name)) {
+ tests.push({
+ setup: module.setup,
+ teardown: module.teardown,
+ testFunction: self._makeTest(suite, name, module[name]),
+ name: suite + "." + name
+ });
+ }
+ }
+ });
+
+ cb(tests);
+ }
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/unit-test.js b/tools/addon-sdk-1.7/packages/api-utils/lib/unit-test.js
new file mode 100644
index 0000000..4018487
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/unit-test.js
@@ -0,0 +1,440 @@
+/* vim:st=2:sts=2:sw=2:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const memory = require('api-utils/memory');
+var timer = require("./timer");
+
+exports.findAndRunTests = function findAndRunTests(options) {
+ var TestFinder = require("./unit-test-finder").TestFinder;
+ var finder = new TestFinder({
+ filter: options.filter,
+ testInProcess: options.testInProcess,
+ testOutOfProcess: options.testOutOfProcess
+ });
+ var runner = new TestRunner({fs: options.fs});
+ finder.findTests(
+ function (tests) {
+ runner.startMany({tests: tests,
+ stopOnError: options.stopOnError,
+ onDone: options.onDone});
+ });
+};
+
+var TestRunner = exports.TestRunner = function TestRunner(options) {
+ if (options) {
+ this.fs = options.fs;
+ }
+ this.console = (options && "console" in options) ? options.console : console;
+ memory.track(this);
+ this.passed = 0;
+ this.failed = 0;
+ this.testRunSummary = [];
+ this.expectFailNesting = 0;
+};
+
+TestRunner.prototype = {
+ toString: function toString() "[object TestRunner]",
+
+ DEFAULT_PAUSE_TIMEOUT: 10000,
+ PAUSE_DELAY: 500,
+
+ _logTestFailed: function _logTestFailed(why) {
+ this.test.errors[why]++;
+ if (!this.testFailureLogged) {
+ this.console.error("TEST FAILED: " + this.test.name + " (" + why + ")");
+ this.testFailureLogged = true;
+ }
+ },
+
+ pass: function pass(message) {
+ if(!this.expectFailure) {
+ this.console.info("pass:", message);
+ this.passed++;
+ this.test.passed++;
+ }
+ else {
+ this.expectFailure = false;
+ this.fail('Failure Expected: ' + message);
+ }
+ },
+
+ fail: function fail(message) {
+ if(!this.expectFailure) {
+ this._logTestFailed("failure");
+ this.console.error("fail:", message);
+ this.console.trace();
+ this.failed++;
+ this.test.failed++;
+ }
+ else {
+ this.expectFailure = false;
+ this.pass(message);
+ }
+ },
+
+ expectFail: function(callback) {
+ this.expectFailure = true;
+ callback();
+ this.expectFailure = false;
+ },
+
+ exception: function exception(e) {
+ this._logTestFailed("exception");
+ this.console.exception(e);
+ this.failed++;
+ this.test.failed++;
+ },
+
+ assertMatches: function assertMatches(string, regexp, message) {
+ if (regexp.test(string)) {
+ if (!message)
+ message = uneval(string) + " matches " + uneval(regexp);
+ this.pass(message);
+ } else {
+ var no = uneval(string) + " doesn't match " + uneval(regexp);
+ if (!message)
+ message = no;
+ else
+ message = message + " (" + no + ")";
+ this.fail(message);
+ }
+ },
+
+ assertRaises: function assertRaises(func, predicate, message) {
+ try {
+ func();
+ if (message)
+ this.fail(message + " (no exception thrown)");
+ else
+ this.fail("function failed to throw exception");
+ } catch (e) {
+ var errorMessage;
+ if (typeof(e) == "string")
+ errorMessage = e;
+ else
+ errorMessage = e.message;
+ if (typeof(predicate) == "string")
+ this.assertEqual(errorMessage, predicate, message);
+ else
+ this.assertMatches(errorMessage, predicate, message);
+ }
+ },
+
+ assert: function assert(a, message) {
+ if (!a) {
+ if (!message)
+ message = "assertion failed, value is " + a;
+ this.fail(message);
+ } else
+ this.pass(message || "assertion successful");
+ },
+
+ assertNotEqual: function assertNotEqual(a, b, message) {
+ if (a != b) {
+ if (!message)
+ message = "a != b != " + uneval(a);
+ this.pass(message);
+ } else {
+ var equality = uneval(a) + " == " + uneval(b);
+ if (!message)
+ message = equality;
+ else
+ message += " (" + equality + ")";
+ this.fail(message);
+ }
+ },
+
+ assertEqual: function assertEqual(a, b, message) {
+ if (a == b) {
+ if (!message)
+ message = "a == b == " + uneval(a);
+ this.pass(message);
+ } else {
+ var inequality = uneval(a) + " != " + uneval(b);
+ if (!message)
+ message = inequality;
+ else
+ message += " (" + inequality + ")";
+ this.fail(message);
+ }
+ },
+
+ assertNotStrictEqual: function assertNotStrictEqual(a, b, message) {
+ if (a !== b) {
+ if (!message)
+ message = "a !== b !== " + uneval(a);
+ this.pass(message);
+ } else {
+ var equality = uneval(a) + " === " + uneval(b);
+ if (!message)
+ message = equality;
+ else
+ message += " (" + equality + ")";
+ this.fail(message);
+ }
+ },
+
+ assertStrictEqual: function assertStrictEqual(a, b, message) {
+ if (a === b) {
+ if (!message)
+ message = "a === b === " + uneval(a);
+ this.pass(message);
+ } else {
+ var inequality = uneval(a) + " !== " + uneval(b);
+ if (!message)
+ message = inequality;
+ else
+ message += " (" + inequality + ")";
+ this.fail(message);
+ }
+ },
+
+ assertFunction: function assertFunction(a, message) {
+ this.assertStrictEqual('function', typeof a, message);
+ },
+
+ assertUndefined: function(a, message) {
+ this.assertStrictEqual('undefined', typeof a, message);
+ },
+
+ assertNotUndefined: function(a, message) {
+ this.assertNotStrictEqual('undefined', typeof a, message);
+ },
+
+ assertNull: function(a, message) {
+ this.assertStrictEqual(null, a, message);
+ },
+
+ assertNotNull: function(a, message) {
+ this.assertNotStrictEqual(null, a, message);
+ },
+
+ assertObject: function(a, message) {
+ this.assertStrictEqual('[object Object]', Object.prototype.toString.apply(a), message);
+ },
+
+ assertString: function(a, message) {
+ this.assertStrictEqual('[object String]', Object.prototype.toString.apply(a), message);
+ },
+
+ assertArray: function(a, message) {
+ this.assertStrictEqual('[object Array]', Object.prototype.toString.apply(a), message);
+ },
+
+ assertNumber: function(a, message) {
+ this.assertStrictEqual('[object Number]', Object.prototype.toString.apply(a), message);
+ },
+
+ done: function done() {
+ if (!this.isDone) {
+ this.isDone = true;
+ if(this.test.teardown) {
+ this.test.teardown(this);
+ }
+ if (this.waitTimeout !== null) {
+ timer.clearTimeout(this.waitTimeout);
+ this.waitTimeout = null;
+ }
+ if (this.test.passed == 0 && this.test.failed == 0) {
+ this._logTestFailed("empty test");
+ this.failed++;
+ this.test.failed++;
+ }
+
+ this.testRunSummary.push({
+ name: this.test.name,
+ passed: this.test.passed,
+ failed: this.test.failed,
+ errors: [error for (error in this.test.errors)].join(", ")
+ });
+
+ if (this.onDone !== null) {
+ var onDone = this.onDone;
+ var self = this;
+ this.onDone = null;
+ timer.setTimeout(function() { onDone(self); }, 0);
+ }
+ }
+ },
+
+ // Set of assertion functions to wait for an assertion to become true
+ // These functions take the same arguments as the TestRunner.assert* methods.
+ waitUntil: function waitUntil() {
+ return this._waitUntil(this.assert, arguments);
+ },
+
+ waitUntilNotEqual: function waitUntilNotEqual() {
+ return this._waitUntil(this.assertNotEqual, arguments);
+ },
+
+ waitUntilEqual: function waitUntilEqual() {
+ return this._waitUntil(this.assertEqual, arguments);
+ },
+
+ waitUntilMatches: function waitUntilMatches() {
+ return this._waitUntil(this.assertMatches, arguments);
+ },
+
+ /**
+ * Internal function that waits for an assertion to become true.
+ * @param {Function} assertionMethod
+ * Reference to a TestRunner assertion method like test.assert,
+ * test.assertEqual, ...
+ * @param {Array} args
+ * List of arguments to give to the previous assertion method.
+ * All functions in this list are going to be called to retrieve current
+ * assertion values.
+ */
+ _waitUntil: function waitUntil(assertionMethod, args) {
+ let count = 0;
+ let maxCount = this.DEFAULT_PAUSE_TIMEOUT / this.PAUSE_DELAY;
+
+ // We need to ensure that test is asynchronous
+ if (!this.waitTimeout)
+ this.waitUntilDone(this.DEFAULT_PAUSE_TIMEOUT);
+
+ let callback = null;
+ let finished = false;
+
+ let test = this;
+
+ // capture a traceback before we go async.
+ let traceback = require("./traceback");
+ let stack = traceback.get();
+ stack.splice(-2, 2);
+ let currentWaitStack = traceback.format(stack);
+ let timeout = null;
+
+ function loop(stopIt) {
+ timeout = null;
+
+ // Build a mockup object to fake TestRunner API and intercept calls to
+ // pass and fail methods, in order to retrieve nice error messages
+ // and assertion result
+ let mock = {
+ pass: function (msg) {
+ test.pass(msg);
+ test.waitUntilCallback = null;
+ if (callback && !stopIt)
+ callback();
+ finished = true;
+ },
+ fail: function (msg) {
+ // If we are called on test timeout, we stop the loop
+ // and print which test keeps failing:
+ if (stopIt) {
+ test.console.error("test assertion never became true:\n",
+ msg + "\n",
+ currentWaitStack);
+ if (timeout)
+ timer.clearTimeout(timeout);
+ return;
+ }
+ timeout = timer.setTimeout(loop, test.PAUSE_DELAY);
+ }
+ };
+
+ // Automatically call args closures in order to build arguments for
+ // assertion function
+ let appliedArgs = [];
+ for (let i = 0, l = args.length; i < l; i++) {
+ let a = args[i];
+ if (typeof a == "function") {
+ try {
+ a = a();
+ }
+ catch(e) {
+ test.fail("Exception when calling asynchronous assertion: " + e);
+ finished = true;
+ return;
+ }
+ }
+ appliedArgs.push(a);
+ }
+
+ // Finally call assertion function with current assertion values
+ assertionMethod.apply(mock, appliedArgs);
+ }
+ loop();
+ this.waitUntilCallback = loop;
+
+ // Return an object with `then` method, to offer a way to execute
+ // some code when the assertion passed or failed
+ return {
+ then: function (c) {
+ callback = c;
+
+ // In case of immediate positive result, we need to execute callback
+ // immediately here:
+ if (finished)
+ callback();
+ }
+ };
+ },
+
+ waitUntilDone: function waitUntilDone(ms) {
+ if (ms === undefined)
+ ms = this.DEFAULT_PAUSE_TIMEOUT;
+
+ var self = this;
+
+ function tiredOfWaiting() {
+ self._logTestFailed("timed out");
+ if (self.waitUntilCallback) {
+ self.waitUntilCallback(true);
+ self.waitUntilCallback = null;
+ }
+ self.failed++;
+ self.test.failed++;
+ self.done();
+ }
+
+ // We may already have registered a timeout callback
+ if (this.waitTimeout)
+ timer.clearTimeout(this.waitTimeout);
+
+ this.waitTimeout = timer.setTimeout(tiredOfWaiting, ms);
+ },
+
+ startMany: function startMany(options) {
+ function runNextTest(self) {
+ var test = options.tests.shift();
+ if (options.stopOnError && self.test && self.test.failed) {
+ self.console.error("aborted: test failed and --stop-on-error was specified");
+ options.onDone(self);
+ } else if (test) {
+ self.start({test: test, onDone: runNextTest});
+ } else {
+ options.onDone(self);
+ }
+ }
+ runNextTest(this);
+ },
+
+ start: function start(options) {
+ this.test = options.test;
+ this.test.passed = 0;
+ this.test.failed = 0;
+ this.test.errors = {};
+
+ this.isDone = false;
+ this.onDone = options.onDone;
+ this.waitTimeout = null;
+ this.testFailureLogged = false;
+
+ try {
+ if(this.test.setup) {
+ this.test.setup(this);
+ }
+ this.test.testFunction(this);
+ } catch (e) {
+ this.exception(e);
+ }
+ if (this.waitTimeout === null)
+ this.done();
+ }
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/unload.js b/tools/addon-sdk-1.7/packages/api-utils/lib/unload.js
new file mode 100644
index 0000000..aba5923
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/unload.js
@@ -0,0 +1,63 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// Parts of this module were taken from narwhal:
+//
+// http://narwhaljs.org
+
+var observers = [];
+var unloaders = [];
+
+var when = exports.when = function when(observer) {
+ if (observers.indexOf(observer) != -1)
+ return;
+ observers.unshift(observer);
+};
+
+var send = exports.send = function send(reason, onError) {
+ onError = onError || console.exception;
+ observers.forEach(function (observer) {
+ try {
+ observer(reason);
+ } catch (e) {
+ onError(e);
+ }
+ });
+};
+
+var ensure = exports.ensure = function ensure(obj, destructorName) {
+ if (!destructorName)
+ destructorName = "unload";
+ if (!(destructorName in obj))
+ throw new Error("object has no '" + destructorName + "' property");
+
+ let called = false;
+ let originalDestructor = obj[destructorName];
+
+ function unloadWrapper(reason) {
+ if (!called) {
+ called = true;
+ let index = unloaders.indexOf(unloadWrapper);
+ if (index == -1)
+ throw new Error("internal error: unloader not found");
+ unloaders.splice(index, 1);
+ originalDestructor.call(obj, reason);
+ originalDestructor = null;
+ destructorName = null;
+ obj = null;
+ }
+ };
+
+ unloaders.push(unloadWrapper);
+
+ obj[destructorName] = unloadWrapper;
+};
+
+when(
+ function(reason) {
+ unloaders.slice().forEach(
+ function(unloadWrapper) {
+ unloadWrapper(reason);
+ });
+ });
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/url.js b/tools/addon-sdk-1.7/packages/api-utils/lib/url.js
new file mode 100644
index 0000000..29fc12c
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/url.js
@@ -0,0 +1,113 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {Cc,Ci,Cr} = require("chrome");
+
+var ios = Cc['@mozilla.org/network/io-service;1']
+ .getService(Ci.nsIIOService);
+
+var resProt = ios.getProtocolHandler("resource")
+ .QueryInterface(Ci.nsIResProtocolHandler);
+
+function newURI(uriStr, base) {
+ try {
+ let baseURI = base ? ios.newURI(base, null, null) : null;
+ return ios.newURI(uriStr, null, baseURI);
+ }
+ catch (e if e.result == Cr.NS_ERROR_MALFORMED_URI) {
+ throw new Error("malformed URI: " + uriStr);
+ }
+ catch (e if (e.result == Cr.NS_ERROR_FAILURE ||
+ e.result == Cr.NS_ERROR_ILLEGAL_VALUE)) {
+ throw new Error("invalid URI: " + uriStr);
+ }
+}
+
+function resolveResourceURI(uri) {
+ var resolved;
+ try {
+ resolved = resProt.resolveURI(uri);
+ } catch (e if e.result == Cr.NS_ERROR_NOT_AVAILABLE) {
+ throw new Error("resource does not exist: " + uri.spec);
+ };
+ return resolved;
+}
+
+let fromFilename = exports.fromFilename = function fromFilename(path) {
+ var file = Cc['@mozilla.org/file/local;1']
+ .createInstance(Ci.nsILocalFile);
+ file.initWithPath(path);
+ return ios.newFileURI(file).spec;
+};
+
+let toFilename = exports.toFilename = function toFilename(url) {
+ var uri = newURI(url);
+ if (uri.scheme == "resource")
+ uri = newURI(resolveResourceURI(uri));
+ if (uri.scheme == "chrome") {
+ var channel = ios.newChannelFromURI(uri);
+ try {
+ channel = channel.QueryInterface(Ci.nsIFileChannel);
+ return channel.file.path;
+ } catch (e if e.result == Cr.NS_NOINTERFACE) {
+ throw new Error("chrome url isn't on filesystem: " + url);
+ }
+ }
+ if (uri.scheme == "file") {
+ var file = uri.QueryInterface(Ci.nsIFileURL).file;
+ return file.path;
+ }
+ throw new Error("cannot map to filename: " + url);
+};
+
+function URL(url, base) {
+ if (!(this instanceof URL)) {
+ return new URL(url, base);
+ }
+
+ var uri = newURI(url, base);
+
+ var userPass = null;
+ try {
+ userPass = uri.userPass ? uri.userPass : null;
+ } catch (e if e.result == Cr.NS_ERROR_FAILURE) {}
+
+ var host = null;
+ try {
+ host = uri.host;
+ } catch (e if e.result == Cr.NS_ERROR_FAILURE) {}
+
+ var port = null;
+ try {
+ port = uri.port == -1 ? null : uri.port;
+ } catch (e if e.result == Cr.NS_ERROR_FAILURE) {}
+
+ this.__defineGetter__("scheme", function() uri.scheme);
+ this.__defineGetter__("userPass", function() userPass);
+ this.__defineGetter__("host", function() host);
+ this.__defineGetter__("port", function() port);
+ this.__defineGetter__("path", function() uri.path);
+
+ Object.defineProperties(this, {
+ toString: {
+ value: function URL_toString() new String(uri.spec).toString(),
+ enumerable: false
+ },
+ valueOf: {
+ value: function() new String(uri.spec).valueOf(),
+ enumerable: false
+ },
+ toSource: {
+ value: function() new String(uri.spec).toSource(),
+ enumerable: false
+ }
+ });
+
+ return this;
+};
+
+URL.prototype = Object.create(String.prototype);
+exports.URL = URL;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/utils/data.js b/tools/addon-sdk-1.7/packages/api-utils/lib/utils/data.js
new file mode 100644
index 0000000..33356cd
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/utils/data.js
@@ -0,0 +1,71 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Cc, Ci, Cu } = require("chrome");
+const IOService = Cc["@mozilla.org/network/io-service;1"].
+ getService(Ci.nsIIOService);
+const AppShellService = Cc["@mozilla.org/appshell/appShellService;1"].
+ getService(Ci.nsIAppShellService);
+
+const { NetUtil } = Cu.import("resource://gre/modules/NetUtil.jsm");
+const FaviconService = Cc["@mozilla.org/browser/favicon-service;1"].
+ getService(Ci.nsIFaviconService);
+
+const PNG_B64 = "data:image/png;base64,";
+const DEF_FAVICON_URI = "chrome://mozapps/skin/places/defaultFavicon.png";
+let DEF_FAVICON = null;
+
+/**
+ * Takes URI of the page and returns associated favicon URI.
+ * If page under passed uri has no favicon then base64 encoded data URI of
+ * default faveicon is returned.
+ * @param {String} uri
+ * @returns {String}
+ */
+exports.getFaviconURIForLocation = function getFaviconURIForLocation(uri) {
+ let pageURI = NetUtil.newURI(uri);
+ try {
+ return FaviconService.getFaviconDataAsDataURL(
+ FaviconService.getFaviconForPage(pageURI));
+ }
+ catch(e) {
+ if (!DEF_FAVICON) {
+ DEF_FAVICON = PNG_B64 +
+ base64Encode(getChromeURIContent(DEF_FAVICON_URI));
+ }
+ return DEF_FAVICON;
+ }
+}
+
+/**
+ * Takes chrome URI and returns content under that URI.
+ * @param {String} chromeURI
+ * @returns {String}
+ */
+function getChromeURIContent(chromeURI) {
+ let channel = IOService.newChannel(chromeURI, null, null);
+ let input = channel.open();
+ let stream = Cc["@mozilla.org/binaryinputstream;1"].
+ createInstance(Ci.nsIBinaryInputStream);
+ stream.setInputStream(input);
+ let content = stream.readBytes(input.available());
+ stream.close();
+ input.close();
+ return content;
+}
+exports.getChromeURIContent = getChromeURIContent;
+
+/**
+ * Creates a base-64 encoded ASCII string from a string of binary data.
+ */
+function base64Encode(data) AppShellService.hiddenDOMWindow.btoa(String(data));
+exports.base64Encode = base64Encode;
+
+/**
+ * Decodes a string of data which has been encoded using base-64 encoding.
+ */
+function base64Decode(data) AppShellService.hiddenDOMWindow.atob(String(data));
+exports.base64Decode = base64Decode;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/utils/object.js b/tools/addon-sdk-1.7/packages/api-utils/lib/utils/object.js
new file mode 100644
index 0000000..165aa0b
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/utils/object.js
@@ -0,0 +1,46 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+/**
+ * Merges all the properties of all arguments into first argument. If two or
+ * more argument objects have own properties with the same name, the property
+ * is overridden, with precedence from right to left, implying, that properties
+ * of the object on the left are overridden by a same named property of the
+ * object on the right.
+ * @examples
+ * var a = { bar: 0, a: 'a' }
+ * var b = merge(a, { foo: 'foo', bar: 1 }, { foo: 'bar', name: 'b' });
+ * b === a // true
+ * b.a // 'a'
+ * b.foo // 'bar'
+ * b.bar // 1
+ * b.name // 'b'
+ */
+function merge(source) {
+ let descriptor = {};
+ Array.slice(arguments, 1).forEach(function onEach(properties) {
+ Object.getOwnPropertyNames(properties).forEach(function(name) {
+ descriptor[name] = Object.getOwnPropertyDescriptor(properties, name);
+ });
+ });
+ return Object.defineProperties(source, descriptor);
+}
+exports.merge = merge;
+
+/**
+ * Returns an object that inherits from the first argument and contains all the
+ * properties from all following arguments.
+ * `extend(source1, source2, source3)` is equivalent of
+ * `merge(Object.create(source1), source2, source3)`.
+ */
+function extend(source) {
+ let rest = Array.slice(arguments, 1);
+ rest.unshift(Object.create(source));
+ return merge.apply(null, rest);
+}
+exports.extend = extend;
+
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/utils/registry.js b/tools/addon-sdk-1.7/packages/api-utils/lib/utils/registry.js
new file mode 100644
index 0000000..2ce6a6e
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/utils/registry.js
@@ -0,0 +1,57 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const { EventEmitter } = require('../events');
+const unload = require('../unload');
+
+const Registry = EventEmitter.compose({
+ _registry: null,
+ _constructor: null,
+ constructor: function Registry(constructor) {
+ this._registry = [];
+ this._constructor = constructor;
+ this.on('error', this._onError = this._onError.bind(this));
+ unload.ensure(this, "_destructor");
+ },
+ _destructor: function _destructor() {
+ let _registry = this._registry.slice(0);
+ for each (let instance in _registry)
+ this._emit('remove', instance);
+ this._registry.splice(0);
+ },
+ _onError: function _onError(e) {
+ if (!this._listeners('error').length)
+ console.error(e);
+ },
+ has: function has(instance) {
+ let _registry = this._registry;
+ return (
+ (0 <= _registry.indexOf(instance)) ||
+ (instance && instance._public && 0 <= _registry.indexOf(instance._public))
+ );
+ },
+ add: function add(instance) {
+ let { _constructor, _registry } = this;
+ if (!(instance instanceof _constructor))
+ instance = new _constructor(instance);
+ if (0 > _registry.indexOf(instance)) {
+ _registry.push(instance);
+ this._emit('add', instance);
+ }
+ return instance;
+ },
+ remove: function remove(instance) {
+ let _registry = this._registry;
+ let index = _registry.indexOf(instance)
+ if (0 <= index) {
+ this._emit('remove', instance);
+ _registry.splice(index, 1);
+ }
+ }
+});
+exports.Registry = Registry;
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/utils/thumbnail.js b/tools/addon-sdk-1.7/packages/api-utils/lib/utils/thumbnail.js
new file mode 100644
index 0000000..dfd03dd
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/utils/thumbnail.js
@@ -0,0 +1,43 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Cc, Ci, Cu } = require("chrome");
+const AppShellService = Cc["@mozilla.org/appshell/appShellService;1"].
+ getService(Ci.nsIAppShellService);
+
+const NS = "http://www.w3.org/1999/xhtml";
+const COLOR = "rgb(255,255,255)";
+
+/**
+ * Creates canvas element with a thumbnail of the passed window.
+ * @param {Window} window
+ * @returns {Element}
+ */
+function getThumbnailCanvasForWindow(window) {
+ let aspectRatio = 0.5625; // 16:9
+ let thumbnail = AppShellService.hiddenDOMWindow.document
+ .createElementNS(NS, "canvas");
+ thumbnail.mozOpaque = true;
+ thumbnail.width = Math.ceil(window.screen.availWidth / 5.75);
+ thumbnail.height = Math.round(thumbnail.width * aspectRatio);
+ let ctx = thumbnail.getContext("2d");
+ let snippetWidth = window.innerWidth * .6;
+ let scale = thumbnail.width / snippetWidth;
+ ctx.scale(scale, scale);
+ ctx.drawWindow(window, window.scrollX, window.scrollY, snippetWidth,
+ snippetWidth * aspectRatio, COLOR);
+ return thumbnail;
+}
+exports.getThumbnailCanvasForWindow = getThumbnailCanvasForWindow;
+
+/**
+ * Creates Base64 encoded data URI of the thumbnail for the passed window.
+ * @param {Window} window
+ * @returns {String}
+ */
+exports.getThumbnailURIForWindow = function getThumbnailURIForWindow(window) {
+ return getThumbnailCanvasForWindow(window).toDataURL()
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/uuid.js b/tools/addon-sdk-1.7/packages/api-utils/lib/uuid.js
new file mode 100644
index 0000000..cd667ae
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/uuid.js
@@ -0,0 +1,13 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Cc, Ci, components: { ID: parseUUID } } = require('chrome');
+const { generateUUID } = Cc['@mozilla.org/uuid-generator;1'].
+ getService(Ci.nsIUUIDGenerator);
+
+// Returns `uuid`. If `id` is passed then it's parsed to `uuid` and returned
+// if not then new one is generated.
+exports.uuid = function uuid(id) id ? parseUUID(id) : generateUUID()
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/window-utils.js b/tools/addon-sdk-1.7/packages/api-utils/lib/window-utils.js
new file mode 100644
index 0000000..bd2f2d5
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/window-utils.js
@@ -0,0 +1,278 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Cc, Ci } = require("chrome");
+const { EventEmitter } = require('./events'),
+ { Trait } = require('./traits');
+const { when } = require('./unload');
+const { getInnerId, getOuterId } = require('./window-utils');
+const errors = require("./errors");
+
+const windowWatcher = Cc["@mozilla.org/embedcomp/window-watcher;1"].
+ getService(Ci.nsIWindowWatcher);
+const appShellService = Cc["@mozilla.org/appshell/appShellService;1"].
+ getService(Ci.nsIAppShellService);
+const observers = require('api-utils/observer-service');
+
+
+const XUL = 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul';
+
+/**
+ * An iterator for XUL windows currently in the application.
+ *
+ * @return A generator that yields XUL windows exposing the
+ * nsIDOMWindow interface.
+ */
+function windowIterator() {
+ let winEnum = windowWatcher.getWindowEnumerator();
+ while (winEnum.hasMoreElements())
+ yield winEnum.getNext().QueryInterface(Ci.nsIDOMWindow);
+};
+exports.windowIterator = windowIterator;
+
+/**
+ * An iterator for browser windows currently open in the application.
+ * @returns {Function}
+ * A generator that yields browser windows exposing the `nsIDOMWindow`
+ * interface.
+ */
+function browserWindowIterator() {
+ for each (let window in windowIterator()) {
+ if (isBrowser(window))
+ yield window;
+ }
+}
+exports.browserWindowIterator = browserWindowIterator;
+
+function WindowTracker(delegate) {
+ if (!(this instanceof WindowTracker)) {
+ return new WindowTracker(delegate);
+ }
+
+ this._delegate = delegate;
+ this._loadingWindows = [];
+
+ for (let window in windowIterator())
+ this._regWindow(window);
+ windowWatcher.registerNotification(this);
+
+ require("./unload").ensure(this);
+
+ return this;
+};
+
+WindowTracker.prototype = {
+ _regLoadingWindow: function _regLoadingWindow(window) {
+ this._loadingWindows.push(window);
+ window.addEventListener("load", this, true);
+ },
+
+ _unregLoadingWindow: function _unregLoadingWindow(window) {
+ var index = this._loadingWindows.indexOf(window);
+
+ if (index != -1) {
+ this._loadingWindows.splice(index, 1);
+ window.removeEventListener("load", this, true);
+ }
+ },
+
+ _regWindow: function _regWindow(window) {
+ if (window.document.readyState == "complete") {
+ this._unregLoadingWindow(window);
+ this._delegate.onTrack(window);
+ } else
+ this._regLoadingWindow(window);
+ },
+
+ _unregWindow: function _unregWindow(window) {
+ if (window.document.readyState == "complete") {
+ if (this._delegate.onUntrack)
+ this._delegate.onUntrack(window);
+ } else {
+ this._unregLoadingWindow(window);
+ }
+ },
+
+ unload: function unload() {
+ windowWatcher.unregisterNotification(this);
+ for (let window in windowIterator())
+ this._unregWindow(window);
+ },
+
+ handleEvent: errors.catchAndLog(function handleEvent(event) {
+ if (event.type == "load" && event.target) {
+ var window = event.target.defaultView;
+ if (window)
+ this._regWindow(window);
+ }
+ }),
+
+ observe: errors.catchAndLog(function observe(subject, topic, data) {
+ var window = subject.QueryInterface(Ci.nsIDOMWindow);
+ if (topic == "domwindowopened")
+ this._regWindow(window);
+ else
+ this._unregWindow(window);
+ })
+};
+exports.WindowTracker = WindowTracker;
+
+const WindowTrackerTrait = Trait.compose({
+ _onTrack: Trait.required,
+ _onUntrack: Trait.required,
+ constructor: function WindowTrackerTrait() {
+ WindowTracker({
+ onTrack: this._onTrack.bind(this),
+ onUntrack: this._onUntrack.bind(this)
+ });
+ }
+});
+exports.WindowTrackerTrait = WindowTrackerTrait;
+
+var gDocsToClose = [];
+
+function onDocUnload(event) {
+ var index = gDocsToClose.indexOf(event.target);
+ if (index == -1)
+ throw new Error("internal error: unloading document not found");
+ var document = gDocsToClose.splice(index, 1)[0];
+ // Just in case, let's remove the event listener too.
+ document.defaultView.removeEventListener("unload", onDocUnload, false);
+}
+
+onDocUnload = require("./errors").catchAndLog(onDocUnload);
+
+exports.closeOnUnload = function closeOnUnload(window) {
+ window.addEventListener("unload", onDocUnload, false);
+ gDocsToClose.push(window.document);
+};
+
+Object.defineProperties(exports, {
+ activeWindow: {
+ enumerable: true,
+ get: function() {
+ return Cc["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Ci.nsIWindowMediator)
+ .getMostRecentWindow(null);
+ },
+ set: function(window) {
+ try { window.focus(); } catch (e) { }
+ }
+ },
+ activeBrowserWindow: {
+ enumerable: true,
+ get: function() {
+ return Cc["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Ci.nsIWindowMediator)
+ .getMostRecentWindow("navigator:browser");
+ }
+ }
+});
+
+
+/**
+ * Returns the ID of the window's current inner window.
+ */
+exports.getInnerId = function(window) {
+ console.warn('require("window-utils").getInnerId is deprecated, ' +
+ 'please use require("window/utils").getInnerId instead');
+ return getInnerId(window);
+};
+
+exports.getOuterId = function(window) {
+ console.warn('require("window-utils").getOuterId is deprecated, ' +
+ 'please use require("window/utils").getOuterId instead');
+ return getOuterId(window);
+};
+
+function isBrowser(window) {
+ return window.document.documentElement.getAttribute("windowtype") ===
+ "navigator:browser";
+};
+exports.isBrowser = isBrowser;
+
+exports.hiddenWindow = appShellService.hiddenDOMWindow;
+
+function createHiddenXULFrame() {
+ return function promise(deliver) {
+ let window = appShellService.hiddenDOMWindow;
+
+ // Ensuring waiting for hidden window end of loading
+ // (The hidden window is still loading on windows/thunderbird)
+ if (window.document.readyState != "complete") {
+ window.addEventListener("load", function onload() {
+ window.removeEventListener("load", onload, false);
+ // We recurse with same arguments, when the window is ready
+ promise(deliver);
+ }, false);
+ return;
+ }
+
+ let document = window.document;
+ let isXMLDoc = (document.contentType == "application/xhtml+xml" ||
+ document.contentType == "application/vnd.mozilla.xul+xml")
+
+ if (isXMLDoc) {
+ deliver(window)
+ }
+ else {
+ let frame = document.createElement('iframe');
+ // This is ugly but we need window for XUL document in order to create
+ // browser elements.
+
+ // See bug 725323: hiddenWindow URL is different on each mozilla product
+ let prefs = Cc["@mozilla.org/preferences-service;1"].
+ getService(Ci.nsIPrefBranch);
+ let hiddenWindowURL = prefs.getCharPref("browser.hiddenWindowChromeURL", "");
+
+ frame.src = hiddenWindowURL;
+ frame.setAttribute('src', hiddenWindowURL);
+ frame.addEventListener('DOMContentLoaded', function onLoad(event) {
+ frame.removeEventListener('DOMContentLoaded', onLoad, false);
+ deliver(frame.contentWindow);
+ }, false);
+ document.documentElement.appendChild(frame);
+ }
+ }
+};
+exports.createHiddenXULFrame = createHiddenXULFrame;
+
+function createRemoteBrowser(remote) {
+ return function promise(deliver) {
+ createHiddenXULFrame()(function(hiddenWindow) {
+ let document = hiddenWindow.document;
+ let browser = document.createElementNS(XUL, "browser");
+ // Remote="true" enable everything here:
+ // http://mxr.mozilla.org/mozilla-central/source/content/base/src/nsFrameLoader.cpp#1347
+ if (remote !== false)
+ browser.setAttribute("remote","true");
+ // Type="content" is mandatory to enable stuff here:
+ // http://mxr.mozilla.org/mozilla-central/source/content/base/src/nsFrameLoader.cpp#1776
+ browser.setAttribute("type","content");
+ // We remove XBL binding to avoid execution of code that is not going to work
+ // because browser has no docShell attribute in remote mode (for example)
+ browser.setAttribute("style","-moz-binding: none;");
+ // Flex it in order to be visible (optional, for debug purpose)
+ browser.setAttribute("flex", "1");
+ document.documentElement.appendChild(browser);
+
+ // Bug 724433: do not leak this <browser> DOM node
+ when(function () {
+ document.documentElement.removeChild(browser);
+ });
+
+ // Return browser
+ deliver(browser);
+ });
+ };
+};
+exports.createRemoteBrowser = createRemoteBrowser;
+
+require("./unload").when(
+ function() {
+ gDocsToClose.slice().forEach(
+ function(doc) { doc.defaultView.close(); });
+ });
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/window/utils.js b/tools/addon-sdk-1.7/packages/api-utils/lib/window/utils.js
new file mode 100644
index 0000000..b4a8493
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/window/utils.js
@@ -0,0 +1,110 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+const { Cc, Ci } = require('chrome');
+
+const windowWatcher = Cc['@mozilla.org/embedcomp/window-watcher;1'].
+ getService(Ci.nsIWindowWatcher);
+const appShellService = Cc['@mozilla.org/appshell/appShellService;1'].
+ getService(Ci.nsIAppShellService);
+const observers = require('api-utils/observer-service');
+
+/**
+ * Returns the ID of the window's current inner window.
+ */
+function getInnerId(window) {
+ return window.QueryInterface(Ci.nsIInterfaceRequestor).
+ getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID;
+};
+exports.getInnerId = getInnerId;
+
+/**
+ * Returns the ID of the window's outer window.
+ */
+function getOuterId(window) {
+ return window.QueryInterface(Ci.nsIInterfaceRequestor).
+ getInterface(Ci.nsIDOMWindowUtils).outerWindowID;
+};
+exports.getOuterId = getOuterId;
+
+/**
+ * Returns `nsIXULWindow` for the given `nsIDOMWindow`.
+ */
+function getXULWindow(window) {
+ return window.QueryInterface(Ci.nsIInterfaceRequestor).
+ getInterface(Ci.nsIWebNavigation).
+ QueryInterface(Ci.nsIDocShellTreeItem).
+ treeOwner.QueryInterface(Ci.nsIInterfaceRequestor).
+ getInterface(Ci.nsIXULWindow);
+};
+exports.getXULWindow = getXULWindow;
+
+/**
+ * Returns `nsIBaseWindow` for the given `nsIDOMWindow`.
+ */
+function getBaseWindow(window) {
+ return window.QueryInterface(Ci.nsIInterfaceRequestor).
+ getInterface(Ci.nsIWebNavigation).
+ QueryInterface(Ci.nsIDocShell).
+ QueryInterface(Ci.nsIDocShellTreeItem).
+ treeOwner.
+ QueryInterface(Ci.nsIBaseWindow);
+}
+exports.getBaseWindow = getBaseWindow;
+
+/**
+ * Removes given window from the application's window registry. Unless
+ * `options.close` is `false` window is automatically closed on application
+ * quit.
+ * @params {nsIDOMWindow} window
+ * @params {Boolean} options.close
+ */
+function backgroundify(window, options) {
+ let base = getBaseWindow(window);
+ base.visibility = false;
+ base.enabled = false;
+ appShellService.unregisterTopLevelWindow(getXULWindow(window));
+ if (!options || options.close !== false)
+ observers.add('quit-application-granted', window.close.bind(window));
+
+ return window;
+}
+exports.backgroundify = backgroundify;
+
+/**
+ * Takes hash of options and serializes it to a features string that
+ * can be used passed to `window.open`. For more details on features string see:
+ * https://developer.mozilla.org/en/DOM/window.open#Position_and_size_features
+ */
+function serializeFeatures(options) {
+ return Object.keys(options).reduce(function(result, name) {
+ let value = options[name];
+ return result + ',' + name + '=' +
+ (value === true ? 'yes' : value === false ? 'no' : value);
+ }, '').substr(1);
+}
+
+/**
+ * Opens a top level window and returns it's `nsIDOMWindow` representation.
+ * @params {String} uri
+ * URI of the document to be loaded into window.
+ * @params {nsIDOMWindow} options.parent
+ * Used as parent for the created window.
+ * @params {String} options.name
+ * Optional name that is assigned to the window.
+ * @params {Object} options.features
+ * Map of key, values like: `{ width: 10, height: 15, chrome: true }`.
+ */
+function open(uri, options) {
+ options = options || {};
+ return windowWatcher.
+ openWindow(options.parent || null,
+ uri,
+ options.name || null,
+ serializeFeatures(options.features || {}),
+ null);
+}
+exports.open = open;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/windows/dom.js b/tools/addon-sdk-1.7/packages/api-utils/lib/windows/dom.js
new file mode 100644
index 0000000..1ff966a
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/windows/dom.js
@@ -0,0 +1,27 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+const { Trait } = require('../traits');
+
+const WindowDom = Trait.compose({
+ _window: Trait.required,
+ get title() {
+ let window = this._window;
+ return window && window.document ? window.document.title : null
+ },
+ close: function close() {
+ let window = this._window;
+ if (window) window.close();
+ return this._public;
+ },
+ activate: function activate() {
+ let window = this._window;
+ if (window) window.focus();
+ return this._public;
+ }
+});
+exports.WindowDom = WindowDom;
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/windows/loader.js b/tools/addon-sdk-1.7/packages/api-utils/lib/windows/loader.js
new file mode 100644
index 0000000..b596e73
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/windows/loader.js
@@ -0,0 +1,120 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const { Cc, Ci } = require('chrome'),
+ { setTimeout } = require("../timer"),
+ { Trait } = require('../traits'),
+
+ WM = Cc['@mozilla.org/appshell/window-mediator;1'].
+ getService(Ci.nsIWindowMediator),
+
+ URI_BROWSER = 'chrome://browser/content/browser.xul',
+ NAME = '_blank',
+ FEATURES = 'chrome,all,dialog=no',
+ PARAMS = [ URI_BROWSER, NAME, FEATURES ],
+ ON_LOAD = 'load',
+ ON_UNLOAD = 'unload',
+ STATE_LOADED = 'complete',
+ BROWSER = 'navigator:browser';
+
+/**
+ * Trait provides private `_window` property and requires `_onLoad` property
+ * that will be called when `_window` is loaded. If `_window` property value
+ * is changed with already loaded window `_onLoad` still will be called.
+ */
+const WindowLoader = Trait.compose({
+ /**
+ * Internal listener that is called when window is loaded.
+ * Please keep in mind that this trait will not handle exceptions that may
+ * be thrown by this method so method itself should take care of
+ * handling them.
+ * @param {nsIWindow} window
+ */
+ _onLoad: Trait.required,
+ _tabOptions: Trait.required,
+ /**
+ * Internal listener that is called when `_window`'s DOM 'unload' event
+ * is dispatched. Please note that this trait will not handle exceptions that
+ * may be thrown by this method so method itself should take care of
+ * handling them.
+ */
+ _onUnload: Trait.required,
+ _load: function _load() {
+ if (this.__window) return;
+ let params = PARAMS.slice()
+ params.push(this._tabOptions.map(function(options) options.url).join("|"))
+ let browser = WM.getMostRecentWindow(BROWSER);
+ this._window = browser.openDialog.apply(browser, params);
+ },
+ /**
+ * Private window who's load event is being tracked. Once window is loaded
+ * `_onLoad` is called.
+ * @type {nsIWindow}
+ */
+ get _window() this.__window,
+ set _window(window) {
+ let _window = this.__window;
+ if (!window) window = null;
+ if (window !== _window) {
+ if (_window) {
+ _window.removeEventListener(ON_UNLOAD, this.__unloadListener, false);
+ _window.removeEventListener(ON_LOAD, this.__loadListener, false);
+ }
+ if (window) {
+ window.addEventListener(
+ ON_UNLOAD,
+ this.__unloadListener ||
+ (this.__unloadListener = this._unloadListener.bind(this))
+ ,
+ false
+ );
+ this.__window = window;
+ // If window is not loaded yet setting up a listener.
+ if (STATE_LOADED != window.document.readyState) {
+ window.addEventListener(
+ ON_LOAD,
+ this.__loadListener ||
+ (this.__loadListener = this._loadListener.bind(this))
+ ,
+ false
+ );
+ }
+ else { // If window is loaded calling listener next turn of event loop.
+ this._onLoad(window)
+ }
+ }
+ }
+ },
+ __window: null,
+ /**
+ * Internal method used for listening 'load' event on the `_window`.
+ * Method takes care of removing itself from 'load' event listeners once
+ * event is being handled.
+ */
+ _loadListener: function _loadListener(event) {
+ let window = this._window;
+ if (!event.target || event.target.defaultView != window) return;
+ window.removeEventListener(ON_LOAD, this.__loadListener, false);
+ this._onLoad(window);
+ },
+ __loadListener: null,
+ /**
+ * Internal method used for listening 'unload' event on the `_window`.
+ * Method takes care of removing itself from 'unload' event listeners once
+ * event is being handled.
+ */
+ _unloadListener: function _unloadListener(event) {
+ let window = this._window;
+ if (!event.target
+ || event.target.defaultView != window
+ || STATE_LOADED != window.document.readyState
+ ) return;
+ window.removeEventListener(ON_UNLOAD, this.__unloadListener, false);
+ this._onUnload(window);
+ },
+ __unloadListener: null
+});
+exports.WindowLoader = WindowLoader;
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/windows/observer.js b/tools/addon-sdk-1.7/packages/api-utils/lib/windows/observer.js
new file mode 100644
index 0000000..45191b7
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/windows/observer.js
@@ -0,0 +1,53 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { EventEmitterTrait: EventEmitter } = require("../events");
+const { WindowTracker, windowIterator } = require("../window-utils");
+const { DOMEventAssembler } = require("../events/assembler");
+const { Trait } = require("../light-traits");
+
+// Event emitter objects used to register listeners and emit events on them
+// when they occur.
+const observer = Trait.compose(DOMEventAssembler, EventEmitter).create({
+ /**
+ * Method is implemented by `EventEmitter` and is used just for emitting
+ * events on registered listeners.
+ */
+ _emit: Trait.required,
+ /**
+ * Events that are supported and emitted by the module.
+ */
+ supportedEventsTypes: [ "activate", "deactivate" ],
+ /**
+ * Function handles all the supported events on all the windows that are
+ * observed. Method is used to proxy events to the listeners registered on
+ * this event emitter.
+ * @param {Event} event
+ * Keyboard event being emitted.
+ */
+ handleEvent: function handleEvent(event) {
+ this._emit(event.type, event.target, event);
+ }
+});
+
+// Using `WindowTracker` to track window events.
+WindowTracker({
+ onTrack: function onTrack(chromeWindow) {
+ observer._emit("open", chromeWindow);
+ observer.observe(chromeWindow);
+ },
+ onUntrack: function onUntrack(chromeWindow) {
+ observer._emit("close", chromeWindow);
+ observer.ignore(chromeWindow);
+ }
+});
+
+// Making observer aware of already opened windows.
+for each (let window in windowIterator())
+ observer.observe(window);
+
+exports.observer = observer;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/windows/tabs.js b/tools/addon-sdk-1.7/packages/api-utils/lib/windows/tabs.js
new file mode 100644
index 0000000..231a22e
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/windows/tabs.js
@@ -0,0 +1,178 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const { Trait } = require("../traits");
+const { List } = require("../list");
+const { Tab, Options } = require("../tabs/tab");
+const { EventEmitter } = require("../events");
+const { EVENTS } = require("../tabs/events");
+const { getOwnerWindow, getActiveTab, getTabs,
+ openTab, activateTab } = require("../tabs/utils");
+const { observer: tabsObserver } = require("../tabs/observer");
+
+const TAB_BROWSER = "tabbrowser";
+
+/**
+ * This is a trait that is used in composition of window wrapper. Trait tracks
+ * tab related events of the wrapped window in order to keep track of open
+ * tabs and maintain their wrappers. Every new tab gets wrapped and jetpack
+ * type event is emitted.
+ */
+const WindowTabTracker = Trait.compose({
+ /**
+ * Chrome window whose tabs are tracked.
+ */
+ _window: Trait.required,
+ /**
+ * Function used to emit events.
+ */
+ _emit: EventEmitter.required,
+ _tabOptions: Trait.required,
+ /**
+ * Function to add event listeners.
+ */
+ on: EventEmitter.required,
+ removeListener: EventEmitter.required,
+ /**
+ * Initializes tab tracker for a browser window.
+ */
+ _initWindowTabTracker: function _initWindowTabTracker() {
+ // Ugly hack that we have to remove at some point (see Bug 658059). At this
+ // point it is necessary to invoke lazy `tabs` getter on the windows object
+ // which creates a `TabList` instance.
+ this.tabs;
+ // Binding all methods used as event listeners to the instance.
+ this._onTabReady = this._emitEvent.bind(this, "ready");
+ this._onTabOpen = this._onTabEvent.bind(this, "open");
+ this._onTabClose = this._onTabEvent.bind(this, "close");
+ this._onTabActivate = this._onTabEvent.bind(this, "activate");
+ this._onTabDeactivate = this._onTabEvent.bind(this, "deactivate");
+ this._onTabPinned = this._onTabEvent.bind(this, "pinned");
+ this._onTabUnpinned = this._onTabEvent.bind(this, "unpinned");
+
+ for each (let tab in getTabs(this._window)) {
+ // We emulate "open" events for all open tabs since gecko does not emits
+ // them on the tabs that new windows are open with. Also this is
+ // necessary to synchronize tabs lists with an actual state.
+ this._onTabOpen(tab);
+ }
+ // We also emulate "activate" event so that it's picked up by a tab list.
+ this._onTabActivate(getActiveTab(this._window));
+
+ // Setting up event listeners
+ tabsObserver.on("open", this._onTabOpen);
+ tabsObserver.on("close", this._onTabClose);
+ tabsObserver.on("activate", this._onTabActivate);
+ tabsObserver.on("deactivate", this._onTabDeactivate);
+ tabsObserver.on("pinned", this._onTabPinned);
+ tabsObserver.on("unpinned", this._onTabUnpinned);
+ },
+ _destroyWindowTabTracker: function _destroyWindowTabTracker() {
+ // We emulate close events on all tabs, since gecko does not emits such
+ // events by itself.
+ for each (let tab in this.tabs)
+ this._emitEvent("close", tab);
+
+ this._tabs._clear();
+
+ tabsObserver.removeListener("open", this._onTabOpen);
+ tabsObserver.removeListener("close", this._onTabClose);
+ tabsObserver.removeListener("activate", this._onTabActivate);
+ tabsObserver.removeListener("deactivate", this._onTabDeactivate);
+ },
+ _onTabEvent: function _onTabEvent(type, tab) {
+ if (this._window === getOwnerWindow(tab)) {
+ let options = this._tabOptions.shift() || {};
+ options.tab = tab;
+ options.window = this._public;
+ // creating tab wrapper and adding listener to "ready" events.
+ let wrappedTab = Tab(options);
+
+ // Setting up an event listener for ready events.
+ if (type === "open")
+ wrappedTab.on("ready", this._onTabReady);
+
+ this._emitEvent(type, wrappedTab);
+ }
+ },
+ _emitEvent: function _emitEvent(type, tab) {
+ // Notifies combined tab list that tab was added / removed.
+ tabs._emit(type, tab);
+ // Notifies contained tab list that window was added / removed.
+ this._tabs._emit(type, tab);
+ }
+});
+exports.WindowTabTracker = WindowTabTracker;
+
+/**
+ * This trait is used to create live representation of open tab lists. Each
+ * window wrapper's tab list is represented by an object created from this
+ * trait. It is also used to represent list of all the open windows. Trait is
+ * composed out of `EventEmitter` in order to emit 'TabOpen', 'TabClose' events.
+ * **Please note** that objects created by this trait can't be exposed outside
+ * instead you should expose it's `_public` property, see comments in
+ * constructor for details.
+ */
+const TabList = List.resolve({ constructor: "_init" }).compose(
+ // This is ugly, but necessary. Will be removed by #596248
+ EventEmitter.resolve({ toString: null }),
+ Trait.compose({
+ on: Trait.required,
+ _emit: Trait.required,
+ constructor: function TabList(options) {
+ this._window = options.window;
+ // Add new items to the list
+ this.on(EVENTS.open.name, this._add.bind(this));
+ // Remove closed items from the list
+ this.on(EVENTS.close.name, this._remove.bind(this));
+
+ // Set value whenever new tab becomes active.
+ this.on("activate", function onTabActivate(tab) {
+ this._activeTab = tab;
+ }.bind(this));
+ // Initialize list.
+ this._init();
+ // This list is not going to emit any events, object holding this list
+ // will do it instead, to make that possible we return a private API.
+ return this;
+ },
+ get activeTab() this._activeTab,
+ _activeTab: null,
+
+ open: function open(options) {
+ options = Options(options);
+ this._window._tabOptions.push(options);
+ let tab = openTab(this._window._window, options.url);
+ if (!options.inBackground)
+ activateTab(tab);
+ }
+ // This is ugly, but necessary. Will be removed by #596248
+ }).resolve({ toString: null })
+);
+
+/**
+ * Combined list of all open tabs on all the windows.
+ * type {TabList}
+ */
+var tabs = TabList({ window: null });
+exports.tabs = tabs._public;
+
+/**
+ * Trait is a part of composition that represents window wrapper. This trait is
+ * composed out of `WindowTabTracker` that allows it to keep track of open tabs
+ * on the window being wrapped.
+ */
+const WindowTabs = Trait.compose(
+ WindowTabTracker,
+ Trait.compose({
+ _window: Trait.required,
+ /**
+ * List of tabs
+ */
+ get tabs() (this._tabs || (this._tabs = TabList({ window: this })))._public,
+ _tabs: null,
+ })
+);
+exports.WindowTabs = WindowTabs;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/xhr.js b/tools/addon-sdk-1.7/packages/api-utils/lib/xhr.js
new file mode 100644
index 0000000..b7808dc
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/xhr.js
@@ -0,0 +1,150 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {Cc,Ci} = require("chrome");
+const memory = require('api-utils/memory');
+
+// ## Implementation Notes ##
+//
+// Making `XMLHttpRequest` objects available to Jetpack code involves a
+// few key principles universal to all low-level module implementations:
+//
+// * **Unloadability**. A Jetpack-based extension using this module can be
+// asked to unload itself at any time, e.g. because the user decides to
+// uninstall or disable the extension. This means we need to keep track of
+// all in-progress reqests and abort them on unload.
+//
+// * **Developer-Ergonomic Tracebacks**. Whenever an exception is raised
+// by a Jetpack-based extension, we want it to be logged in a
+// place that is specific to that extension--so that a developer
+// can distinguish it from an error on a web page or in another
+// extension, for instance. We also want it to be logged with a
+// full stack traceback, which the Mozilla platform doesn't usually
+// do.
+//
+// Because of this, we don't actually want to give the Mozilla
+// platform's "real" XHR implementation to clients, but instead provide
+// a simple wrapper that trivially delegates to the implementation in
+// all cases except where callbacks are involved: whenever Mozilla
+// platform code calls into the extension, such as during the XHR's
+// `onreadystatechange` callback, we want to wrap the client's callback
+// in a try-catch clause that traps any exceptions raised by the
+// callback and logs them via console.exception() instead of allowing
+// them to propagate back into Mozilla platform code.
+
+// This is a private list of all active requests, so we know what to
+// abort if we're asked to unload.
+var requests = [];
+
+// Events on XHRs that we should listen for, so we know when to remove
+// a request from our private list.
+const TERMINATE_EVENTS = ["load", "error", "abort"];
+
+// Read-only properties of XMLHttpRequest objects that we want to
+// directly delegate to.
+const READ_ONLY_PROPS = ["readyState", "responseText", "responseXML",
+ "status", "statusText"];
+
+// Methods of XMLHttpRequest that we want to directly delegate to.
+const DELEGATED_METHODS = ["abort", "getAllResponseHeaders",
+ "getResponseHeader", "overrideMimeType",
+ "send", "sendAsBinary", "setRequestHeader",
+ "open"];
+
+var getRequestCount = exports.getRequestCount = function getRequestCount() {
+ return requests.length;
+};
+
+var XMLHttpRequest = exports.XMLHttpRequest = function XMLHttpRequest() {
+ var req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
+ .createInstance(Ci.nsIXMLHttpRequest);
+ // For the sake of simplicity, don't tie this request to any UI.
+ req.mozBackgroundRequest = true;
+
+ memory.track(req, "XMLHttpRequest");
+
+ this._req = req;
+ this._orsc = null;
+
+ requests.push(this);
+
+ var self = this;
+
+ this._boundCleanup = function _boundCleanup() {
+ self._cleanup();
+ };
+
+ TERMINATE_EVENTS.forEach(
+ function(name) {
+ self._req.addEventListener(name, self._boundCleanup, false);
+ });
+};
+
+XMLHttpRequest.prototype = {
+ _cleanup: function _cleanup() {
+ this.onreadystatechange = null;
+ var index = requests.indexOf(this);
+ if (index != -1) {
+ var self = this;
+ TERMINATE_EVENTS.forEach(
+ function(name) {
+ self._req.removeEventListener(name, self._boundCleanup, false);
+ });
+ requests.splice(index, 1);
+ }
+ },
+ _unload: function _unload() {
+ this._req.abort();
+ this._cleanup();
+ },
+ addEventListener: function addEventListener() {
+ throw new Error("not implemented");
+ },
+ removeEventListener: function removeEventListener() {
+ throw new Error("not implemented");
+ },
+ set upload(newValue) {
+ throw new Error("not implemented");
+ },
+ get onreadystatechange() {
+ return this._orsc;
+ },
+ set onreadystatechange(cb) {
+ this._orsc = cb;
+ if (cb) {
+ var self = this;
+ this._req.onreadystatechange = function() {
+ try {
+ self._orsc.apply(self, arguments);
+ } catch (e) {
+ console.exception(e);
+ }
+ };
+ } else
+ this._req.onreadystatechange = null;
+ }
+};
+
+READ_ONLY_PROPS.forEach(
+ function(name) {
+ XMLHttpRequest.prototype.__defineGetter__(
+ name,
+ function() {
+ return this._req[name];
+ });
+ });
+
+DELEGATED_METHODS.forEach(
+ function(name) {
+ XMLHttpRequest.prototype[name] = function() {
+ return this._req[name].apply(this._req, arguments);
+ };
+ });
+
+require("./unload").when(
+ function() {
+ requests.slice().forEach(function(request) { request._unload(); });
+ });
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/xpcom.js b/tools/addon-sdk-1.7/packages/api-utils/lib/xpcom.js
new file mode 100644
index 0000000..efdf873
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/xpcom.js
@@ -0,0 +1,207 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Cc, Ci, Cr, Cm, components: { classesByID } } = require('chrome');
+const { registerFactory, unregisterFactory, isCIDRegistered } =
+ Cm.QueryInterface(Ci.nsIComponentRegistrar);
+
+const { when: unload } = require('./unload');
+const { Base } = require('./base');
+const { uuid } = require('./uuid');
+
+// This is a base prototype, that provides bare bones of XPCOM. JS based
+// components can be easily implement by extending it.
+const Unknown = Base.extend({
+ // Method `extend` is overridden so that resulting object will contain
+ // `interfaces` array property, containing elements from ancestor and all
+ // provided sources.
+ extend: function extend() {
+ let args = Array.slice(arguments);
+ return Base.extend.apply(this, args.concat([{
+ interfaces: args.reduce(function(interfaces, source) {
+ // If given source has `interfaces` property concatenate it's elements
+ // them resulting `interfaces` array, otherwise return resulting
+ // `interfaces` array.
+ return 'interfaces' in source ? source.interfaces.concat(interfaces)
+ : interfaces;
+ }, this.interfaces)
+ }]));
+ },
+ /**
+ * The `QueryInterface` method provides runtime type discovery used by XPCOM.
+ * This method return quired instance of `this` if given `iid` is listed in
+ * the `interfaces` property.
+ */
+ QueryInterface: function QueryInterface(iid) {
+ // For some reason there are cases when `iid` is `null`. In such cases we
+ // just return `this`. Otherwise we verify that component implements given
+ // `iid` interface.
+ if (iid && !this.interfaces.some(function(id) iid.equals(Ci[id])))
+ throw Cr.NS_ERROR_NO_INTERFACE;
+ return this;
+ },
+ /**
+ * Array of `XPCOM` interfaces (as strings) implemented by this component. All
+ * components implement `nsISupports` by default which is default value here.
+ * Provide array of interfaces implemented by an object when extending, to
+ * append them to this list (Please note that there is no need to repeat
+ * interfaces implemented by super as they will be added automatically).
+ */
+ interfaces: [ 'nsISupports' ]
+});
+exports.Unknown = Unknown;
+
+// Base exemplar for creating instances implementing `nsIFactory` interface,
+// that maybe registered into runtime via `register` function. Instances of
+// this factory create instances of enclosed component on `createInstance`.
+const Factory = Unknown.extend({
+ interfaces: [ 'nsIFactory' ],
+ /**
+ * All the descendants will get auto generated `id` (also known as `classID`
+ * in XPCOM world) unless one is manually provided.
+ */
+ get id() { throw Error('Factory must implement `id` property') },
+ /**
+ * XPCOM `contractID` may optionally be provided to associate this factory
+ * with it. `contract` is a unique string that has a following format:
+ * '@vendor.com/unique/id;1'.
+ */
+ contract: null,
+ /**
+ * Class description that is being registered. This value is intended as a
+ * human-readable description for the given class and does not needs to be
+ * globally unique.
+ */
+ description: 'Jetpack generated factory',
+ /**
+ * This method is required by `nsIFactory` interfaces, but as in most
+ * implementations it does nothing interesting.
+ */
+ lockFactory: function lockFactory(lock) undefined,
+ /**
+ * If property is `true` XPCOM service / factory will be registered
+ * automatically on creation.
+ */
+ register: true,
+ /**
+ * If property is `true` XPCOM factory will be unregistered prior to add-on
+ * unload.
+ */
+ unregister: true,
+ /**
+ * Method is called on `Service.new(options)` passing given `options` to
+ * it. Options is expected to have `component` property holding XPCOM
+ * component implementation typically decedent of `Unknown` or any custom
+ * implementation with a `new` method and optional `register`, `unregister`
+ * flags. Unless `register` is `false` Service / Factory will be
+ * automatically registered. Unless `unregister` is `false` component will
+ * be automatically unregistered on add-on unload.
+ */
+ initialize: function initialize(options) {
+ options = options || {}
+ this.merge(options, { id: 'id' in options && options.id || uuid() });
+
+ // If service / factory has auto registration enabled then register.
+ if (this.register)
+ register(this);
+ },
+ /**
+ * Creates an instance of the class associated with this factory.
+ */
+ createInstance: function createInstance(outer, iid) {
+ try {
+ if (outer)
+ throw Cr.NS_ERROR_NO_AGGREGATION;
+ return this.create().QueryInterface(iid);
+ }
+ catch (error) {
+ throw error instanceof Ci.nsIException ? error : Cr.NS_ERROR_FAILURE;
+ }
+ },
+ create: function create() this.component.new()
+});
+exports.Factory = Factory;
+
+// Exemplar for creating services that implement `nsIFactory` interface, that
+// can be registered into runtime via call to `register`. This services return
+// enclosed `component` on `getService`.
+const Service = Factory.extend({
+ description: 'Jetpack generated service',
+ /**
+ * Creates an instance of the class associated with this factory.
+ */
+ create: function create() this.component
+});
+exports.Service = Service;
+
+function isRegistered({ id }) isCIDRegistered(id)
+exports.isRegistered = isRegistered;
+
+/**
+ * Registers given `component` object to be used to instantiate a particular
+ * class identified by `component.id`, and creates an association of class
+ * name and `component.contract` with the class.
+ */
+function register(factory) {
+ registerFactory(factory.id, factory.description, factory.contract, factory);
+
+ if (factory.unregister)
+ unload(unregister.bind(null, factory));
+}
+exports.register = register;
+
+/**
+ * Unregister a factory associated with a particular class identified by
+ * `factory.classID`.
+ */
+function unregister(factory) {
+ if (isRegistered(factory))
+ unregisterFactory(factory.id, factory);
+}
+exports.unregister = unregister;
+
+function autoRegister(path) {
+ // TODO: This assumes that the url points to a directory
+ // that contains subdirectories corresponding to OS/ABI and then
+ // further subdirectories corresponding to Gecko platform version.
+ // we should probably either behave intelligently here or allow
+ // the caller to pass-in more options if e.g. there aren't
+ // Gecko-specific binaries for a component (which will be the case
+ // if only frozen interfaces are used).
+
+ var runtime = require("./runtime");
+ var osDirName = runtime.OS + "_" + runtime.XPCOMABI;
+ var platformVersion = require("./xul-app").platformVersion.substring(0, 5);
+
+ var file = Cc['@mozilla.org/file/local;1']
+ .createInstance(Ci.nsILocalFile);
+ file.initWithPath(path);
+ file.append(osDirName);
+ file.append(platformVersion);
+
+ if (!(file.exists() && file.isDirectory()))
+ throw new Error("component not available for OS/ABI " +
+ osDirName + " and platform " + platformVersion);
+
+ Cm.QueryInterface(Ci.nsIComponentRegistrar);
+ Cm.autoRegister(file);
+}
+exports.autoRegister = autoRegister;
+
+/**
+ * Returns registered factory that has a given `id` or `null` if not found.
+ */
+function factoryByID(id) classesByID[id] || null
+exports.factoryByID = factoryByID;
+
+/**
+ * Returns factory registered with a given `contract` or `null` if not found.
+ * In contrast to `Cc[contract]` that does ignores new factory registration
+ * with a given `contract` this will return a factory currently associated
+ * with a `contract`.
+ */
+function factoryByContract(contract) factoryByID(Cm.contractIDToCID(contract))
+exports.factoryByContract = factoryByContract;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/lib/xul-app.js b/tools/addon-sdk-1.7/packages/api-utils/lib/xul-app.js
new file mode 100644
index 0000000..9272d88
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/lib/xul-app.js
@@ -0,0 +1,63 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {Cc, Ci} = require("chrome");
+
+var appInfo = Cc["@mozilla.org/xre/app-info;1"]
+ .getService(Ci.nsIXULAppInfo);
+
+var ID = exports.ID = appInfo.ID;
+var name = exports.name = appInfo.name;
+var version = exports.version = appInfo.version;
+var platformVersion = exports.platformVersion = appInfo.platformVersion;
+
+// The following mapping of application names to GUIDs was taken from:
+//
+// https://addons.mozilla.org/en-US/firefox/pages/appversions
+//
+// Using the GUID instead of the app's name is preferable because sometimes
+// re-branded versions of a product have different names: for instance,
+// Firefox, Minefield, Iceweasel, and Shiretoko all have the same
+// GUID.
+// This mapping is duplicated in `app-extensions/bootstrap.js`. They should keep
+// in sync, so if you change one, change the other too!
+
+var ids = exports.ids = {
+ Firefox: "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}",
+ Mozilla: "{86c18b42-e466-45a9-ae7a-9b95ba6f5640}",
+ Sunbird: "{718e30fb-e89b-41dd-9da7-e25a45638b28}",
+ SeaMonkey: "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}",
+ Fennec: "{aa3c5121-dab2-40e2-81ca-7ea25febc110}",
+ Thunderbird: "{3550f703-e582-4d05-9a08-453d09bdfdc6}"
+};
+
+var is = exports.is = function is(name) {
+ if (!(name in ids))
+ throw new Error("Unkown Mozilla Application: " + name);
+ return ID == ids[name];
+};
+
+var isOneOf = exports.isOneOf = function isOneOf(names) {
+ for (var i = 0; i < names.length; i++)
+ if (is(names[i]))
+ return true;
+ return false;
+};
+
+/**
+ * Use this to check whether the given version (e.g. xulApp.platformVersion)
+ * is in the given range. Versions must be in version comparator-compatible
+ * format. See MDC for details:
+ * https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIVersionComparator
+ */
+var versionInRange = exports.versionInRange =
+function versionInRange(version, lowInclusive, highExclusive) {
+ var vc = Cc["@mozilla.org/xpcom/version-comparator;1"]
+ .getService(Ci.nsIVersionComparator);
+ return (vc.compare(version, lowInclusive) >= 0) &&
+ (vc.compare(version, highExclusive) < 0);
+}
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/package.json b/tools/addon-sdk-1.7/packages/api-utils/package.json
new file mode 100644
index 0000000..1e777fe
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/package.json
@@ -0,0 +1,14 @@
+{
+ "name": "api-utils",
+ "description": "Foundational infrastructure and utilities.",
+ "keywords": ["javascript", "engine", "platform", "xulrunner",
+ "jetpack-low-level"],
+ "author": "Atul Varma (http://toolness.com/) <atul@mozilla.com>",
+ "contributors": [
+ "Myk Melez (http://melez.com/) <myk@mozilla.org>",
+ "Daniel Aquino <mr.danielaquino@gmail.com>"
+ ],
+ "license": "MPL 2.0",
+ "dependencies": ["addon-kit"],
+ "loader": "lib/cuddlefish.js"
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/commonjs-test-adapter/asserts.js b/tools/addon-sdk-1.7/packages/api-utils/tests/commonjs-test-adapter/asserts.js
new file mode 100644
index 0000000..8618ace
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/commonjs-test-adapter/asserts.js
@@ -0,0 +1,54 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const AssertBase = require("test/assert").Assert;
+
+/**
+ * Generates custom assertion constructors that may be bundled with a test
+ * suite.
+ * @params {String}
+ * names of assertion function to be added to the generated Assert.
+ */
+function Assert() {
+ let assertDescriptor = {};
+ Array.forEach(arguments, function(name) {
+ assertDescriptor[name] = { value: function(message) {
+ this.pass(message);
+ }}
+ });
+
+ return function Assert() {
+ return Object.create(AssertBase.apply(null, arguments), assertDescriptor);
+ };
+}
+
+exports["test suite"] = {
+ Assert: Assert("foo"),
+ "test that custom assertor is passed to test function": function(assert) {
+ assert.ok("foo" in assert, "custom assertion function `foo` is defined");
+ assert.foo("custom assertion function `foo` is called");
+ },
+ "test sub suite": {
+ "test that `Assert` is inherited by sub suits": function(assert) {
+ assert.ok("foo" in assert, "assertion function `foo` is not defined");
+ },
+ "test sub sub suite": {
+ Assert: Assert("bar"),
+ "test that custom assertor is passed to test function": function(assert) {
+ assert.ok("bar" in assert,
+ "custom assertion function `bar` is defined");
+ assert.bar("custom assertion function `bar` is called");
+ },
+ "test that `Assert` is not inherited by sub sub suits": function(assert) {
+ assert.ok(!("foo" in assert),
+ "assertion function `foo` is not defined");
+ }
+ }
+ }
+};
+
+if (module == require.main)
+ require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/fixtures/es5.js b/tools/addon-sdk-1.7/packages/api-utils/tests/fixtures/es5.js
new file mode 100644
index 0000000..746cae3
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/fixtures/es5.js
@@ -0,0 +1,8 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+exports.frozen = Object.freeze({});
+exports.sealed = Object.seal({});
+exports.inextensible = Object.preventExtensions({});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/fixtures/sandbox-complex-character.js b/tools/addon-sdk-1.7/packages/api-utils/tests/fixtures/sandbox-complex-character.js
new file mode 100644
index 0000000..6ae6769
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/fixtures/sandbox-complex-character.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var chars = 'გამარჯობა';
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/fixtures/sandbox-normal.js b/tools/addon-sdk-1.7/packages/api-utils/tests/fixtures/sandbox-normal.js
new file mode 100644
index 0000000..5425298
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/fixtures/sandbox-normal.js
@@ -0,0 +1,7 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var a = 1;
+this.b = 2;
+function f() { return 4; }
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/helpers.js b/tools/addon-sdk-1.7/packages/api-utils/tests/helpers.js
new file mode 100644
index 0000000..c639849
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/helpers.js
@@ -0,0 +1,24 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Loader } = require("@loader");
+
+exports.Loader = function(module, globals, packaging) {
+ var options = packaging || JSON.parse(JSON.stringify(require("@packaging")));
+ options.globals = globals;
+
+ let loader = Loader.new(options);
+ return Object.create(loader, {
+ require: { value: Loader.require.bind(loader, module.path) },
+ sandbox: { value: function sandbox(id) {
+ let path = options.manifest[module.path].requirements[id].path;
+ return loader.sandboxes[path].sandbox;
+ }},
+ unload: { value: function unload(reason, callback) {
+ loader.unload(reason, callback);
+ }}
+ })
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/loader/fixture.js b/tools/addon-sdk-1.7/packages/api-utils/tests/loader/fixture.js
new file mode 100644
index 0000000..c2dc0f1
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/loader/fixture.js
@@ -0,0 +1,6 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.foo = foo;
+console.log('testing', 1, [2, 3, 4]);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/add.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/add.js
new file mode 100644
index 0000000..5472934
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/add.js
@@ -0,0 +1,9 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+define('modules/add', function () {
+ return function (a, b) {
+ return a + b;
+ };
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/async1.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/async1.js
new file mode 100644
index 0000000..b7b60fd
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/async1.js
@@ -0,0 +1,14 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+define(['./traditional2', './async2'], function () {
+ var traditional2 = require('./traditional2');
+ return {
+ name: 'async1',
+ traditional1Name: traditional2.traditional1Name,
+ traditional2Name: traditional2.name,
+ async2Name: require('./async2').name,
+ async2Traditional2Name: require('./async2').traditional2Name
+ };
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/async2.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/async2.js
new file mode 100644
index 0000000..802fb25
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/async2.js
@@ -0,0 +1,8 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+define(['./traditional2', 'exports'], function (traditional2, exports) {
+ exports.name = 'async2';
+ exports.traditional2Name = traditional2.name;
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/badExportAndReturn.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/badExportAndReturn.js
new file mode 100644
index 0000000..35a5359
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/badExportAndReturn.js
@@ -0,0 +1,10 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// This is a bad module, it asks for exports but also returns a value from
+// the define defintion function.
+define(['exports'], function (exports) {
+ return 'badExportAndReturn';
+});
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/badFirst.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/badFirst.js
new file mode 100644
index 0000000..fdb03bd
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/badFirst.js
@@ -0,0 +1,9 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+define(['./badSecond'], function (badSecond) {
+ return {
+ name: 'badFirst'
+ };
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/badSecond.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/badSecond.js
new file mode 100644
index 0000000..8321a85
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/badSecond.js
@@ -0,0 +1,8 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var first = require('./badFirst');
+
+exports.name = 'badSecond';
+exports.badFirstName = first.name;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/blue.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/blue.js
new file mode 100644
index 0000000..14ab149
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/blue.js
@@ -0,0 +1,9 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+define(function () {
+ return {
+ name: 'blue'
+ };
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/castor.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/castor.js
new file mode 100644
index 0000000..9209623
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/castor.js
@@ -0,0 +1,10 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+define(['exports', './pollux'], function(exports, pollux) {
+ exports.name = 'castor';
+ exports.getPolluxName = function () {
+ return pollux.name;
+ };
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/cheetah.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/cheetah.js
new file mode 100644
index 0000000..37d12bf
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/cheetah.js
@@ -0,0 +1,9 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+define(function () {
+ return function () {
+ return 'cheetah';
+ };
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/color.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/color.js
new file mode 100644
index 0000000..0d946bd
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/color.js
@@ -0,0 +1,7 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+define({
+ type: 'color'
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/dupe.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/dupe.js
new file mode 100644
index 0000000..f87fa55
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/dupe.js
@@ -0,0 +1,15 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+define({
+ name: 'dupe'
+});
+
+// This is wrong and should not be allowed. Only one call to
+// define per file.
+define([], function () {
+ return {
+ name: 'dupe2'
+ };
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/dupeNested.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/dupeNested.js
new file mode 100644
index 0000000..703948c
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/dupeNested.js
@@ -0,0 +1,15 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+define(function () {
+ // This is wrong and should not be allowed.
+ define('dupeNested2', {
+ name: 'dupeNested2'
+ });
+
+ return {
+ name: 'dupeNested'
+ };
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/dupeSetExports.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/dupeSetExports.js
new file mode 100644
index 0000000..12a1be2
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/dupeSetExports.js
@@ -0,0 +1,8 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+define({name: "dupeSetExports"});
+
+// so this should cause a failure
+module.setExports("no no no");
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/exportsEquals.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/exportsEquals.js
new file mode 100644
index 0000000..e176316
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/exportsEquals.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+module.exports = 4;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/green.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/green.js
new file mode 100644
index 0000000..ce2d134
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/green.js
@@ -0,0 +1,10 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+define('modules/green', ['./color'], function (color) {
+ return {
+ name: 'green',
+ parentType: color.type
+ };
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/lion.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/lion.js
new file mode 100644
index 0000000..9c3ac3b
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/lion.js
@@ -0,0 +1,7 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+define(function(require) {
+ return 'lion';
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/orange.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/orange.js
new file mode 100644
index 0000000..900a32b
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/orange.js
@@ -0,0 +1,10 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+define(['./color'], function (color) {
+ return {
+ name: 'orange',
+ parentType: color.type
+ };
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/pollux.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/pollux.js
new file mode 100644
index 0000000..61cf66f
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/pollux.js
@@ -0,0 +1,10 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+define(['exports', './castor'], function(exports, castor) {
+ exports.name = 'pollux';
+ exports.getCastorName = function () {
+ return castor.name;
+ };
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/red.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/red.js
new file mode 100644
index 0000000..c47b8e9
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/red.js
@@ -0,0 +1,16 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+define(function (require) {
+ // comment fake-outs for require finding.
+ // require('bad1');
+ return {
+ name: 'red',
+ parentType: require('./color').type
+ };
+
+ /*
+ require('bad2');
+ */
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/setExports.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/setExports.js
new file mode 100644
index 0000000..495c301
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/setExports.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+module.setExports(5);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/subtract.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/subtract.js
new file mode 100644
index 0000000..06e1053
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/subtract.js
@@ -0,0 +1,9 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+define(function () {
+ return function (a, b) {
+ return a - b;
+ }
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/tiger.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/tiger.js
new file mode 100644
index 0000000..e332deb
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/tiger.js
@@ -0,0 +1,8 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+define(function (require, exports) {
+ exports.name = 'tiger';
+ exports.type = require('modules/types/cat').type;
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/traditional1.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/traditional1.js
new file mode 100644
index 0000000..28af8ef
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/traditional1.js
@@ -0,0 +1,12 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.name = 'traditional1'
+
+var async1 = require('./async1');
+
+exports.traditional2Name = async1.traditional2Name;
+exports.traditional1Name = async1.traditional1Name;
+exports.async2Name = async1.async2Name;
+exports.async2Traditional2Name = async1.async2Traditional2Name;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/traditional2.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/traditional2.js
new file mode 100644
index 0000000..67b64ee
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/traditional2.js
@@ -0,0 +1,6 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.name = 'traditional2';
+exports.traditional1Name = require('./traditional1').name;
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/modules/types/cat.js b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/types/cat.js
new file mode 100644
index 0000000..41513d6
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/modules/types/cat.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.type = 'cat';
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-api-utils.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-api-utils.js
new file mode 100644
index 0000000..15f1f3e
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-api-utils.js
@@ -0,0 +1,241 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const apiUtils = require("api-utils/api-utils");
+
+exports.testPublicConstructor = function (test) {
+ function PrivateCtor() {}
+ PrivateCtor.prototype = {};
+
+ let PublicCtor = apiUtils.publicConstructor(PrivateCtor);
+ test.assert(
+ PrivateCtor.prototype.isPrototypeOf(PublicCtor.prototype),
+ "PrivateCtor.prototype should be prototype of PublicCtor.prototype"
+ );
+
+ function testObj(useNew) {
+ let obj = useNew ? new PublicCtor() : PublicCtor();
+ test.assert(obj instanceof PublicCtor,
+ "Object should be instance of PublicCtor");
+ test.assert(obj instanceof PrivateCtor,
+ "Object should be instance of PrivateCtor");
+ test.assert(PublicCtor.prototype.isPrototypeOf(obj),
+ "PublicCtor's prototype should be prototype of object");
+ test.assertEqual(obj.constructor, PublicCtor,
+ "Object constructor should be PublicCtor");
+ }
+ testObj(true);
+ testObj(false);
+};
+
+exports.testValidateOptionsEmpty = function (test) {
+ let val = apiUtils.validateOptions(null, {});
+ assertObjsEqual(test, val, {});
+
+ val = apiUtils.validateOptions(null, { foo: {} });
+ assertObjsEqual(test, val, {});
+
+ val = apiUtils.validateOptions({}, {});
+ assertObjsEqual(test, val, {});
+
+ val = apiUtils.validateOptions({}, { foo: {} });
+ assertObjsEqual(test, val, {});
+};
+
+exports.testValidateOptionsNonempty = function (test) {
+ let val = apiUtils.validateOptions({ foo: 123 }, {});
+ assertObjsEqual(test, val, {});
+
+ val = apiUtils.validateOptions({ foo: 123, bar: 456 },
+ { foo: {}, bar: {}, baz: {} });
+ assertObjsEqual(test, val, { foo: 123, bar: 456 });
+};
+
+exports.testValidateOptionsMap = function (test) {
+ let val = apiUtils.validateOptions({ foo: 3, bar: 2 }, {
+ foo: { map: function (v) v * v },
+ bar: { map: function (v) undefined }
+ });
+ assertObjsEqual(test, val, { foo: 9, bar: undefined });
+};
+
+exports.testValidateOptionsMapException = function (test) {
+ let val = apiUtils.validateOptions({ foo: 3 }, {
+ foo: { map: function () { throw new Error(); }}
+ });
+ assertObjsEqual(test, val, { foo: 3 });
+};
+
+exports.testValidateOptionsOk = function (test) {
+ let val = apiUtils.validateOptions({ foo: 3, bar: 2, baz: 1 }, {
+ foo: { ok: function (v) v },
+ bar: { ok: function (v) v }
+ });
+ assertObjsEqual(test, val, { foo: 3, bar: 2 });
+
+ test.assertRaises(
+ function () apiUtils.validateOptions({ foo: 2, bar: 2 }, {
+ bar: { ok: function (v) v > 2 }
+ }),
+ 'The option "bar" is invalid.',
+ "ok should raise exception on invalid option"
+ );
+
+ test.assertRaises(
+ function () apiUtils.validateOptions(null, { foo: { ok: function (v) v }}),
+ 'The option "foo" is invalid.',
+ "ok should raise exception on invalid option"
+ );
+};
+
+exports.testValidateOptionsIs = function (test) {
+ let opts = {
+ array: [],
+ boolean: true,
+ func: function () {},
+ nul: null,
+ number: 1337,
+ object: {},
+ string: "foo",
+ undef1: undefined
+ };
+ let requirements = {
+ array: { is: ["array"] },
+ boolean: { is: ["boolean"] },
+ func: { is: ["function"] },
+ nul: { is: ["null"] },
+ number: { is: ["number"] },
+ object: { is: ["object"] },
+ string: { is: ["string"] },
+ undef1: { is: ["undefined"] },
+ undef2: { is: ["undefined"] }
+ };
+ let val = apiUtils.validateOptions(opts, requirements);
+ assertObjsEqual(test, val, opts);
+
+ test.assertRaises(
+ function () apiUtils.validateOptions(null, {
+ foo: { is: ["object", "number"] }
+ }),
+ 'The option "foo" must be one of the following types: object, number',
+ "Invalid type should raise exception"
+ );
+};
+
+exports.testValidateOptionsMapIsOk = function (test) {
+ let [map, is, ok] = [false, false, false];
+ let val = apiUtils.validateOptions({ foo: 1337 }, {
+ foo: {
+ map: function (v) v.toString(),
+ is: ["string"],
+ ok: function (v) v.length > 0
+ }
+ });
+ assertObjsEqual(test, val, { foo: "1337" });
+
+ let requirements = {
+ foo: {
+ is: ["object"],
+ ok: function () test.fail("is should have caused us to throw by now")
+ }
+ };
+ test.assertRaises(
+ function () apiUtils.validateOptions(null, requirements),
+ 'The option "foo" must be one of the following types: object',
+ "is should be used before ok is called"
+ );
+};
+
+exports.testValidateOptionsErrorMsg = function (test) {
+ test.assertRaises(
+ function () apiUtils.validateOptions(null, {
+ foo: { ok: function (v) v, msg: "foo!" }
+ }),
+ "foo!",
+ "ok should raise exception with customized message"
+ );
+};
+
+exports.testValidateMapWithMissingKey = function (test) {
+ let val = apiUtils.validateOptions({ }, {
+ foo: {
+ map: function (v) v || "bar"
+ }
+ });
+ assertObjsEqual(test, val, { foo: "bar" });
+
+ val = apiUtils.validateOptions({ }, {
+ foo: {
+ map: function (v) { throw "bar" }
+ }
+ });
+ assertObjsEqual(test, val, { });
+};
+
+exports.testAddIterator = function testAddIterator(test) {
+ let obj = {};
+ let keys = ["foo", "bar", "baz"];
+ let vals = [1, 2, 3];
+ let keysVals = [["foo", 1], ["bar", 2], ["baz", 3]];
+ apiUtils.addIterator(
+ obj,
+ function keysValsGen() {
+ for each (let keyVal in keysVals)
+ yield keyVal;
+ }
+ );
+
+ let keysItr = [];
+ for (let key in obj)
+ keysItr.push(key);
+ test.assertEqual(keysItr.length, keys.length,
+ "the keys iterator returns the correct number of items");
+ for (let i = 0; i < keys.length; i++)
+ test.assertEqual(keysItr[i], keys[i], "the key is correct");
+
+ let valsItr = [];
+ for each (let val in obj)
+ valsItr.push(val);
+ test.assertEqual(valsItr.length, vals.length,
+ "the vals iterator returns the correct number of items");
+ for (let i = 0; i < vals.length; i++)
+ test.assertEqual(valsItr[i], vals[i], "the val is correct");
+
+ let keysValsItr = [];
+ for (let keyVal in Iterator(obj))
+ keysValsItr.push(keyVal);
+ test.assertEqual(keysValsItr.length, keysVals.length, "the keys/vals " +
+ "iterator returns the correct number of items");
+ for (let i = 0; i < keysVals.length; i++) {
+ test.assertEqual(keysValsItr[i][0], keysVals[i][0], "the key is correct");
+ test.assertEqual(keysValsItr[i][1], keysVals[i][1], "the val is correct");
+ }
+
+ let keysOnlyItr = [];
+ for (let key in Iterator(obj, true /* keysonly */))
+ keysOnlyItr.push(key);
+ test.assertEqual(keysOnlyItr.length, keysVals.length, "the keys only " +
+ "iterator returns the correct number of items");
+ for (let i = 0; i < keysVals.length; i++)
+ test.assertEqual(keysOnlyItr[i], keysVals[i][0], "the key is correct");
+};
+
+function assertObjsEqual(test, obj1, obj2) {
+ var items = 0;
+ for (let [key, val] in Iterator(obj1)) {
+ items++;
+ test.assert(key in obj2, "obj1 key should be present in obj2");
+ test.assertEqual(obj2[key], val, "obj1 value should match obj2 value");
+ }
+ for (let [key, val] in Iterator(obj2)) {
+ items++;
+ test.assert(key in obj1, "obj2 key should be present in obj1");
+ test.assertEqual(obj1[key], val, "obj2 value should match obj1 value");
+ }
+ if (!items)
+ test.assertEqual(JSON.stringify(obj1), JSON.stringify(obj2),
+ "obj1 should have same JSON representation as obj2");
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-app-strings.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-app-strings.js
new file mode 100644
index 0000000..902c31f
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-app-strings.js
@@ -0,0 +1,62 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const { Cc,Ci } = require("chrome");
+
+let StringBundle = require("app-strings").StringBundle;
+exports.testStringBundle = function(test) {
+ let url = "chrome://global/locale/security/caps.properties";
+
+ let strings = StringBundle(url);
+
+ test.assertEqual(strings.url, url,
+ "'url' property contains correct URL of string bundle");
+
+ let appLocale = Cc["@mozilla.org/intl/nslocaleservice;1"].
+ getService(Ci.nsILocaleService).
+ getApplicationLocale();
+
+ let stringBundle = Cc["@mozilla.org/intl/stringbundle;1"].
+ getService(Ci.nsIStringBundleService).
+ createBundle(url, appLocale);
+
+ let (name = "Yes") {
+ test.assertEqual(strings.get(name), stringBundle.GetStringFromName(name),
+ "getting a string returns the string");
+ }
+
+ let (name = "ExtensionCapability", args = ["foo"]) {
+ test.assertEqual(strings.get(name, args),
+ stringBundle.formatStringFromName(name, args, args.length),
+ "getting a formatted string returns the formatted string");
+ }
+
+ test.assertRaises(function () strings.get("nonexistentString"),
+ "String 'nonexistentString' could not be retrieved from " +
+ "the bundle due to an unknown error (it doesn't exist?).",
+ "retrieving a nonexistent string throws an exception");
+
+ let a = [], b = [];
+ let enumerator = stringBundle.getSimpleEnumeration();
+ while (enumerator.hasMoreElements()) {
+ let elem = enumerator.getNext().QueryInterface(Ci.nsIPropertyElement);
+ a.push([elem.key, elem.value]);
+ }
+ for (let keyVal in Iterator(strings))
+ b.push(keyVal);
+
+ // Sort the arrays, because we don't assume enumeration has a set order.
+ // Sort compares [key, val] as string "key,val", which sorts the way we want
+ // it to, so there is no need to provide a custom compare function.
+ a.sort();
+ b.sort();
+
+ test.assertEqual(a.length, b.length,
+ "the iterator returns the correct number of items");
+ for (let i = 0; i < a.length; i++) {
+ test.assertEqual(a[i][0], b[i][0], "the iterated string's name is correct");
+ test.assertEqual(a[i][1], b[i][1],
+ "the iterated string's value is correct");
+ }
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-array.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-array.js
new file mode 100644
index 0000000..878a6ce
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-array.js
@@ -0,0 +1,40 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var array = require("array");
+
+exports.testHas = function(test) {
+ var testAry = [1, 2, 3];
+ test.assertEqual(array.has([1, 2, 3], 1), true);
+ test.assertEqual(testAry.length, 3);
+ test.assertEqual(testAry[0], 1);
+ test.assertEqual(testAry[1], 2);
+ test.assertEqual(testAry[2], 3);
+ test.assertEqual(array.has(testAry, 2), true);
+ test.assertEqual(array.has(testAry, 3), true);
+ test.assertEqual(array.has(testAry, 4), false);
+ test.assertEqual(array.has(testAry, "1"), false);
+};
+
+exports.testAdd = function(test) {
+ var testAry = [1];
+ test.assertEqual(array.add(testAry, 1), false);
+ test.assertEqual(testAry.length, 1);
+ test.assertEqual(testAry[0], 1);
+ test.assertEqual(array.add(testAry, 2), true);
+ test.assertEqual(testAry.length, 2);
+ test.assertEqual(testAry[0], 1);
+ test.assertEqual(testAry[1], 2);
+};
+
+exports.testRemove = function(test) {
+ var testAry = [1, 2];
+ test.assertEqual(array.remove(testAry, 3), false);
+ test.assertEqual(testAry.length, 2);
+ test.assertEqual(testAry[0], 1);
+ test.assertEqual(testAry[1], 2);
+ test.assertEqual(array.remove(testAry, 2), true);
+ test.assertEqual(testAry.length, 1);
+ test.assertEqual(testAry[0], 1);
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-base.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-base.js
new file mode 100644
index 0000000..e97b8b0
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-base.js
@@ -0,0 +1,240 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+var { Base, Class } = require("api-utils/base");
+
+exports["test .isPrototypeOf"] = function(assert) {
+ assert.ok(Base.isPrototypeOf(Base.new()),
+ "Base is a prototype of Base.new()");
+ assert.ok(Base.isPrototypeOf(Base.extend()),
+ "Base is a prototype of Base.extned()");
+ assert.ok(Base.isPrototypeOf(Base.extend().new()),
+ "Base is a prototoype of Base.extend().new()");
+ assert.ok(!Base.extend().isPrototypeOf(Base.extend()),
+ "Base.extend() in not prototype of Base.extend()");
+ assert.ok(!Base.extend().isPrototypeOf(Base.new()),
+ "Base.extend() is not prototype of Base.new()");
+ assert.ok(!Base.new().isPrototypeOf(Base.extend()),
+ "Base.new() is not prototype of Base.extend()");
+ assert.ok(!Base.new().isPrototypeOf(Base.new()),
+ "Base.new() is not prototype of Base.new()");
+};
+
+exports["test inheritance"] = function(assert) {
+ var Parent = Base.extend({
+ name: "parent",
+ method: function () {
+ return "hello " + this.name;
+ }
+ });
+
+ assert.equal(Parent.name, "parent", "Parent name is parent");
+ assert.equal(Parent.method(), "hello parent", "method works on prototype");
+ assert.equal(Parent.new().name, Parent.name, "Parent instance inherits name");
+ assert.equal(Parent.new().method(), Parent.method(),
+ "method behaves same on the prototype");
+ assert.equal(Parent.extend({}).name, Parent.name,
+ "Parent decedent inherits name");
+
+ var Child = Parent.extend({ name: "child" });
+ assert.notEqual(Child.name, Parent.name, "Child overides name");
+ assert.equal(Child.new().name, Child.name, "Child intsances inherit name");
+ assert.equal(Child.extend().name, Child.name,
+ "Child decedents inherit name");
+
+ assert.equal(Child.method, Parent.method, "Child inherits method");
+ assert.equal(Child.extend().method, Parent.method,
+ "Child decedent inherit method");
+ assert.equal(Child.new().method, Parent.method,
+ "Child instances inherit method");
+
+ assert.equal(Child.method(), "hello child",
+ "method refers to instance proprety");
+ assert.equal(Child.extend({ name: "decedent" }).new().method(),
+ "hello decedent", "method may be overrided");
+};
+
+exports["test prototype immutability"] = function(assert) {
+
+ assert.throws(function() {
+ var override = function() {};
+ Base.extend = override;
+ if (Base.extend !== override)
+ throw Error("Property was not set");
+ }, "Base prototype is imutable");
+
+ assert.throws(function() {
+ Base.foo = "bar";
+ if (Base.foo !== "bar")
+ throw Error("Property was not set");
+ }, "Base prototype is non-configurabel");
+
+ assert.throws(function() {
+ delete Base.new;
+ if ('new' in Base)
+ throw Error('Property was not deleted');
+ }, "Can't delete properties on prototype");
+
+ var Foo = Base.extend({
+ name: 'hello',
+ rename: function rename(name) {
+ this.name = name;
+ }
+ });
+
+ assert.throws(function() {
+ var override = function() {};
+ Foo.extend = override;
+ if (Foo.extend !== override)
+ throw Error("Property was not set");
+ }, "Can't change prototype properties");
+
+ assert.throws(function() {
+ Foo.foo = "bar";
+ if (Foo.foo !== "bar")
+ throw Error("Property was not set");
+ }, "Can't add prototype properties");
+
+ assert.throws(function() {
+ delete Foo.name;
+ if ('new' in Foo)
+ throw Error('Property was not deleted');
+ }, "Can't remove prototype properties");
+
+ assert.throws(function() {
+ Foo.rename("new name");
+ if (Foo.name !== "new name")
+ throw Error("Property was not modified");
+ }, "Method's can't mutate prototypes");
+
+ var Bar = Foo.extend({
+ rename: function rename() {
+ return this.name;
+ }
+ });
+
+ assert.equal(Bar.rename(), Foo.name,
+ "properties may be overided on decedents");
+};
+
+exports['test instance mutability'] = function(assert) {
+ var Foo = Base.extend({
+ name: "foo",
+ init: function init(number) {
+ this.number = number;
+ }
+ });
+ var f1 = Foo.new();
+ /* V8 does not supports this yet!
+ assert.throws(function() {
+ f1.name = "f1";
+ }, "can't change prototype properties");
+ */
+ f1.alias = "f1";
+ assert.equal(f1.alias, "f1", "instance is mutable");
+ delete f1.alias;
+ assert.ok(!('alias' in f1), "own properties are deletable");
+ f1.init(1);
+ assert.equal(f1.number, 1, "method can mutate instance's own properties");
+};
+
+exports['test super'] = function(assert) {
+ var Foo = Base.extend({
+ initialize: function Foo(options) {
+ this.name = options.name;
+ }
+ });
+
+ var Bar = Foo.extend({
+ initialize: function Bar(options) {
+ Foo.initialize.call(this, options);
+ this.type = 'bar';
+ }
+ });
+
+ var bar = Bar.new({ name: 'test' });
+
+ assert.ok(Bar.isPrototypeOf(bar), 'Bar is prototype of Bar.new');
+ assert.ok(Foo.isPrototypeOf(bar), 'Foo is prototype of Bar.new');
+ assert.ok(Base.isPrototypeOf(bar), 'Base is prototype of Bar.new');
+ assert.equal(bar.type, 'bar', 'bar initializer was called');
+ assert.equal(bar.name, 'test', 'bar initializer called Foo initializer');
+};
+
+exports['test class'] = function(assert) {
+ var Foo = Base.extend({
+ type: 'Foo',
+ initialize: function(options) {
+ this.name = options.name;
+ },
+ serialize: function serialize() {
+ return '<' + this.name + ':' + this.type + '>';
+ }
+ });
+ var CFoo = Class(Foo);
+ var f1 = CFoo({ name: 'f1' });
+ var f2 = new CFoo({ name: 'f2' });
+ var f3 = CFoo.new({ name: 'f3' });
+ var f4 = Foo.new({ name: 'f4' });
+
+ assert.ok(f1 instanceof CFoo, 'correct instanceof');
+ assert.equal(f1.name, 'f1', 'property initialized');
+ assert.equal(f1.serialize(), '<f1:Foo>', 'method works');
+
+ assert.ok(f2 instanceof CFoo, 'correct instanceof when created with new')
+ assert.equal(f2.name, 'f2', 'property initialized');
+ assert.equal(f2.serialize(), '<f2:Foo>', 'method works');
+
+ assert.ok(f3 instanceof CFoo, 'correct instanceof when created with .new')
+ assert.equal(f3.name, 'f3', 'property initialized');
+ assert.equal(f3.serialize(), '<f3:Foo>', 'method works');
+
+ assert.ok(f4 instanceof CFoo, 'correct instanceof when created from prototype')
+ assert.equal(f4.name, 'f4', 'property initialized');
+ assert.equal(f4.serialize(), '<f4:Foo>', 'method works');
+
+ var Bar = Foo.extend({
+ type: 'Bar',
+ initialize: function(options) {
+ this.size = options.size;
+ Foo.initialize.call(this, options);
+ }
+ });
+ var CBar = Class(Bar);
+
+
+ var b1 = CBar({ name: 'b1', size: 1 });
+ var b2 = new CBar({ name: 'b2', size: 2 });
+ var b3 = CBar.new({ name: 'b3', size: 3 });
+ var b4 = Bar.new({ name: 'b4', size: 4 });
+
+ assert.ok(b1 instanceof CFoo, 'correct instanceof');
+ assert.ok(b1 instanceof CBar, 'correct instanceof');
+ assert.equal(b1.name, 'b1', 'property initialized');
+ assert.equal(b1.size, 1, 'property initialized');
+ assert.equal(b1.serialize(), '<b1:Bar>', 'method works');
+
+ assert.ok(b2 instanceof CFoo, 'correct instanceof when created with new');
+ assert.ok(b2 instanceof CBar, 'correct instanceof when created with new');
+ assert.equal(b2.name, 'b2', 'property initialized');
+ assert.equal(b2.size, 2, 'property initialized');
+ assert.equal(b2.serialize(), '<b2:Bar>', 'method works');
+
+ assert.ok(b3 instanceof CFoo, 'correct instanceof when created with .new');
+ assert.ok(b3 instanceof CBar, 'correct instanceof when created with .new');
+ assert.equal(b3.name, 'b3', 'property initialized');
+ assert.equal(b3.size, 3, 'property initialized');
+ assert.equal(b3.serialize(), '<b3:Bar>', 'method works');
+
+ assert.ok(b4 instanceof CFoo, 'correct instanceof when created from prototype');
+ assert.ok(b4 instanceof CBar, 'correct instanceof when created from prototype');
+ assert.equal(b4.name, 'b4', 'property initialized');
+ assert.equal(b4.size, 4, 'property initialized');
+ assert.equal(b4.serialize(), '<b4:Bar>', 'method works');
+};
+
+require("test").run(exports);
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-byte-streams.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-byte-streams.js
new file mode 100644
index 0000000..5bd1e42
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-byte-streams.js
@@ -0,0 +1,169 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim:set ts=2 sw=2 sts=2 et filetype=javascript
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const byteStreams = require("byte-streams");
+const file = require("file");
+const { pathFor } = require("api-utils/system");
+const { Loader } = require("./helpers");
+
+const STREAM_CLOSED_ERROR = "The stream is closed and cannot be used.";
+
+// This should match the constant of the same name in byte-streams.js.
+const BUFFER_BYTE_LEN = 0x8000;
+
+exports.testWriteRead = function (test) {
+ let fname = dataFileFilename();
+
+ // Write a small string less than the stream's buffer size...
+ let str = "exports.testWriteRead data!";
+ let stream = open(test, fname, true);
+ test.assert(!stream.closed, "stream.closed after open should be false");
+ stream.write(str);
+ stream.close();
+ test.assert(stream.closed, "Stream should be closed after stream.close");
+ test.assertRaises(function () stream.write("This shouldn't be written!"),
+ STREAM_CLOSED_ERROR,
+ "stream.write after close should raise error");
+
+ // ... and read it.
+ stream = open(test, fname);
+ test.assertEqual(stream.read(), str,
+ "stream.read should return string written");
+ test.assertEqual(stream.read(), "",
+ "stream.read at EOS should return empty string");
+ stream.close();
+ test.assert(stream.closed, "Stream should be closed after stream.close");
+ test.assertRaises(function () stream.read(),
+ STREAM_CLOSED_ERROR,
+ "stream.read after close should raise error");
+
+ file.remove(fname);
+};
+
+// Write a big string many times the size of the stream's buffer and read it.
+exports.testWriteReadBig = function (test) {
+ let str = "";
+ let bufLen = BUFFER_BYTE_LEN;
+ let fileSize = bufLen * 10;
+ for (let i = 0; i < fileSize; i++)
+ str += i % 10;
+ let fname = dataFileFilename();
+ let stream = open(test, fname, true);
+ stream.write(str);
+ stream.close();
+ stream = open(test, fname);
+ test.assertEqual(stream.read(), str,
+ "stream.read should return string written");
+ stream.close();
+ file.remove(fname);
+};
+
+// The same, but write and read in chunks.
+exports.testWriteReadChunks = function (test) {
+ let str = "";
+ let bufLen = BUFFER_BYTE_LEN;
+ let fileSize = bufLen * 10;
+ for (let i = 0; i < fileSize; i++)
+ str += i % 10;
+ let fname = dataFileFilename();
+ let stream = open(test, fname, true);
+ let i = 0;
+ while (i < str.length) {
+ // Use a chunk length that spans buffers.
+ let chunk = str.substr(i, bufLen + 1);
+ stream.write(chunk);
+ i += bufLen + 1;
+ }
+ stream.close();
+ stream = open(test, fname);
+ let readStr = "";
+ bufLen = BUFFER_BYTE_LEN;
+ let readLen = bufLen + 1;
+ do {
+ var frag = stream.read(readLen);
+ readStr += frag;
+ } while (frag);
+ stream.close();
+ test.assertEqual(readStr, str,
+ "stream.write and read in chunks should work as expected");
+ file.remove(fname);
+};
+
+exports.testReadLengths = function (test) {
+ let fname = dataFileFilename();
+ let str = "exports.testReadLengths data!";
+ let stream = open(test, fname, true);
+ stream.write(str);
+ stream.close();
+
+ stream = open(test, fname);
+ test.assertEqual(stream.read(str.length * 1000), str,
+ "stream.read with big byte length should return string " +
+ "written");
+ stream.close();
+
+ stream = open(test, fname);
+ test.assertEqual(stream.read(0), "",
+ "string.read with zero byte length should return empty " +
+ "string");
+ stream.close();
+
+ stream = open(test, fname);
+ test.assertEqual(stream.read(-1), "",
+ "string.read with negative byte length should return " +
+ "empty string");
+ stream.close();
+
+ file.remove(fname);
+};
+
+exports.testTruncate = function (test) {
+ let fname = dataFileFilename();
+ let str = "exports.testReadLengths data!";
+ let stream = open(test, fname, true);
+ stream.write(str);
+ stream.close();
+
+ stream = open(test, fname);
+ test.assertEqual(stream.read(), str,
+ "stream.read should return string written");
+ stream.close();
+
+ stream = open(test, fname, true);
+ stream.close();
+
+ stream = open(test, fname);
+ test.assertEqual(stream.read(), "",
+ "stream.read after truncate should be empty");
+ stream.close();
+
+ file.remove(fname);
+};
+
+exports.testUnload = function (test) {
+ let loader = Loader(module);
+ let file = loader.require("file");
+
+ let filename = dataFileFilename("temp-b");
+ let stream = file.open(filename, "wb");
+
+ loader.unload();
+ test.assert(stream.closed, "Stream should be closed after module unload");
+};
+
+// Returns the name of a file that should be used to test writing and reading.
+function dataFileFilename() {
+ return file.join(pathFor("ProfD"), "test-byte-streams-data");
+}
+
+// Opens and returns the given file and ensures it's of the correct class.
+function open(test, filename, forWriting) {
+ let stream = file.open(filename, forWriting ? "wb" : "b");
+ let klass = forWriting ? "ByteWriter" : "ByteReader";
+ test.assert(stream instanceof byteStreams[klass],
+ "Opened stream should be a " + klass);
+ return stream;
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-collection.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-collection.js
new file mode 100644
index 0000000..f3e5476
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-collection.js
@@ -0,0 +1,127 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const collection = require("collection");
+
+exports.testAddRemove = function (test) {
+ let coll = new collection.Collection();
+ compare(test, coll, []);
+ addRemove(test, coll, [], false);
+};
+
+exports.testAddRemoveBackingArray = function (test) {
+ let items = ["foo"];
+ let coll = new collection.Collection(items);
+ compare(test, coll, items);
+ addRemove(test, coll, items, true);
+
+ items = ["foo", "bar"];
+ coll = new collection.Collection(items);
+ compare(test, coll, items);
+ addRemove(test, coll, items, true);
+};
+
+exports.testProperty = function (test) {
+ let obj = makeObjWithCollProp();
+ compare(test, obj.coll, []);
+ addRemove(test, obj.coll, [], false);
+
+ // Test single-value set.
+ let items = ["foo"];
+ obj.coll = items[0];
+ compare(test, obj.coll, items);
+ addRemove(test, obj.coll, items, false);
+
+ // Test array set.
+ items = ["foo", "bar"];
+ obj.coll = items;
+ compare(test, obj.coll, items);
+ addRemove(test, obj.coll, items, false);
+};
+
+exports.testPropertyBackingArray = function (test) {
+ let items = ["foo"];
+ let obj = makeObjWithCollProp(items);
+ compare(test, obj.coll, items);
+ addRemove(test, obj.coll, items, true);
+
+ items = ["foo", "bar"];
+ obj = makeObjWithCollProp(items);
+ compare(test, obj.coll, items);
+ addRemove(test, obj.coll, items, true);
+};
+
+// Adds some values to coll and then removes them. initialItems is an array
+// containing coll's initial items. isBacking is true if initialItems is coll's
+// backing array; the point is that updates to coll should affect initialItems
+// if that's the case.
+function addRemove(test, coll, initialItems, isBacking) {
+ let items = isBacking ? initialItems : initialItems.slice(0);
+ let numInitialItems = items.length;
+
+ // Test add(val).
+ let numInsertions = 5;
+ for (let i = 0; i < numInsertions; i++) {
+ compare(test, coll, items);
+ coll.add(i);
+ if (!isBacking)
+ items.push(i);
+ }
+ compare(test, coll, items);
+
+ // Add the items we just added to make sure duplicates aren't added.
+ for (let i = 0; i < numInsertions; i++)
+ coll.add(i);
+ compare(test, coll, items);
+
+ // Test remove(val). Do a kind of shuffled remove. Remove item 1, then
+ // item 0, 3, 2, 5, 4, ...
+ for (let i = 0; i < numInsertions; i++) {
+ let val = i % 2 ? i - 1 :
+ i === numInsertions - 1 ? i : i + 1;
+ coll.remove(val);
+ if (!isBacking)
+ items.splice(items.indexOf(val), 1);
+ compare(test, coll, items);
+ }
+ test.assertEqual(coll.length, numInitialItems,
+ "All inserted items should be removed");
+
+ // Remove the items we just removed. coll should be unchanged.
+ for (let i = 0; i < numInsertions; i++)
+ coll.remove(i);
+ compare(test, coll, items);
+
+ // Test add and remove([val1, val2]).
+ let newItems = [0, 1];
+ coll.add(newItems);
+ compare(test, coll, isBacking ? items : items.concat(newItems));
+ coll.remove(newItems);
+ compare(test, coll, items);
+ test.assertEqual(coll.length, numInitialItems,
+ "All inserted items should be removed");
+}
+
+// Asserts that the items in coll are the items of array.
+function compare(test, coll, array) {
+ test.assertEqual(coll.length, array.length,
+ "Collection length should be correct");
+ let numItems = 0;
+ for (let item in coll) {
+ test.assertEqual(item, array[numItems], "Items should be equal");
+ numItems++;
+ }
+ test.assertEqual(numItems, array.length,
+ "Number of items in iteration should be correct");
+}
+
+// Returns a new object with a collection property named "coll". backingArray,
+// if defined, will create the collection with that backing array.
+function makeObjWithCollProp(backingArray) {
+ let obj = {};
+ collection.addCollectionProperty(obj, "coll", backingArray);
+ return obj;
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-commonjs-test-adapter.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-commonjs-test-adapter.js
new file mode 100644
index 0000000..936bea9
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-commonjs-test-adapter.js
@@ -0,0 +1,11 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+exports["test custom `Assert`'s"] = require("./commonjs-test-adapter/asserts");
+
+// Disabling this check since it is not yet supported by jetpack.
+// if (module == require.main)
+ require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-content-loader.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-content-loader.js
new file mode 100644
index 0000000..e19e316
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-content-loader.js
@@ -0,0 +1,226 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+const { Loader } = require('content/loader');
+const self = require("self");
+
+exports['test:contentURL'] = function(test) {
+ let loader = Loader(),
+ value, emitted = 0, changes = 0;
+
+ test.assertRaises(
+ function() loader.contentURL = undefined,
+ 'The `contentURL` option must be a valid URL.',
+ 'Must throw an exception if `contentURL` is not URL.'
+ );
+ test.assertRaises(
+ function() loader.contentURL = null,
+ 'The `contentURL` option must be a valid URL.',
+ 'Must throw an exception if `contentURL` is not URL.'
+ );
+ test.assertRaises(
+ function() loader.contentURL = 4,
+ 'The `contentURL` option must be a valid URL.',
+ 'Must throw an exception if `contentURL` is not URL.'
+ );
+ test.assertRaises(
+ function() loader.contentURL = { toString: function() 'Oops' },
+ 'The `contentURL` option must be a valid URL.',
+ 'Must throw an exception if `contentURL` is not URL.'
+ );
+
+ function listener(e) {
+ emitted ++;
+ test.assert(
+ 'contentURL' in e,
+ 'emitted event must contain "content" property'
+ );
+ test.assert(
+ value,
+ '' + e.contentURL,
+ 'content property of an event must match value'
+ );
+ }
+ loader.on('propertyChange', listener);
+
+ test.assertEqual(
+ null,
+ loader.contentURL,
+ 'default value is `null`'
+ );
+ loader.contentURL = value = 'data:text/html,<html><body>Hi</body><html>';
+ test.assertEqual(
+ value,
+ '' + loader.contentURL,
+ 'data uri is ok'
+ );
+ test.assertEqual(
+ ++changes,
+ emitted,
+ 'had to emit `propertyChange`'
+ );
+ loader.contentURL = value;
+ test.assertEqual(
+ changes,
+ emitted,
+ 'must not emit `propertyChange` if same value is set'
+ );
+
+ loader.contentURL = value = 'http://google.com/';
+ test.assertEqual(
+ value,
+ '' + loader.contentURL,
+ 'value must be set'
+ );
+ test.assertEqual(
+ ++ changes,
+ emitted,
+ 'had to emit `propertyChange`'
+ );
+ loader.contentURL = value;
+ test.assertEqual(
+ changes,
+ emitted,
+ 'must not emit `propertyChange` if same value is set'
+ );
+
+ loader.removeListener('propertyChange', listener);
+ loader.contentURL = value = 'about:blank';
+ test.assertEqual(
+ value,
+ '' + loader.contentURL,
+ 'contentURL must be an actual value'
+ );
+ test.assertEqual(
+ changes,
+ emitted,
+ 'listener had to be romeved'
+ );
+};
+
+exports['test:contentScriptWhen'] = function(test) {
+ let loader = Loader();
+ test.assertEqual(
+ 'end',
+ loader.contentScriptWhen,
+ '`contentScriptWhen` defaults to "end"'
+ );
+ loader.contentScriptWhen = "end";
+ test.assertEqual(
+ "end",
+ loader.contentScriptWhen
+ );
+ try {
+ loader.contentScriptWhen = 'boom';
+ test.fail('must throw when wrong value is set');
+ } catch(e) {
+ test.assertEqual(
+ 'The `contentScriptWhen` option must be either "start", "ready" or "end".',
+ e.message
+ );
+ }
+ loader.contentScriptWhen = null;
+ test.assertEqual(
+ 'end',
+ loader.contentScriptWhen,
+ '`contentScriptWhen` defaults to "end"'
+ );
+ loader.contentScriptWhen = "ready";
+ test.assertEqual(
+ "ready",
+ loader.contentScriptWhen
+ );
+ loader.contentScriptWhen = "start";
+ test.assertEqual(
+ 'start',
+ loader.contentScriptWhen
+ );
+};
+
+exports['test:contentScript'] = function(test) {
+ let loader = Loader(), value;
+ test.assertEqual(
+ null,
+ loader.contentScript,
+ '`contentScript` defaults to `null`'
+ );
+ loader.contentScript = value = 'let test = {};';
+ test.assertEqual(
+ value,
+ loader.contentScript
+ );
+ try {
+ loader.contentScript = { 1: value }
+ test.fail('must throw when wrong value is set');
+ } catch(e) {
+ test.assertEqual(
+ 'The `contentScript` option must be a string or an array of strings.',
+ e.message
+ );
+ }
+ try {
+ loader.contentScript = ['oue', 2]
+ test.fail('must throw when wrong value is set');
+ } catch(e) {
+ test.assertEqual(
+ 'The `contentScript` option must be a string or an array of strings.',
+ e.message
+ );
+ }
+ loader.contentScript = undefined;
+ test.assertEqual(
+ null,
+ loader.contentScript
+ );
+ loader.contentScript = value = ["1;", "2;"];
+ test.assertEqual(
+ value,
+ loader.contentScript
+ );
+};
+
+exports['test:contentScriptFile'] = function(test) {
+ let loader = Loader(), value, uri = self.data.url("test-content-loader.js");
+ test.assertEqual(
+ null,
+ loader.contentScriptFile,
+ '`contentScriptFile` defaults to `null`'
+ );
+ loader.contentScriptFile = value = uri;
+ test.assertEqual(
+ value,
+ loader.contentScriptFile
+ );
+ try {
+ loader.contentScriptFile = { 1: uri }
+ test.fail('must throw when wrong value is set');
+ } catch(e) {
+ test.assertEqual(
+ 'The `contentScriptFile` option must be a local URL or an array of URLs.',
+ e.message
+ );
+ }
+
+ try {
+ loader.contentScriptFile = [ 'oue', uri ]
+ test.fail('must throw when wrong value is set');
+ } catch(e) {
+ test.assertEqual(
+ 'The `contentScriptFile` option must be a local URL or an array of URLs.',
+ e.message
+ );
+ }
+
+ loader.contentScriptFile = undefined;
+ test.assertEqual(
+ null,
+ loader.contentScriptFile
+ );
+ loader.contentScriptFile = value = [uri];
+ test.assertEqual(
+ value,
+ loader.contentScriptFile
+ );
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-content-proxy.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-content-proxy.js
new file mode 100644
index 0000000..f7f1235
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-content-proxy.js
@@ -0,0 +1,807 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const hiddenFrames = require("hidden-frame");
+const xulApp = require("xul-app");
+
+const { Loader } = require('./helpers');
+
+/*
+ * Utility function that allow to easily run a proxy test with a clean
+ * new HTML document. See first unit test for usage.
+ */
+function createProxyTest(html, callback) {
+ return function (test) {
+ test.waitUntilDone();
+
+ let url = 'data:text/html,' + encodeURI(html);
+
+ let hiddenFrame = hiddenFrames.add(hiddenFrames.HiddenFrame({
+ onReady: function () {
+
+ function onDOMReady() {
+ hiddenFrame.element.removeEventListener("DOMContentLoaded", onDOMReady,
+ false);
+
+ let xrayWindow = hiddenFrame.element.contentWindow;
+ let rawWindow = xrayWindow.wrappedJSObject;
+
+ let done = false;
+ let helper = {
+ xrayWindow: xrayWindow,
+ rawWindow: rawWindow,
+ createWorker: function (contentScript) {
+ return createWorker(test, xrayWindow, contentScript, helper.done);
+ },
+ done: function () {
+ if (done)
+ return;
+ done = true;
+ hiddenFrames.remove(hiddenFrame);
+ test.done();
+ }
+ }
+ callback(helper, test);
+ }
+
+ hiddenFrame.element.addEventListener("DOMContentLoaded", onDOMReady, false);
+ hiddenFrame.element.setAttribute("src", url);
+
+ }
+ }));
+ };
+}
+
+function createWorker(test, xrayWindow, contentScript, done) {
+ // We have to use Sandboxed loader in order to get access to the private
+ // unlock key `PRIVATE_KEY`. This key should not be used anywhere else.
+ // See `PRIVATE_KEY` definition in worker.js
+ let loader = Loader(module);
+ let Worker = loader.require("api-utils/content/worker").Worker;
+ let key = loader.sandbox("api-utils/content/worker").PRIVATE_KEY;
+ let worker = Worker({
+ exposeUnlockKey : key,
+ window: xrayWindow,
+ contentScript: [
+ 'new ' + function () {
+ assert = function assert(v, msg) {
+ self.port.emit("assert", {assertion:v, msg:msg});
+ }
+ done = function done() {
+ self.port.emit("done");
+ }
+ },
+ contentScript
+ ]
+ });
+
+ worker.port.on("done", done);
+ worker.port.on("assert", function (data) {
+ test.assert(data.assertion, data.msg);
+ });
+
+ return worker;
+}
+
+/* Examples for the `createProxyTest` uses */
+
+let html = "<script>var documentGlobal = true</script>";
+exports.testCreateProxyTest = createProxyTest(html, function (helper, test) {
+ // You can get access to regular `test` object in second argument of
+ // `createProxyTest` method:
+ test.assert(helper.rawWindow.documentGlobal,
+ "You have access to a raw window reference via `helper.rawWindow`");
+ test.assert(!("documentGlobal" in helper.xrayWindow),
+ "You have access to an XrayWrapper reference via `helper.xrayWindow`");
+
+ // If you do not create a Worker, you have to call helper.done(),
+ // in order to say when your test is finished
+ helper.done();
+});
+
+exports.testCreateProxyTestWithWorker = createProxyTest("", function (helper) {
+
+ helper.createWorker(
+ "new " + function WorkerScope() {
+ assert(true, "You can do assertions in your content script");
+ // And if you create a worker, you either have to call `done`
+ // from content script or helper.done()
+ done();
+ }
+ );
+
+});
+
+exports.testCreateProxyTestWithEvents = createProxyTest("", function (helper, test) {
+
+ let worker = helper.createWorker(
+ "new " + function WorkerScope() {
+ self.port.emit("foo");
+ }
+ );
+
+ worker.port.on("foo", function () {
+ test.pass("You can use events");
+ // And terminate your test with helper.done:
+ helper.done();
+ });
+
+});
+
+// Verify that the attribute `exposeUnlockKey`, that allow this test
+// to identify proxies, works correctly.
+// See `PRIVATE_KEY` definition in worker.js
+exports.testKeyAccess = createProxyTest("", function(helper) {
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ assert("UNWRAP_ACCESS_KEY" in window, "have access to `UNWRAP_ACCESS_KEY`");
+ done();
+ }
+ );
+
+});
+
+
+// Bug 714778: There was some issue around `toString` functions
+// that ended up being shared between content scripts
+exports.testSharedToStringProxies = createProxyTest("", function(helper) {
+
+ let worker = helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ // We ensure that `toString` can't be modified so that nothing could
+ // leak to/from the document and between content scripts
+ //document.location.toString = function foo() {};
+ document.location.toString.foo = "bar";
+ assert(!("foo" in document.location.toString), "document.location.toString can't be modified");
+ assert(document.location.toString() == "data:text/html,",
+ "First document.location.toString()");
+ self.postMessage("next");
+ }
+ );
+ worker.on("message", function () {
+ helper.createWorker(
+ 'new ' + function ContentScriptScope2() {
+ assert(!("foo" in document.location.toString),
+ "document.location.toString is different for each content script");
+ assert(document.location.toString() == "data:text/html,",
+ "Second document.location.toString()");
+ done();
+ }
+ );
+ });
+});
+
+
+// Ensure that postMessage is working correctly across documents with an iframe
+let html = '<iframe id="iframe" name="test" src="data:text/html," />';
+exports.testPostMessage = createProxyTest(html, function (helper, test) {
+ let ifWindow = helper.xrayWindow.document.getElementById("iframe").contentWindow;
+ // Listen without proxies, to check that it will work in regular case
+ // simulate listening from a web document.
+ ifWindow.addEventListener("message", function listener(event) {
+ //if (event.source.wrappedJSObject == helper.rawWindow) return;
+ ifWindow.removeEventListener("message", listener, false);
+ // As we are in system principal, event is an XrayWrapper
+ test.assertEqual(event.source, ifWindow,
+ "event.source is the iframe window");
+ test.assertEqual(event.origin, "null", "origin is null");
+
+ test.assertEqual(event.data, "{\"foo\":\"bar\\n \\\"escaped\\\".\"}",
+ "message data is correct");
+
+ helper.done();
+ }, false);
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ assert(postMessage === postMessage,
+ "verify that we doesn't generate multiple functions for the same method");
+
+ var json = JSON.stringify({foo : "bar\n \"escaped\"."});
+
+ document.getElementById("iframe").contentWindow.postMessage(json, "*");
+ }
+ );
+});
+
+let html = '<input id="input2" type="checkbox" />';
+exports.testObjectListener = createProxyTest(html, function (helper) {
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ // Test objects being given as event listener
+ let input = document.getElementById("input2");
+ let myClickListener = {
+ called: false,
+ handleEvent: function(event) {
+ assert(this === myClickListener, "`this` is the original object");
+ assert(!this.called, "called only once");
+ this.called = true;
+ assert(event.valueOf() !== event.valueOf(UNWRAP_ACCESS_KEY), "event is wrapped");
+ assert(event.target, input, "event.target is the wrapped window");
+ done();
+ }
+ };
+
+ window.addEventListener("click", myClickListener, true);
+ input.click();
+ window.removeEventListener("click", myClickListener, true);
+ }
+ );
+
+});
+
+exports.testObjectListener2 = createProxyTest("", function (helper) {
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ // Verify object as DOM event listener
+ let myMessageListener = {
+ called: false,
+ handleEvent: function(event) {
+ window.removeEventListener("message", myMessageListener, true);
+
+ assert(this == myMessageListener, "`this` is the original object");
+ assert(!this.called, "called only once");
+ this.called = true;
+ assert(event.valueOf() !== event.valueOf(UNWRAP_ACCESS_KEY), "event is wrapped");
+ assert(event.target == document.defaultView, "event.target is the wrapped window");
+ assert(event.source == document.defaultView, "event.source is the wrapped window");
+ assert(event.origin == "null", "origin is null");
+ assert(event.data == "ok", "message data is correct");
+ done();
+ }
+ };
+
+ window.addEventListener("message", myMessageListener, true);
+ document.defaultView.postMessage("ok", '*');
+ }
+ );
+
+});
+
+let html = '<input id="input" type="text" /><input id="input3" type="checkbox" />' +
+ '<input id="input2" type="checkbox" />';
+exports.testStringOverload = createProxyTest(html, function (helper, test) {
+ // Proxy - toString error
+ let originalString = "string";
+ let p = Proxy.create({
+ get: function(receiver, name) {
+ if (name == "binded")
+ return originalString.toString.bind(originalString);
+ return originalString[name];
+ }
+ });
+ test.assertRaises(function () {
+ p.toString();
+ },
+ /String.prototype.toString called on incompatible Proxy/,
+ "toString can't be called with this being the proxy");
+ test.assertEqual(p.binded(), "string", "but it works if we bind this to the original string");
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ // RightJS is hacking around String.prototype, and do similar thing:
+ // Pass `this` from a String prototype method.
+ // It is funny because typeof this == "object"!
+ // So that when we pass `this` to a native method,
+ // our proxy code can fail on another even more crazy thing.
+ // See following test to see what fails around proxies.
+ String.prototype.update = function () {
+ assert(typeof this == "object", "in update, `this` is an object");
+ assert(this.toString() == "input", "in update, `this.toString works");
+ return document.querySelectorAll(this);
+ };
+ assert("input".update().length == 3, "String.prototype overload works");
+ done();
+ }
+ );
+});
+
+exports.testMozMatchedSelector = createProxyTest("", function (helper) {
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ // Check mozMatchesSelector XrayWrappers bug:
+ // mozMatchesSelector returns bad results when we are not calling it from the node itself
+ // SEE BUG 658909: mozMatchesSelector returns incorrect results with XrayWrappers
+ assert(document.createElement( "div" ).mozMatchesSelector("div"),
+ "mozMatchesSelector works while being called from the node");
+ assert(document.documentElement.mozMatchesSelector.call(
+ document.createElement( "div" ),
+ "div"
+ ),
+ "mozMatchesSelector works while being called from a " +
+ "function reference to " +
+ "document.documentElement.mozMatchesSelector.call");
+ done();
+ }
+ );
+});
+
+exports.testEventsOverload = createProxyTest("", function (helper) {
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ // If we add a "____proxy" attribute on XrayWrappers in order to store
+ // the related proxy to create an unique proxy for each wrapper;
+ // we end up setting this attribute to prototype objects :x
+ // And so, instances created with such prototype will be considered
+ // as equal to the prototype ...
+ // // Internal method that return the proxy for a given XrayWrapper
+ // function proxify(obj) {
+ // if (obj._proxy) return obj._proxy;
+ // return obj._proxy = Proxy.create(...);
+ // }
+ //
+ // // Get a proxy of an XrayWrapper prototype object
+ // let proto = proxify(xpcProto);
+ //
+ // // Use this proxy as a prototype
+ // function Constr() {}
+ // Constr.proto = proto;
+ //
+ // // Try to create an instance using this prototype
+ // let xpcInstance = new Constr();
+ // let wrapper = proxify(xpcInstance)
+ //
+ // xpcProto._proxy = proto and as xpcInstance.__proto__ = xpcProto,
+ // xpcInstance._proxy = proto ... and profixy(xpcInstance) = proto :(
+ //
+ let proto = window.document.createEvent('HTMLEvents').__proto__;
+ window.Event.prototype = proto;
+ let event = document.createEvent('HTMLEvents');
+ assert(event !== proto, "Event should not be equal to its prototype");
+ event.initEvent('dataavailable', true, true);
+ assert(event.type === 'dataavailable', "Events are working fine");
+ done();
+ }
+ );
+
+});
+
+exports.testNestedAttributes = createProxyTest("", function (helper) {
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ // XrayWrappers has a bug when you set an attribute on it,
+ // in some cases, it creates an unnecessary wrapper that introduces
+ // a different object that refers to the same original object
+ // Check that our wrappers don't reproduce this bug
+ // SEE BUG 658560: Fix identity problem with CrossOriginWrappers
+ let o = {sandboxObject:true};
+ window.nested = o;
+ o.foo = true;
+ assert(o === window.nested, "Nested attribute to sandbox object should not be proxified");
+ window.nested = document;
+ assert(window.nested === document, "Nested attribute to proxy should not be double proxified");
+ done();
+ }
+ );
+
+});
+
+exports.testFormNodeName = createProxyTest("", function (helper) {
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ let body = document.body;
+ // Check form[nodeName]
+ let form = document.createElement("form");
+ let input = document.createElement("input");
+ input.setAttribute("name", "test");
+ form.appendChild(input);
+ body.appendChild(form);
+ assert(form.test == input, "form[nodeName] is valid");
+ body.removeChild(form);
+ done();
+ }
+ );
+
+});
+
+exports.testLocalStorage = createProxyTest("", function (helper, test) {
+
+ let worker = helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ // Check localStorage:
+ assert(window.localStorage, "has access to localStorage");
+ window.localStorage.name = 1;
+ assert(window.localStorage.name == 1, "localStorage appears to work");
+
+ self.port.on("step2", function () {
+ window.localStorage.clear();
+ assert(window.localStorage.name == undefined, "localStorage really, really works");
+ done();
+ });
+ self.port.emit("step1");
+ }
+ );
+
+ worker.port.on("step1", function () {
+ test.assertEqual(helper.rawWindow.localStorage.name, 1, "localStorage really works");
+ worker.port.emit("step2");
+ });
+
+});
+
+exports.testAutoUnwrapCustomAttributes = createProxyTest("", function (helper) {
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ let body = document.body;
+ // Setting a custom object to a proxy attribute is not wrapped when we get it afterward
+ let object = {custom: true, enumerable: false};
+ body.customAttribute = object;
+ assert(body.customAttribute.valueOf() === body.customAttribute.valueOf(UNWRAP_ACCESS_KEY), "custom JS attributes are not wrapped");
+ assert(object === body.customAttribute, "custom JS attributes are not wrapped");
+ done();
+ }
+ );
+
+});
+
+exports.testObjectTag = createProxyTest("", function (helper) {
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ // <object>, <embed> and other tags return typeof 'function'
+ let flash = document.createElement("object");
+ assert(typeof flash == "function", "<object> is typeof 'function'");
+ assert(flash.toString().match(/\[object HTMLObjectElement.*\]/), "<object> is HTMLObjectElement");
+ assert("setAttribute" in flash, "<object> has a setAttribute method");
+ done();
+ }
+ );
+
+});
+
+exports.testHighlightToStringBehavior = createProxyTest("", function (helper, test) {
+ // We do not have any workaround this particular use of toString
+ // applied on <object> elements. So disable this test until we found one!
+ //test.assertEqual(helper.rawWindow.Object.prototype.toString.call(flash), "[object HTMLObjectElement]", "<object> is HTMLObjectElement");
+ function f() {};
+ test.assertMatches(Object.prototype.toString.call(f), /\[object Function.*\]/, "functions are functions 1");
+ // This is how jquery call toString:
+ test.assertMatches(helper.rawWindow.Object.prototype.toString.call(""), /\[object String.*\]/, "strings are strings");
+ test.assertMatches(helper.rawWindow.Object.prototype.toString.call({}), /\[object Object.*\]/, "objects are objects");
+
+ // Make sure to pass a function from the same compartments
+ // or toString will return [object Object] on FF8+
+ let f2 = helper.rawWindow.eval("(function () {})");
+ test.assertMatches(helper.rawWindow.Object.prototype.toString.call(f2), /\[object Function.*\]/, "functions are functions 2");
+
+ helper.done();
+});
+
+exports.testDocumentTagName = createProxyTest("", function (helper) {
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ let body = document.body;
+ // Check document[tagName]
+ let div = document.createElement("div");
+ div.setAttribute("name", "test");
+ body.appendChild(div);
+ assert(!document.test, "document[divName] is undefined");
+ body.removeChild(div);
+
+ let form = document.createElement("form");
+ form.setAttribute("name", "test");
+ body.appendChild(form);
+ assert(document.test == form, "document[formName] is valid");
+ body.removeChild(form);
+
+ let img = document.createElement("img");
+ img.setAttribute("name", "test");
+ body.appendChild(img);
+ assert(document.test == img, "document[imgName] is valid");
+ body.removeChild(img);
+ done();
+ }
+ );
+
+});
+
+let html = '<iframe id="iframe" name="test" src="data:text/html," />';
+exports.testWindowFrames = createProxyTest(html, function (helper) {
+
+ helper.createWorker(
+ 'let glob = this; new ' + function ContentScriptScope() {
+ // Check window[frameName] and window.frames[i]
+ let iframe = document.getElementById("iframe");
+ //assert(window.frames.length == 1, "The iframe is reported in window.frames check1");
+ //assert(window.frames[0] == iframe.contentWindow, "The iframe is reported in window.frames check2");
+ //console.log(window.test+ "-"+iframe.contentWindow);
+ //console.log(window);
+ assert(window.test == iframe.contentWindow, "window[frameName] is valid");
+ done();
+ }
+ );
+
+});
+
+exports.testCollections = createProxyTest("", function (helper) {
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ // Highlight XPCNativeWrapper bug with HTMLCollection
+ // tds[0] is only defined on first access :o
+ let body = document.body;
+ let div = document.createElement("div");
+ body.appendChild(div);
+ div.innerHTML = "<table><tr><td style='padding:0;border:0;display:none'></td><td>t</td></tr></table>";
+ let tds = div.getElementsByTagName("td");
+ assert(tds[0] == tds[0], "We can get array element multiple times");
+ body.removeChild(div);
+ done();
+ }
+ );
+
+});
+
+let html = '<input id="input" type="text" /><input id="input3" type="checkbox" />' +
+ '<input id="input2" type="checkbox" />';
+exports.testCollections2 = createProxyTest(html, function (helper) {
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ // Verify that NodeList/HTMLCollection are working fine
+ let body = document.body;
+ let inputs = body.getElementsByTagName("input");
+ assert(body.childNodes.length == 3, "body.childNodes length is correct");
+ assert(inputs.length == 3, "inputs.length is correct");
+ assert(body.childNodes[0] == inputs[0], "body.childNodes[0] is correct");
+ assert(body.childNodes[1] == inputs[1], "body.childNodes[1] is correct");
+ assert(body.childNodes[2] == inputs[2], "body.childNodes[2] is correct");
+ let count = 0;
+ for(let i in body.childNodes) {
+ count++;
+ }
+ assert(count == 3, "body.childNodes is iterable");
+ done();
+ }
+ );
+
+});
+
+exports.testValueOf = createProxyTest("", function (helper) {
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ // Check internal use of valueOf()
+ assert(window.valueOf().toString().match(/\[object Window.*\]/), "proxy.valueOf() returns the wrapped version");
+ assert(window.valueOf({}).toString().match(/\[object Window.*\]/), "proxy.valueOf({}) returns the wrapped version");
+ assert(window.valueOf(UNWRAP_ACCESS_KEY).toString().match(/\[object XrayWrapper \[object Window.*\].*\]/), "proxy.valueOf(UNWRAP_ACCESS_KEY) returns the unwrapped version");
+ done();
+ }
+ );
+
+});
+
+exports.testXMLHttpRequest = createProxyTest("", function (helper) {
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ // XMLHttpRequest doesn't support XMLHttpRequest.apply,
+ // that may break our proxy code
+ assert(window.XMLHttpRequest(), "we are able to instantiate XMLHttpRequest object");
+ done();
+ }
+ );
+
+});
+
+exports.testXPathResult = createProxyTest("", function (helper, test) {
+
+ // Check XPathResult bug with constants being undefined on
+ // XPCNativeWrapper
+ let value = helper.rawWindow.XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE;
+ let xpcXPathResult = helper.xrayWindow.XPathResult;
+ test.assertEqual(xpcXPathResult.wrappedJSObject.
+ UNORDERED_NODE_SNAPSHOT_TYPE,
+ value,
+ "XPathResult's constants are valid on unwrapped node");
+
+ if (xulApp.versionInRange(xulApp.platformVersion, "10.0a1", "*")) {
+ test.assertEqual(xpcXPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, 6,
+ "XPathResult's constants are defined on " +
+ "XPCNativeWrapper (platform bug #)");
+ }
+ else {
+ test.assertEqual(xpcXPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
+ undefined,
+ "XPathResult's constants are undefined on " +
+ "XPCNativeWrapper (platform bug #665279)");
+ }
+
+ let worker = helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ self.port.on("value", function (value) {
+ // Check that our work around is working:
+ assert(window.XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE === value,
+ "XPathResult works correctly on Proxies");
+ done();
+ });
+ }
+ );
+ worker.port.emit("value", value);
+
+});
+
+exports.testPrototypeInheritance = createProxyTest("", function (helper) {
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ // Verify that inherited prototype function like initEvent
+ // are handled correctly. (e2.type will return an error if it's not the case)
+ let event1 = document.createEvent( 'MouseEvents' );
+ event1.initEvent( "click", true, true );
+ let event2 = document.createEvent( 'MouseEvents' );
+ event2.initEvent( "click", true, true );
+ assert(event2.type == "click", "We are able to create an event");
+ done();
+ }
+ );
+
+});
+
+exports.testFunctions = createProxyTest("", function (helper) {
+
+ helper.rawWindow.callFunction = function (f) f();
+ helper.rawWindow.isEqual = function (a, b) a == b;
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ // Check basic usage of functions
+ let closure2 = function () {return "ok";};
+ assert(window.wrappedJSObject.callFunction(closure2) == "ok", "Function references work");
+
+ // Ensure that functions are cached when being wrapped to native code
+ let closure = function () {};
+ assert(window.wrappedJSObject.isEqual(closure, closure), "Function references are cached before being wrapped to native");
+ done();
+ }
+ );
+
+});
+
+let html = '<input id="input2" type="checkbox" />';
+exports.testListeners = createProxyTest(html, function (helper) {
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ // Verify listeners:
+ let input = document.getElementById("input2");
+ assert(input, "proxy.getElementById works");
+
+ function onclick() {};
+ input.onclick = onclick;
+ assert(input.onclick === onclick, "on* attributes are equal to original function set");
+
+ let addEventListenerCalled = false;
+ let expandoCalled = false;
+ input.addEventListener("click", function onclick(event) {
+ input.removeEventListener("click", onclick, true);
+
+ assert(!addEventListenerCalled, "closure given to addEventListener is called once");
+ if (addEventListenerCalled)
+ return;
+ addEventListenerCalled = true;
+
+ assert(!event.target.ownerDocument.defaultView.documentGlobal, "event object is still wrapped and doesn't expose document globals");
+ assert("__isWrappedProxy" in event.target, "event object is a proxy");
+
+ let input2 = document.getElementById("input2");
+
+ input.onclick = function (event) {
+ input.onclick = null;
+ assert(!expandoCalled, "closure set to expando is called once");
+ if (expandoCalled) return;
+ expandoCalled = true;
+
+ assert(!event.target.ownerDocument.defaultView.documentGlobal, "event object is still wrapped and doesn't expose document globals");
+ assert("__isWrappedProxy" in event.target, "event object is a proxy");
+
+ setTimeout(function () {
+ input.click();
+ done();
+ }, 0);
+
+ }
+
+ setTimeout(function () {
+ input.click();
+ }, 0);
+
+ }, true);
+
+ input.click();
+ }
+ );
+
+});
+
+exports.testMozRequestAnimationFrame = createProxyTest("", function (helper) {
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ window.mozRequestAnimationFrame(function callback() {
+ assert(callback == this, "callback is equal to `this`");
+ done();
+ });
+ }
+ );
+
+});
+
+exports.testGlobalScope = createProxyTest("", function (helper) {
+
+ helper.createWorker(
+ 'let toplevelScope = true;' +
+ 'assert(window.toplevelScope, "variables in toplevel scope are set to `window` object");' +
+ 'assert(this.toplevelScope, "variables in toplevel scope are set to `this` object");' +
+ 'done();'
+ );
+
+});
+
+// Bug 671016: Typed arrays should not be proxified
+exports.testTypedArrays = createProxyTest("", function (helper) {
+
+ helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ let canvas = document.createElement("canvas");
+ let context = canvas.getContext("2d");
+ let imageData = context.getImageData(0,0, 1, 1);
+ let unwrappedData = imageData.valueOf(UNWRAP_ACCESS_KEY).data;
+ let data = imageData.data;
+ assert(unwrappedData === data, "Typed array isn't proxified")
+ done();
+ }
+ );
+
+});
+
+// Bug 715755: proxy code throw an exception on COW
+// Create an http server in order to simulate real cross domain documents
+exports.testCrossDomainIframe = createProxyTest("", function (helper) {
+ let serverPort = 8099;
+ let server = require("httpd").startServerAsync(serverPort);
+ server.registerPathHandler("/", function handle(request, response) {
+ // Returns an empty webpage
+ response.write("");
+ });
+
+ let worker = helper.createWorker(
+ 'new ' + function ContentScriptScope() {
+ // Waits for the server page url
+ self.on("message", function (url) {
+ // Creates an iframe with this page
+ let iframe = document.createElement("iframe");
+ iframe.addEventListener("load", function onload() {
+ iframe.removeEventListener("load", onload, true);
+ try {
+ // Try accessing iframe's content that is made of COW wrappers
+ // Take care of debug builds that add object address after `Window`
+ assert(String(iframe.contentWindow).match(/\[object Window.*\]/),
+ "COW works properly");
+ } catch(e) {
+ assert(false, "COW fails : "+e.message);
+ }
+ self.port.emit("end");
+ }, true);
+ iframe.setAttribute("src", url);
+ document.body.appendChild(iframe);
+ });
+ }
+ );
+
+ worker.port.on("end", function () {
+ server.stop(helper.done);
+ });
+
+ worker.postMessage("http://localhost:" + serverPort + "/");
+
+});
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-content-symbiont.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-content-symbiont.js
new file mode 100644
index 0000000..526af05
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-content-symbiont.js
@@ -0,0 +1,190 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Cc, Ci } = require('chrome');
+const { Symbiont } = require('content/symbiont');
+const self = require("self");
+
+function makeWindow() {
+ let content =
+ '<?xml version="1.0"?>' +
+ '<window ' +
+ 'xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">' +
+ '<iframe id="content" type="content"/>' +
+ '</window>';
+ var url = "data:application/vnd.mozilla.xul+xml," +
+ encodeURIComponent(content);
+ var features = ["chrome", "width=10", "height=10"];
+
+ return Cc["@mozilla.org/embedcomp/window-watcher;1"].
+ getService(Ci.nsIWindowWatcher).
+ openWindow(null, url, null, features.join(","), null);
+}
+
+exports['test:constructing symbiont && validating API'] = function(test) {
+ let window = makeWindow();
+ window.addEventListener("load", function onLoad() {
+ window.removeEventListener("load", onLoad, false);
+ let frame = window.document.getElementById("content");
+ // TODO: support arrays ??
+ let contentScripts = ["1;", "2;"];
+ let contentSymbiont = Symbiont({
+ frame: frame,
+ contentScriptFile: self.data.url("test-content-symbiont.js"),
+ contentScript: contentScripts,
+ contentScriptWhen: "start"
+ });
+
+ test.assertEqual(
+ self.data.url("test-content-symbiont.js"),
+ contentSymbiont.contentScriptFile,
+ "There is one contentScriptFile, as specified in options."
+ );
+ test.assertEqual(
+ contentScripts.length,
+ contentSymbiont.contentScript.length,
+ "There are two contentScripts, as specified in options."
+ );
+ test.assertEqual(
+ contentScripts[0],
+ contentSymbiont.contentScript[0],
+ "There are two contentScripts, as specified in options."
+ );
+ test.assertEqual(
+ contentScripts[1],
+ contentSymbiont.contentScript[1],
+ "There are two contentScripts, as specified in options."
+ )
+ test.assertEqual(
+ contentSymbiont.contentScriptWhen,
+ "start",
+ "contentScriptWhen is as specified in options."
+ );
+
+ test.done();
+ window.close();
+ frame.setAttribute("src", "data:text/html,<html><body></body></html>");
+ }, false);
+ test.waitUntilDone();
+};
+
+exports["test:communication with worker global scope"] = function(test) {
+ let window = makeWindow();
+ let contentSymbiont;
+
+ function onMessage1(message) {
+ test.assertEqual(message, 1, "Program gets message via onMessage.");
+ contentSymbiont.removeListener('message', onMessage1);
+ contentSymbiont.on('message', onMessage2);
+ contentSymbiont.postMessage(2);
+ };
+
+ function onMessage2(message) {
+ if (5 == message) {
+ test.done();
+ } else {
+ test.assertEqual(message, 3, "Program gets message via onMessage2.");
+ contentSymbiont.postMessage(4)
+ }
+ }
+
+ window.addEventListener("load", function onLoad() {
+ window.removeEventListener("load", onLoad, false);
+ let frame = window.document.getElementById("content");
+ contentSymbiont = Symbiont({
+ frame: frame,
+ contentScript: 'new ' + function() {
+ self.postMessage(1);
+ self.on("message", function onMessage(message) {
+ if (message === 2)
+ self.postMessage(3);
+ if (message === 4)
+ self.postMessage(5);
+ });
+ } + '()',
+ contentScriptWhen: 'ready',
+ onMessage: onMessage1
+ });
+
+ frame.setAttribute("src", "data:text/html,<html><body></body></html>");
+ }, false);
+ test.waitUntilDone();
+};
+
+exports['test:pageWorker'] = function(test) {
+ test.waitUntilDone();
+ let worker = Symbiont({
+ contentURL: 'about:buildconfig',
+ contentScript: 'new ' + function WorkerScope() {
+ self.on('message', function(data) {
+ if (data.valid)
+ self.postMessage('bye!');
+ })
+ self.postMessage(window.location.toString());
+ },
+ onMessage: function(msg) {
+ if (msg == 'bye!') {
+ test.done()
+ } else {
+ test.assertEqual(
+ worker.contentURL + '',
+ msg
+ );
+ worker.postMessage({ valid: true });
+ }
+ }
+ });
+};
+
+exports["test:document element present on 'start'"] = function(test) {
+ test.waitUntilDone();
+ let xulApp = require("xul-app");
+ let worker = Symbiont({
+ contentURL: "about:buildconfig",
+ contentScript: "self.postMessage(!!document.documentElement)",
+ contentScriptWhen: "start",
+ onMessage: function(message) {
+ if (xulApp.versionInRange(xulApp.platformVersion, "2.0b6", "*"))
+ test.assert(message, "document element present on 'start'");
+ else
+ test.pass("document element not necessarily present on 'start'");
+ test.done();
+ }
+ });
+};
+
+exports["test:direct communication with trusted document"] = function(test) {
+ test.waitUntilDone();
+
+ let worker = Symbiont({
+ contentURL: require("self").data.url("test-trusted-document.html")
+ });
+
+ worker.port.on('document-to-addon', function (arg) {
+ test.assertEqual(arg, "ok", "Received an event from the document");
+ worker.destroy();
+ test.done();
+ });
+ worker.port.emit('addon-to-document', 'ok');
+};
+
+exports["test:`addon` is not available when a content script is set"] = function(test) {
+ test.waitUntilDone();
+
+ let worker = Symbiont({
+ contentURL: require("self").data.url("test-trusted-document.html"),
+ contentScript: "new " + function ContentScriptScope() {
+ self.port.emit("cs-to-addon", "addon" in unsafeWindow);
+ }
+ });
+
+ worker.port.on('cs-to-addon', function (hasAddon) {
+ test.assertEqual(hasAddon, false,
+ "`addon` is not available");
+ worker.destroy();
+ test.done();
+ });
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-content-worker.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-content-worker.js
new file mode 100644
index 0000000..d5e95a1
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-content-worker.js
@@ -0,0 +1,465 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use stirct";
+
+const { Cc, Ci } = require('chrome');
+const timer = require('timer');
+const { Loader } = require("@loader");
+
+function makeWindow(contentURL) {
+ let content =
+ '<?xml version="1.0"?>' +
+ '<window ' +
+ 'xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">' +
+ '<iframe id="content" type="content" src="' +
+ encodeURIComponent(contentURL) + '"/>' +
+ '<script>var documentValue=true;</script>' +
+ '</window>';
+ var url = "data:application/vnd.mozilla.xul+xml," +
+ encodeURIComponent(content);
+ var features = ["chrome", "width=10", "height=10"];
+
+ return Cc["@mozilla.org/embedcomp/window-watcher;1"].
+ getService(Ci.nsIWindowWatcher).
+ openWindow(null, url, null, features.join(","), null);
+}
+
+const { Worker } = require('content/worker');
+exports['test:sample'] = function(test) {
+ let window = makeWindow();
+ test.waitUntilDone();
+
+ // As window has just being created, its document is still loading,
+ // and we have about:blank document before the expected one
+ test.assertEqual(window.document.location.href, "about:blank",
+ "window starts by loading about:blank");
+
+ // We need to wait for the load/unload of temporary about:blank
+ // or our worker is going to be automatically destroyed
+ window.addEventListener("load", function onload() {
+ window.removeEventListener("load", onload, true);
+
+ test.assertNotEqual(window.document.location.href, "about:blank",
+ "window is now on the right document");
+
+ let worker = Worker({
+ window: window,
+ contentScript: 'new ' + function WorkerScope() {
+ // window is accessible
+ let myLocation = window.location.toString();
+ self.on('message', function(data) {
+ if (data == 'hi!')
+ self.postMessage('bye!');
+ });
+ },
+ contentScriptWhen: 'ready',
+ onMessage: function(msg) {
+ test.assertEqual('bye!', msg);
+ test.assertEqual(worker.url, window.document.location.href,
+ "worker.url still works");
+ test.done();
+ }
+ });
+
+ test.assertEqual(worker.url, window.document.location.href,
+ "worker.url works");
+ worker.postMessage('hi!');
+
+ }, true);
+
+}
+
+exports['test:emit'] = function(test) {
+ let window = makeWindow();
+ test.waitUntilDone();
+
+ let worker = Worker({
+ window: window,
+ contentScript: 'new ' + function WorkerScope() {
+ // Validate self.on and self.emit
+ self.port.on('addon-to-content', function (data) {
+ self.port.emit('content-to-addon', data);
+ });
+
+ // Check for global pollution
+ //if (typeof on != "undefined")
+ // self.postMessage("`on` is in globals");
+ if (typeof once != "undefined")
+ self.postMessage("`once` is in globals");
+ if (typeof emit != "undefined")
+ self.postMessage("`emit` is in globals");
+
+ },
+ onMessage: function(msg) {
+ test.fail("Got an unexpected message : "+msg);
+ }
+ });
+
+ // Validate worker.port
+ worker.port.on('content-to-addon', function (data) {
+ test.assertEqual(data, "event data");
+ test.done();
+ });
+ worker.port.emit('addon-to-content', 'event data');
+
+}
+
+exports['test:emit hack message'] = function(test) {
+ let window = makeWindow();
+ test.waitUntilDone();
+
+ let worker = Worker({
+ window: window,
+ contentScript: 'new ' + function WorkerScope() {
+ // Validate self.port
+ self.port.on('message', function (data) {
+ self.port.emit('message', data);
+ });
+ // We should not receive message on self, but only on self.port
+ self.on('message', function (data) {
+ self.postMessage('message', data);
+ });
+ },
+ onError: function(e) {
+ test.fail("Got exception: "+e);
+ }
+ });
+
+ worker.port.on('message', function (data) {
+ test.assertEqual(data, "event data");
+ test.done();
+ });
+ worker.on('message', function (data) {
+ test.fail("Got an unexpected message : "+msg);
+ });
+ worker.port.emit('message', 'event data');
+
+}
+
+exports['test:n-arguments emit'] = function(test) {
+ let window = makeWindow();
+ test.waitUntilDone();
+
+ let worker = Worker({
+ window: window,
+ contentScript: 'new ' + function WorkerScope() {
+ // Validate self.on and self.emit
+ self.port.on('addon-to-content', function (a1, a2, a3) {
+ self.port.emit('content-to-addon', a1, a2, a3);
+ });
+ }
+ });
+
+ // Validate worker.port
+ worker.port.on('content-to-addon', function (arg1, arg2, arg3) {
+ test.assertEqual(arg1, "first argument");
+ test.assertEqual(arg2, "second");
+ test.assertEqual(arg3, "third");
+ test.done();
+ });
+ worker.port.emit('addon-to-content', 'first argument', 'second', 'third');
+}
+
+exports['test:post-json-values-only'] = function(test) {
+ let window = makeWindow("data:text/html,");
+ test.waitUntilDone();
+
+ window.addEventListener("load", function onload() {
+ window.removeEventListener("load", onload, true);
+
+ let worker = Worker({
+ window: window.document.getElementById("content").contentWindow,
+ contentScript: 'new ' + function WorkerScope() {
+ self.on('message', function (message) {
+ self.postMessage([ message.fun === undefined,
+ typeof message.w,
+ message.w && "port" in message.w,
+ message.w.url,
+ Array.isArray(message.array),
+ JSON.stringify(message.array)]);
+ });
+ }
+ });
+
+ // Validate worker.onMessage
+ let array = [1, 2, 3];
+ worker.on('message', function (message) {
+ test.assert(message[0], "function becomes undefined");
+ test.assertEqual(message[1], "object", "object stays object");
+ test.assert(message[2], "object's attributes are enumerable");
+ test.assertEqual(message[3], "about:blank", "jsonable attributes are accessible");
+ // See bug 714891, Arrays may be broken over compartements:
+ test.assert(message[4], "Array keeps being an array");
+ test.assertEqual(message[5], JSON.stringify(array),
+ "Array is correctly serialized");
+ test.done();
+ });
+ worker.postMessage({ fun: function () {}, w: worker, array: array });
+
+ }, true);
+
+};
+
+
+exports['test:emit-json-values-only'] = function(test) {
+ let window = makeWindow("data:text/html,");
+ test.waitUntilDone();
+
+ window.addEventListener("load", function onload() {
+ window.removeEventListener("load", onload, true);
+
+ let win = window.document.getElementById("content").contentWindow;
+ let worker = Worker({
+ window: win,
+ contentScript: 'new ' + function WorkerScope() {
+ // Validate self.on and self.emit
+ self.port.on('addon-to-content', function (fun, w, obj, array) {
+ self.port.emit('content-to-addon', [
+ fun === null,
+ typeof w,
+ "port" in w,
+ w.url,
+ "fun" in obj,
+ Object.keys(obj.dom).length,
+ Array.isArray(array),
+ JSON.stringify(array)
+ ]);
+ });
+ }
+ });
+
+ // Validate worker.port
+ let array = [1, 2, 3];
+ worker.port.on('content-to-addon', function (result) {
+ test.assert(result[0], "functions become null");
+ test.assertEqual(result[1], "object", "objects stay objects");
+ test.assert(result[2], "object's attributes are enumerable");
+ test.assertEqual(result[3], "about:blank", "json attribute is accessible");
+ test.assert(!result[4], "function as object attribute is removed");
+ test.assertEqual(result[5], 0, "DOM nodes are converted into empty object");
+ // See bug 714891, Arrays may be broken over compartments:
+ test.assert(result[6], "Array keeps being an array");
+ test.assertEqual(result[7], JSON.stringify(array),
+ "Array is correctly serialized");
+ test.done();
+ });
+
+ let obj = {
+ fun: function () {},
+ dom: window.document.createElement("div")
+ };
+ worker.port.emit("addon-to-content", function () {}, worker, obj, array);
+
+ }, true);
+}
+
+exports['test:content is wrapped'] = function(test) {
+ let contentURL = 'data:text/html,<script>var documentValue=true;</script>';
+ let window = makeWindow(contentURL);
+ test.waitUntilDone();
+
+ window.addEventListener("load", function onload() {
+ window.removeEventListener("load", onload, true);
+
+ let worker = Worker({
+ window: window.document.getElementById("content").contentWindow,
+ contentScript: 'new ' + function WorkerScope() {
+ self.postMessage(!window.documentValue);
+ },
+ contentScriptWhen: 'ready',
+ onMessage: function(msg) {
+ test.assert(msg,
+ "content script has a wrapped access to content document");
+ test.done();
+ }
+ });
+
+ }, true);
+
+}
+
+exports['test:chrome is unwrapped'] = function(test) {
+ let window = makeWindow();
+ test.waitUntilDone();
+
+ window.addEventListener("load", function onload() {
+ window.removeEventListener("load", onload, true);
+
+ let worker = Worker({
+ window: window,
+ contentScript: 'new ' + function WorkerScope() {
+ self.postMessage(window.documentValue);
+ },
+ contentScriptWhen: 'ready',
+ onMessage: function(msg) {
+ test.assert(msg,
+ "content script has an unwrapped access to chrome document");
+ test.done();
+ }
+ });
+
+ }, true);
+
+}
+
+exports['test:nothing is leaked to content script'] = function(test) {
+ let window = makeWindow();
+ test.waitUntilDone();
+
+ window.addEventListener("load", function onload() {
+ window.removeEventListener("load", onload, true);
+
+ let worker = Worker({
+ window: window,
+ contentScript: 'new ' + function WorkerScope() {
+ self.postMessage([
+ "ContentWorker" in window,
+ "UNWRAP_ACCESS_KEY" in window,
+ "getProxyForObject" in window
+ ]);
+ },
+ contentScriptWhen: 'ready',
+ onMessage: function(list) {
+ test.assert(!list[0], "worker API contrustor isn't leaked");
+ test.assert(!list[1], "Proxy API stuff isn't leaked 1/2");
+ test.assert(!list[2], "Proxy API stuff isn't leaked 2/2");
+ test.done();
+ }
+ });
+
+ }, true);
+
+}
+
+exports['test:ensure console.xxx works in cs'] = function(test) {
+ test.waitUntilDone(5000);
+
+ // Create a new module loader in order to be able to create a `console`
+ // module mockup:
+ let sandbox = Loader.new(require("@packaging"));
+ let sandboxRequire = Loader.require.bind(sandbox, module.path);
+ Object.defineProperty(sandbox.globals, 'console', {
+ value: {
+ log: hook.bind("log"),
+ info: hook.bind("info"),
+ warn: hook.bind("warn"),
+ error: hook.bind("error"),
+ debug: hook.bind("debug"),
+ exception: hook.bind("exception")
+ }
+ });
+
+ // Intercept all console method calls
+ let calls = [];
+ function hook(msg) {
+ test.assertEqual(this, msg,
+ "console.xxx(\"xxx\"), i.e. message is equal to the " +
+ "console method name we are calling");
+ calls.push(msg);
+ }
+
+ // Finally, create a worker that will call all console methods
+ let window = makeWindow();
+ window.addEventListener("load", function onload() {
+ window.removeEventListener("load", onload, true);
+
+ let worker = sandboxRequire('content/worker').Worker({
+ window: window,
+ contentScript: 'new ' + function WorkerScope() {
+ console.log("log");
+ console.info("info");
+ console.warn("warn");
+ console.error("error");
+ console.debug("debug");
+ console.exception("exception");
+ self.postMessage();
+ },
+ onMessage: function() {
+ // Ensure that console methods are called in the same execution order
+ test.assertEqual(JSON.stringify(calls),
+ JSON.stringify(["log", "info", "warn", "error", "debug", "exception"]),
+ "console has been called successfully, in the expected order");
+ test.done();
+ }
+ });
+ }, true);
+
+}
+
+
+exports['test:setTimeout can\'t be cancelled by content'] = function(test) {
+ let contentURL = 'data:text/html,<script>var documentValue=true;</script>';
+ let window = makeWindow(contentURL);
+ test.waitUntilDone();
+
+ window.addEventListener("load", function onload() {
+ window.removeEventListener("load", onload, true);
+
+ let worker = Worker({
+ window: window.document.getElementById("content").contentWindow,
+ contentScript: 'new ' + function WorkerScope() {
+ let id = setTimeout(function () {
+ self.postMessage("timeout");
+ }, 100);
+ unsafeWindow.eval("clearTimeout("+id+");");
+ },
+ contentScriptWhen: 'ready',
+ onMessage: function(msg) {
+ test.assert(msg,
+ "content didn't managed to cancel our setTimeout");
+ test.done();
+ }
+ });
+
+ }, true);
+
+}
+
+exports['test:setTimeout are unregistered on content unload'] = function(test) {
+ let contentURL = 'data:text/html,foo';
+ let window = makeWindow(contentURL);
+ test.waitUntilDone();
+
+ window.addEventListener("load", function onload() {
+ window.removeEventListener("load", onload, true);
+
+ let iframe = window.document.getElementById("content");
+ let originalDocument = iframe.contentDocument;
+ let worker = Worker({
+ window: iframe.contentWindow,
+ contentScript: 'new ' + function WorkerScope() {
+ document.title = "ok";
+ let i = 0;
+ setInterval(function () {
+ document.title = i++;
+ }, 10);
+ },
+ contentScriptWhen: 'ready'
+ });
+
+ // Change location so that content script is destroyed,
+ // and all setTimeout/setInterval should be unregistered.
+ // Wait some cycles in order to execute some intervals.
+ timer.setTimeout(function () {
+ // Bug 689621: Wait for the new document load so that we are sure that
+ // previous document cancelled its intervals
+ iframe.addEventListener("load", function onload() {
+ iframe.removeEventListener("load", onload, true);
+ let titleAfterLoad = originalDocument.title;
+ // Wait additional cycles to verify that intervals are really cancelled
+ timer.setTimeout(function () {
+ test.assertEqual(iframe.contentDocument.title, "final",
+ "New document has not been modified");
+ test.assertEqual(originalDocument.title, titleAfterLoad,
+ "Nor previous one");
+ test.done();
+ }, 100);
+ }, true);
+ iframe.setAttribute("src", "data:text/html,<title>final</title>");
+ }, 100);
+
+ }, true);
+
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-cortex.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-cortex.js
new file mode 100644
index 0000000..9f13f0e
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-cortex.js
@@ -0,0 +1,122 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// vim:set ts=2 sw=2 sts=2
+
+"use strict";
+
+var Cortex = require("cortex").Cortex;
+
+exports["test property changes propagate"] = function (assert) {
+ var source = {
+ _foo: "secret",
+ get foo() {
+ return this._foo;
+ },
+ set foo(value) {
+ this._foo = value;
+ },
+ get getOnly() {
+ return this._foo;
+ },
+ set setOnly(value) {
+ this._setOnly = value;
+ },
+ bar: "public",
+ method: function method(a, b) {
+ return this._foo + a + b
+ }
+ };
+ var fixture = Cortex(source);
+
+ assert.ok(!('_foo' in fixture),
+ "properties that start with `_` are omitted");
+ assert.equal(fixture.foo, "secret", "get accessor alias works");
+ fixture.foo = "new secret";
+ assert.equal(fixture.foo, "new secret", "set accessor alias works");
+ assert.equal(source.foo, "new secret", "accessor delegates to the source");
+ assert.equal(fixture.bar, "public", "data property alias works");
+ fixture.bar = "bar";
+ assert.equal(source.bar, "bar", "data property change propagates");
+ source.bar = "foo"
+ assert.equal(fixture.bar, "foo", "data property change probagets back");
+ assert.equal(fixture.method("a", "b"), "new secretab",
+ "public methods are callable");
+ assert.equal(fixture.method.call({ _foo: "test" }, " a,", "b"),
+ "new secret a,b",
+ "`this` pseudo-variable can not be passed through call.");
+ assert.equal(fixture.method.apply({ _foo: "test" }, [" a,", "b"]),
+ "new secret a,b",
+ "`this` pseudo-variable can not be passed through apply.");
+ assert.equal(fixture.getOnly, source._foo,
+ "getter returned property of wrapped object");
+ fixture.setOnly = 'bar'
+ assert.equal(source._setOnly, 'bar', "setter modified wrapped object")
+};
+
+
+exports["test immunity of inheritance"] = function(assert) {
+ function Type() {}
+ Type.prototype = {
+ constructor: Type,
+ _bar: 2,
+ bar: 3,
+ get_Foo: function getFoo() {
+ return this._foo;
+ }
+ }
+ var source = Object.create(Type.prototype, {
+ _foo: { value: 'secret' },
+ getBar: { value: function get_Bar() {
+ return this.bar
+ }},
+ get_Bar: { value: function getBar() {
+ return this._bar
+ }}
+ });
+
+ var fixture = Cortex(source);
+
+ assert.ok(Cortex({}, null, Type.prototype) instanceof Type,
+ "if custom prototype is providede cortex will inherit from it");
+ assert.ok(fixture instanceof Type,
+ "if no prototype is given cortex inherits from object's prototype");
+
+ source.bar += 1;
+ assert.notEqual(fixture.bar, source.bar,
+ "chages of properties don't propagate to non-aliases");
+ assert.equal(fixture.getBar(), source.bar,
+ "methods accessing public properties are bound to the source");
+
+ fixture._bar += 1;
+ assert.notEqual(fixture._bar, source._bar,
+ "changes of non aliased properties don't propagate");
+ assert.equal(fixture.get_Bar(), source._bar,
+ "methods accessing privates are bound to the source");
+ assert.notEqual(fixture.get_Foo(), source._foo,
+ "prototoype methods are not bound to the source");
+}
+
+exports["test customized public properties"] = function(assert) {
+ var source = {
+ _a: 'a',
+ b: 'b',
+ get: function get(name) {
+ return this[name];
+ }
+ };
+
+ var fixture = Cortex(source, ['_a', 'get']);
+ fixture._a += "#change";
+
+
+ assert.ok(!("b" in fixture), "non-public own property is not defined");
+ assert.equal(fixture.get("b"), source.b,
+ "public methods preserve access to the private properties");
+ assert.equal(fixture._a, source._a,
+ "custom public property changes propagate");
+}
+
+//if (require.main == module)
+ require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-dom.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-dom.js
new file mode 100644
index 0000000..52ab1c3
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-dom.js
@@ -0,0 +1,88 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const events = require("dom/events");
+const { activeBrowserWindow: { document } } = require("window-utils");
+const window = document.window;
+
+exports["test on / emit"] = function (assert, done) {
+ let element = document.createElement("div");
+ events.on(element, "click", function listener(event) {
+ assert.equal(event.target, element, "event has correct target");
+ events.removeListener(element, "click", listener);
+ done();
+ });
+
+ events.emit(element, "click", {
+ category: "MouseEvents",
+ settings: [
+ true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null
+ ]
+ });
+};
+
+exports["test remove"] = function (assert, done) {
+ let element = document.createElement("span");
+ let l1 = 0;
+ let l2 = 0;
+ let options = {
+ category: "MouseEvents",
+ settings: [
+ true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null
+ ]
+ };
+
+ events.on(element, "click", function listener1(event) {
+ l1 ++;
+ assert.equal(event.target, element, "event has correct target");
+ events.removeListener(element, "click", listener1);
+ });
+
+ events.on(element, "click", function listener2(event) {
+ l2 ++;
+ if (l1 < l2) {
+ assert.equal(l1, 1, "firs listener was called and then romeved");
+ events.removeListener(element, "click", listener2);
+ done();
+ }
+ events.emit(element, "click", options);
+ });
+
+ events.emit(element, "click", options);
+};
+
+exports["test once"] = function (assert, done) {
+ let element = document.createElement("h1");
+ let l1 = 0;
+ let l2 = 0;
+ let options = {
+ category: "MouseEvents",
+ settings: [
+ true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null
+ ]
+ };
+
+
+ events.once(element, "click", function listener(event) {
+ assert.equal(event.target, element, "event target is a correct element");
+ l1 ++;
+ });
+
+ events.on(element, "click", function listener(event) {
+ l2 ++;
+ if (l2 > 3) {
+ events.removeListener(element, "click", listener);
+ assert.equal(event.target, element, "event has correct target");
+ assert.equal(l1, 1, "once was called only once");
+ done();
+ }
+ events.emit(element, "click", options);
+ });
+
+ events.emit(element, "click", options);
+}
+
+require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-environment.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-environment.js
new file mode 100644
index 0000000..1d7e783
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-environment.js
@@ -0,0 +1,50 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+const { env } = require('api-utils/environment');
+const { Cc, Ci } = require('chrome');
+const { get, set, exists } = Cc['@mozilla.org/process/environment;1'].
+ getService(Ci.nsIEnvironment);
+
+exports['test exists'] = function(assert) {
+ assert.equal('PATH' in env, exists('PATH'),
+ 'PATH environment variable is defined');
+ assert.equal('FOO1' in env, exists('FOO1'),
+ 'FOO1 environment variable is not defined');
+ set('FOO1', 'foo');
+ assert.equal('FOO1' in env, true,
+ 'FOO1 environment variable was set');
+ set('FOO1', null);
+ assert.equal('FOO1' in env, false,
+ 'FOO1 environment variable was unset');
+};
+
+exports['test get'] = function(assert) {
+ assert.equal(env.PATH, get('PATH'), 'PATH env variable matches');
+ assert.equal(env.BAR2, undefined, 'BAR2 env variable is not defined');
+ set('BAR2', 'bar');
+ assert.equal(env.BAR2, 'bar', 'BAR2 env variable was set');
+ set('BAR2', null);
+ assert.equal(env.BAR2, undefined, 'BAR2 env variable was unset');
+};
+
+exports['test set'] = function(assert) {
+ assert.equal(get('BAZ3'), '', 'BAZ3 env variable is not set');
+ assert.equal(env.BAZ3, undefined, 'BAZ3 is not set');
+ env.BAZ3 = 'baz';
+ assert.equal(env.BAZ3, get('BAZ3'), 'BAZ3 env variable is set');
+ assert.equal(get('BAZ3'), 'baz', 'BAZ3 env variable was set to "baz"');
+};
+
+exports['test unset'] = function(assert) {
+ env.BLA4 = 'bla';
+ assert.equal(env.BLA4, 'bla', 'BLA4 env varibale is set');
+ delete env.BLA4;
+ assert.equal(env.BLA4, undefined, 'BLA4 env variable is unset');
+ assert.equal('BLA4' in env, false, 'BLA4 env variable no longer exists' );
+};
+
+require('test').run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-errors.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-errors.js
new file mode 100644
index 0000000..64bb6c9
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-errors.js
@@ -0,0 +1,70 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var errors = require("errors");
+
+exports.testCatchAndLog = function(test) {
+ var caught = [];
+ function dummyLog(e) { caught.push(e); }
+
+ var wrapped = errors.catchAndLog(function(x) {
+ throw Error("blah" + x + this);
+ },
+ "boop",
+ dummyLog);
+ test.assertEqual(wrapped.call("hi", 1), "boop",
+ "exceptions should be trapped, def. resp. returned");
+ test.assertEqual(caught.length, 1,
+ "logging function should be called");
+ test.assertEqual(caught[0].message, "blah1hi",
+ "args and this should be passed to wrapped func");
+};
+
+exports.testCatchAndLogProps = function(test) {
+ var caught = [];
+ function dummyLog(e) { caught.push(e); }
+
+ var thing = {
+ foo: function(x) { throw Error("nowai" + x); },
+ bar: function() { throw Error("blah"); },
+ baz: function() { throw Error("fnarg"); }
+ };
+
+ errors.catchAndLogProps(thing, "foo", "ugh", dummyLog);
+
+ test.assertEqual(thing.foo(1), "ugh",
+ "props should be wrapped");
+ test.assertEqual(caught.length, 1,
+ "logging function should be called");
+ test.assertEqual(caught[0].message, "nowai1",
+ "args should be passed to wrapped func");
+ test.assertRaises(function() { thing.bar(); },
+ "blah",
+ "non-wrapped props should be wrapped");
+
+ errors.catchAndLogProps(thing, ["bar", "baz"], "err", dummyLog);
+ test.assert((thing.bar() == thing.baz()) &&
+ (thing.bar() == "err"),
+ "multiple props should be wrapped if array passed in");
+};
+
+exports.testCatchAndReturn = function(test) {
+ var wrapped = errors.catchAndReturn(function(x) {
+ if (x == 1)
+ return "one";
+ if (x == 2)
+ throw new Error("two");
+ return this + x;
+ });
+
+ test.assertEqual(wrapped(1).returnValue, "one",
+ "arg should be passed; return value should be returned");
+ test.assert(wrapped(2).exception, "exception should be returned");
+ test.assertEqual(wrapped(2).exception.message, "two", "message is correct");
+ test.assert(wrapped(2).exception.fileName.indexOf("test-errors.js") != -1,
+ "filename is present");
+ test.assert(wrapped(2).exception.stack, "stack is available");
+ test.assertEqual(wrapped.call("hi", 3).returnValue, "hi3",
+ "`this` should be set correctly");
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-event-core.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-event-core.js
new file mode 100644
index 0000000..4b664ff
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-event-core.js
@@ -0,0 +1,217 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+const { on, once, off, emit, count, amass } = require('api-utils/event/core');
+const { Loader } = require('./helpers');
+
+exports['test add a listener'] = function(assert) {
+ let events = [ { name: 'event#1' }, 'event#2' ];
+ let target = { name: 'target' };
+
+ on(target, 'message', function(message) {
+ assert.equal(this, target, 'this is a target object');
+ assert.equal(message, events.shift(), 'message is emitted event');
+ });
+ emit(target, 'message', events[0]);
+ emit(target, 'message', events[0]);
+};
+
+exports['test that listener is unique per type'] = function(assert) {
+ let actual = []
+ let target = {}
+ function listener() { actual.push(1) }
+ on(target, 'message', listener);
+ on(target, 'message', listener);
+ on(target, 'message', listener);
+ on(target, 'foo', listener);
+ on(target, 'foo', listener);
+
+ emit(target, 'message');
+ assert.deepEqual([ 1 ], actual, 'only one message listener added');
+ emit(target, 'foo');
+ assert.deepEqual([ 1, 1 ], actual, 'same listener added for other event');
+};
+
+exports['test event type matters'] = function(assert) {
+ let target = { name: 'target' }
+ on(target, 'message', function() {
+ assert.fail('no event is expected');
+ });
+ on(target, 'done', function() {
+ assert.pass('event is emitted');
+ });
+ emit(target, 'foo')
+ emit(target, 'done');
+};
+
+exports['test all arguments are pasesd'] = function(assert) {
+ let foo = { name: 'foo' }, bar = 'bar';
+ let target = { name: 'target' };
+ on(target, 'message', function(a, b) {
+ assert.equal(a, foo, 'first argument passed');
+ assert.equal(b, bar, 'second argument passed');
+ });
+ emit(target, 'message', foo, bar);
+};
+
+exports['test no side-effects in emit'] = function(assert) {
+ let target = { name: 'target' };
+ on(target, 'message', function() {
+ assert.pass('first listener is called');
+ on(target, 'message', function() {
+ assert.fail('second listener is called');
+ });
+ });
+ emit(target, 'message');
+};
+
+exports['test order of propagation'] = function(assert) {
+ let actual = [];
+ let target = { name: 'target' };
+ on(target, 'message', function() { actual.push(1); });
+ on(target, 'message', function() { actual.push(2); });
+ on(target, 'message', function() { actual.push(3); });
+ emit(target, 'message');
+ assert.deepEqual([ 1, 2, 3 ], actual, 'called in order they were added');
+};
+
+exports['test remove a listener'] = function(assert) {
+ let target = { name: 'target' };
+ let actual = [];
+ on(target, 'message', function listener() {
+ actual.push(1);
+ on(target, 'message', function() {
+ off(target, 'message', listener);
+ actual.push(2);
+ })
+ });
+
+ emit(target, 'message');
+ assert.deepEqual([ 1 ], actual, 'first listener called');
+ emit(target, 'message');
+ assert.deepEqual([ 1, 1, 2 ], actual, 'second listener called');
+
+ emit(target, 'message');
+ assert.deepEqual([ 1, 1, 2, 2, 2 ], actual, 'first listener removed');
+};
+
+exports['test remove all listeners for type'] = function(assert) {
+ let actual = [];
+ let target = { name: 'target' }
+ on(target, 'message', function() { actual.push(1); });
+ on(target, 'message', function() { actual.push(2); });
+ on(target, 'message', function() { actual.push(3); });
+ on(target, 'bar', function() { actual.push('b') });
+ off(target, 'message');
+
+ emit(target, 'message');
+ emit(target, 'bar');
+
+ assert.deepEqual([ 'b' ], actual, 'all message listeners were removed');
+};
+
+exports['test remove all listeners'] = function(assert) {
+ let actual = [];
+ let target = { name: 'target' }
+ on(target, 'message', function() { actual.push(1); });
+ on(target, 'message', function() { actual.push(2); });
+ on(target, 'message', function() { actual.push(3); });
+ on(target, 'bar', function() { actual.push('b') });
+ off(target);
+
+ emit(target, 'message');
+ emit(target, 'bar');
+
+ assert.deepEqual([], actual, 'all listeners events were removed');
+};
+
+exports['test falsy arguments are fine'] = function(assert) {
+ let type, listener, actual = [];
+ let target = { name: 'target' }
+ on(target, 'bar', function() { actual.push(0) });
+
+ off(target, 'bar', listener);
+ emit(target, 'bar');
+ assert.deepEqual([ 0 ], actual, '3rd bad ard will keep listeners');
+
+ off(target, type);
+ emit(target, 'bar');
+ assert.deepEqual([ 0, 0 ], actual, '2nd bad arg will keep listener');
+
+ off(target, type, listener);
+ emit(target, 'bar');
+ assert.deepEqual([ 0, 0, 0 ], actual, '2nd&3rd bad args will keep listener');
+};
+
+exports['test error handling'] = function(assert) {
+ let target = Object.create(null);
+ let error = Error('boom!');
+
+ on(target, 'message', function() { throw error; })
+ on(target, 'error', function(boom) {
+ assert.equal(boom, error, 'thrown exception causes error event');
+ });
+ emit(target, 'message');
+};
+
+exports['test unhandled errors'] = function(assert) {
+ let exceptions = [];
+ let loader = Loader(module);
+ let { emit, on } = loader.require('api-utils/event/core');
+ Object.defineProperties(loader.sandbox('api-utils/event/core'), {
+ console: { value: {
+ exception: function(e) {
+ exceptions.push(e)
+ }
+ }}
+ });
+ let target = {};
+ let boom = Error('Boom!');
+ let drax = Error('Draax!!');
+
+ on(target, 'message', function() { throw boom; });
+
+ emit(target, 'message');
+ assert.ok(~String(exceptions[0]).indexOf('Boom!'),
+ 'unhandled exception is logged');
+
+ on(target, 'error', function() { throw drax; });
+ emit(target, 'message');
+ assert.ok(~String(exceptions[1]).indexOf('Draax!'),
+ 'error in error handler is logged');
+};
+
+exports['test count'] = function(assert) {
+ let target = {};
+
+ assert.equal(count(target, 'foo'), 0, 'no listeners for "foo" events');
+ on(target, 'foo', function() {});
+ assert.equal(count(target, 'foo'), 1, 'listener registered');
+ on(target, 'foo', function() {}, 2, 'another listener registered');
+ off(target)
+ assert.equal(count(target, 'foo'), 0, 'listeners unregistered');
+};
+
+exports['test emit.lazy'] = function(assert) {
+ let target = {}, boom = Error('boom!'), errors = [], actual = []
+
+ on(target, 'error', function error(e) errors.push(e))
+
+ on(target, 'a', function() 1);
+ on(target, 'a', function() {});
+ on(target, 'a', function() 2);
+ on(target, 'a', function() { throw boom });
+ on(target, 'a', function() 3);
+
+ for each (let value in emit.lazy(target, 'a'))
+ actual.push(value);
+
+ assert.deepEqual(actual, [ 1, undefined, 2, 3 ],
+ 'all results were collected');
+ assert.deepEqual(errors, [ boom ], 'errors reporetd');
+};
+
+require('test').run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-event-target.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-event-target.js
new file mode 100644
index 0000000..b8960e5
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-event-target.js
@@ -0,0 +1,167 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+const { emit } = require('api-utils/event/core');
+const { EventTarget } = require('api-utils/event/target');
+const { Loader } = require('./helpers');
+
+exports['test add a listener'] = function(assert) {
+ let events = [ { name: 'event#1' }, 'event#2' ];
+ let target = EventTarget.new();
+
+ target.on('message', function(message) {
+ assert.equal(this, target, 'this is a target object');
+ assert.equal(message, events.shift(), 'message is emitted event');
+ });
+
+ emit(target, 'message', events[0]);
+ emit(target, 'message', events[0]);
+};
+
+exports['test pass in listeners'] = function(assert) {
+ let actual = [ ];
+ let target = EventTarget.new({
+ onMessage: function onMessage(message) {
+ assert.equal(this, target, 'this is an event target');
+ actual.push(1);
+ },
+ onFoo: null,
+ onbla: function() {
+ assert.fail('`onbla` is not supposed to be called');
+ }
+ });
+ target.on('message', function(message) {
+ assert.equal(this, target, 'this is an event target');
+ actual.push(2);
+ });
+
+ emit(target, 'message');
+ emit(target, 'missing');
+
+ assert.deepEqual([ 1, 2 ], actual, 'all listeners trigerred in right order');
+};
+
+exports['test that listener is unique per type'] = function(assert) {
+ let actual = []
+ let target = EventTarget.new();
+ function listener() { actual.push(1) }
+ target.on('message', listener);
+ target.on('message', listener);
+ target.on('message', listener);
+ target.on('foo', listener);
+ target.on('foo', listener);
+
+ emit(target, 'message');
+ assert.deepEqual([ 1 ], actual, 'only one message listener added');
+ emit(target, 'foo');
+ assert.deepEqual([ 1, 1 ], actual, 'same listener added for other event');
+};
+
+exports['test event type matters'] = function(assert) {
+ let target = EventTarget.new();
+ target.on('message', function() {
+ assert.fail('no event is expected');
+ });
+ target.on('done', function() {
+ assert.pass('event is emitted');
+ });
+
+ emit(target, 'foo');
+ emit(target, 'done');
+};
+
+exports['test all arguments are pasesd'] = function(assert) {
+ let foo = { name: 'foo' }, bar = 'bar';
+ let target = EventTarget.new();
+ target.on('message', function(a, b) {
+ assert.equal(a, foo, 'first argument passed');
+ assert.equal(b, bar, 'second argument passed');
+ });
+ emit(target, 'message', foo, bar);
+};
+
+exports['test no side-effects in emit'] = function(assert) {
+ let target = EventTarget.new();
+ target.on('message', function() {
+ assert.pass('first listener is called');
+ target.on('message', function() {
+ assert.fail('second listener is called');
+ });
+ });
+ emit(target, 'message');
+};
+
+exports['test order of propagation'] = function(assert) {
+ let actual = [];
+ let target = EventTarget.new();
+ target.on('message', function() { actual.push(1); });
+ target.on('message', function() { actual.push(2); });
+ target.on('message', function() { actual.push(3); });
+ emit(target, 'message');
+ assert.deepEqual([ 1, 2, 3 ], actual, 'called in order they were added');
+};
+
+exports['test remove a listener'] = function(assert) {
+ let target = EventTarget.new();
+ let actual = [];
+ target.on('message', function listener() {
+ actual.push(1);
+ target.on('message', function() {
+ target.removeListener('message', listener);
+ actual.push(2);
+ })
+ });
+
+ target.removeListener('message'); // must do nothing.
+ emit(target, 'message');
+ assert.deepEqual([ 1 ], actual, 'first listener called');
+ emit(target, 'message');
+ assert.deepEqual([ 1, 1, 2 ], actual, 'second listener called');
+ emit(target, 'message');
+ assert.deepEqual([ 1, 1, 2, 2, 2 ], actual, 'first listener removed');
+};
+
+exports['test error handling'] = function(assert) {
+ let target = EventTarget.new();
+ let error = Error('boom!');
+
+ target.on('message', function() { throw error; })
+ target.on('error', function(boom) {
+ assert.equal(boom, error, 'thrown exception causes error event');
+ });
+ emit(target, 'message');
+};
+
+exports['test unhandled errors'] = function(assert) {
+ let exceptions = [];
+ let loader = Loader(module);
+ let { emit } = loader.require('api-utils/event/core');
+ let { EventTarget } = loader.require('api-utils/event/target');
+ Object.defineProperties(loader.sandbox('api-utils/event/core'), {
+ console: { value: {
+ exception: function(e) {
+ exceptions.push(e);
+ }
+ }}
+ });
+ let target = EventTarget.new();
+ let boom = Error('Boom!');
+ let drax = Error('Draax!!');
+
+ target.on('message', function() { throw boom; });
+
+ emit(target, 'message');
+ assert.ok(~String(exceptions[0]).indexOf('Boom!'),
+ 'unhandled exception is logged');
+
+ target.on('error', function() { throw drax; });
+ emit(target, 'message');
+ assert.ok(~String(exceptions[1]).indexOf('Draax!'),
+ 'error in error handler is logged');
+};
+
+require('test').run(exports);
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-events.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-events.js
new file mode 100644
index 0000000..3fe6f03
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-events.js
@@ -0,0 +1,267 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+// Exposing private methods as public in order to test
+const EventEmitter = require('events').EventEmitter.compose({
+ listeners: function(type) this._listeners(type),
+ emit: function() this._emit.apply(this, arguments),
+ emitOnObject: function() this._emitOnObject.apply(this, arguments),
+ removeAllListeners: function(type) this._removeAllListeners(type)
+});
+
+exports['test:add listeners'] = function(test) {
+ let e = new EventEmitter();
+
+ let events_new_listener_emited = [];
+ let times_hello_emited = 0;
+
+ e.on("newListener", function (event, listener) {
+ events_new_listener_emited.push(event)
+ })
+
+ e.on("hello", function (a, b) {
+ times_hello_emited += 1
+ test.assertEqual("a", a)
+ test.assertEqual("b", b)
+ test.assertEqual(this, e, '`this` pseudo-variable is bound to instance');
+ })
+
+ e.emit("hello", "a", "b")
+};
+
+exports['test:removeListener'] = function(test) {
+ let count = 0;
+
+ function listener1 () {
+ count++;
+ }
+ function listener2 () {
+ count++;
+ }
+
+ // test adding and removing listener
+ let e1 = new EventEmitter();
+ test.assertEqual(0, e1.listeners('hello').length);
+ e1.on("hello", listener1);
+ test.assertEqual(1, e1.listeners('hello').length);
+ test.assertEqual(listener1, e1.listeners('hello')[0]);
+ e1.removeListener("hello", listener1);
+ test.assertEqual(0, e1.listeners('hello').length);
+ e1.emit("hello", "");
+ test.assertEqual(0, count);
+
+ // test adding one listener and removing another which was not added
+ let e2 = new EventEmitter();
+ test.assertEqual(0, e2.listeners('hello').length);
+ e2.on("hello", listener1);
+ test.assertEqual(1, e2.listeners('hello').length);
+ e2.removeListener("hello", listener2);
+ test.assertEqual(1, e2.listeners('hello').length);
+ test.assertEqual(listener1, e2.listeners('hello')[0]);
+ e2.emit("hello", "");
+ test.assertEqual(1, count);
+
+ // test adding 2 listeners, and removing one
+ let e3 = new EventEmitter();
+ test.assertEqual(0, e3.listeners('hello').length);
+ e3.on("hello", listener1);
+ test.assertEqual(1, e3.listeners('hello').length);
+ e3.on("hello", listener2);
+ test.assertEqual(2, e3.listeners('hello').length);
+ e3.removeListener("hello", listener1);
+ test.assertEqual(1, e3.listeners('hello').length);
+ test.assertEqual(listener2, e3.listeners('hello')[0]);
+ e3.emit("hello", "");
+ test.assertEqual(2, count);
+};
+
+exports['test:removeAllListeners'] = function(test) {
+ let count = 0;
+
+ function listener1 () {
+ count++;
+ }
+ function listener2 () {
+ count++;
+ }
+
+ // test adding a listener and removing all of that type
+ let e1 = new EventEmitter();
+ e1.on("hello", listener1);
+ test.assertEqual(1, e1.listeners('hello').length);
+ e1.removeAllListeners("hello");
+ test.assertEqual(0, e1.listeners('hello').length);
+ e1.emit("hello", "");
+ test.assertEqual(0, count);
+
+ // test adding a listener and removing all of another type
+ let e2 = new EventEmitter();
+ e2.on("hello", listener1);
+ test.assertEqual(1, e2.listeners('hello').length);
+ e2.removeAllListeners('goodbye');
+ test.assertEqual(1, e2.listeners('hello').length);
+ e2.emit("hello", "");
+ test.assertEqual(1, count);
+
+ // test adding 1+ listeners and removing all of that type
+ let e3 = new EventEmitter();
+ e3.on("hello", listener1);
+ test.assertEqual(1, e3.listeners('hello').length);
+ e3.on("hello", listener2);
+ test.assertEqual(2, e3.listeners('hello').length);
+ e3.removeAllListeners("hello");
+ test.assertEqual(0, e3.listeners('hello').length);
+ e3.emit("hello", "");
+ test.assertEqual(1, count);
+
+ // test adding 2 listeners for 2 types and removing all listeners
+ let e4 = new EventEmitter();
+ e4.on("hello", listener1);
+ test.assertEqual(1, e4.listeners('hello').length);
+ e4.on('goodbye', listener2);
+ test.assertEqual(1, e4.listeners('goodbye').length);
+ e4.emit("goodbye", "");
+ e4.removeAllListeners();
+ test.assertEqual(0, e4.listeners('hello').length);
+ test.assertEqual(0, e4.listeners('goodbye').length);
+ e4.emit("hello", "");
+ e4.emit("goodbye", "");
+ test.assertEqual(2, count);
+};
+
+exports['test: modify in emit'] = function(test) {
+ let callbacks_called = [ ];
+ let e = new EventEmitter();
+
+ function callback1() {
+ callbacks_called.push("callback1");
+ e.on("foo", callback2);
+ e.on("foo", callback3);
+ e.removeListener("foo", callback1);
+ }
+ function callback2() {
+ callbacks_called.push("callback2");
+ e.removeListener("foo", callback2);
+ }
+ function callback3() {
+ callbacks_called.push("callback3");
+ e.removeListener("foo", callback3);
+ }
+
+ e.on("foo", callback1);
+ test.assertEqual(1, e.listeners("foo").length);
+
+ e.emit("foo");
+ test.assertEqual(2, e.listeners("foo").length);
+ test.assertEqual(1, callbacks_called.length);
+ test.assertEqual('callback1', callbacks_called[0]);
+
+ e.emit("foo");
+ test.assertEqual(0, e.listeners("foo").length);
+ test.assertEqual(3, callbacks_called.length);
+ test.assertEqual('callback1', callbacks_called[0]);
+ test.assertEqual('callback2', callbacks_called[1]);
+ test.assertEqual('callback3', callbacks_called[2]);
+
+ e.emit("foo");
+ test.assertEqual(0, e.listeners("foo").length);
+ test.assertEqual(3, callbacks_called.length);
+ test.assertEqual('callback1', callbacks_called[0]);
+ test.assertEqual('callback2', callbacks_called[1]);
+ test.assertEqual('callback3', callbacks_called[2]);
+
+ e.on("foo", callback1);
+ e.on("foo", callback2);
+ test.assertEqual(2, e.listeners("foo").length);
+ e.removeAllListeners("foo");
+ test.assertEqual(0, e.listeners("foo").length);
+
+ // Verify that removing callbacks while in emit allows emits to propagate to
+ // all listeners
+ callbacks_called = [ ];
+
+ e.on("foo", callback2);
+ e.on("foo", callback3);
+ test.assertEqual(2, e.listeners("foo").length);
+ e.emit("foo");
+ test.assertEqual(2, callbacks_called.length);
+ test.assertEqual('callback2', callbacks_called[0]);
+ test.assertEqual('callback3', callbacks_called[1]);
+ test.assertEqual(0, e.listeners("foo").length);
+};
+
+exports['test:adding same listener'] = function(test) {
+ function foo() {}
+ let e = new EventEmitter();
+ e.on("foo", foo);
+ e.on("foo", foo);
+ test.assertEqual(
+ 1,
+ e.listeners("foo").length,
+ "listener reregistration is ignored"
+ );
+}
+
+exports['test:errors are reported if listener throws'] = function(test) {
+ let e = new EventEmitter(),
+ reported = false;
+ e.on('error', function(e) reported = true)
+ e.on('boom', function() { throw new Error('Boom!') });
+ e.emit('boom', 3);
+ test.assert(reported, 'error should be reported through event');
+};
+
+exports['test:emitOnObject'] = function(test) {
+ let e = new EventEmitter();
+
+ e.on("foo", function() {
+ test.assertEqual(this, e, "`this` should be emitter");
+ });
+ e.emitOnObject(e, "foo");
+
+ e.on("bar", function() {
+ test.assertEqual(this, obj, "`this` should be other object");
+ });
+ let obj = {};
+ e.emitOnObject(obj, "bar");
+};
+
+exports['test:once'] = function(test) {
+ let e = new EventEmitter();
+ let called = false;
+
+ e.once('foo', function(value) {
+ test.assert(!called, "listener called only once");
+ test.assertEqual(value, "bar", "correct argument was passed");
+ });
+
+ e.emit('foo', 'bar');
+ e.emit('foo', 'baz');
+};
+
+exports["test:removing once"] = function(test) {
+ let e = require("events").EventEmitterTrait.create();
+ e.once("foo", function() { test.pass("listener was called"); });
+ e.once("error", function() { test.fail("error event was emitted"); });
+ e._emit("foo", "bug-656684");
+};
+
+// Bug 726967: Ensure that `emit` doesn't do an infinite loop when `error`
+// listener throws an exception
+exports['test:emitLoop'] = function(test) {
+ let e = new EventEmitter();
+
+ e.on("foo", function() {
+ throw new Error("foo");
+ });
+
+ e.on("error", function() {
+ throw new Error("error");
+ });
+ e.emit("foo");
+
+ test.pass("emit didn't looped");
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-file.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-file.js
new file mode 100644
index 0000000..de89db8
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-file.js
@@ -0,0 +1,273 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { pathFor } = require('api-utils/system');
+const file = require("api-utils/file");
+const url = require("api-utils/url");
+
+const byteStreams = require("api-utils/byte-streams");
+const textStreams = require("api-utils/text-streams");
+
+const ERRORS = {
+ FILE_NOT_FOUND: /^path does not exist: .+$/,
+ NOT_A_DIRECTORY: /^path is not a directory: .+$/,
+ NOT_A_FILE: /^path is not a file: .+$/,
+};
+
+// Use profile directory to list / read / write files.
+const profilePath = pathFor('ProfD');
+const fileNameInProfile = 'compatibility.ini';
+const dirNameInProfile = 'extensions';
+const filePathInProfile = file.join(profilePath, fileNameInProfile);
+const dirPathInProfile = file.join(profilePath, dirNameInProfile);
+
+exports.testDirName = function(test) {
+ test.assertEqual(file.dirname(dirPathInProfile), profilePath,
+ "file.dirname() of dir should return parent dir");
+
+ test.assertEqual(file.dirname(filePathInProfile), profilePath,
+ "file.dirname() of file should return its dir");
+
+ let dir = profilePath;
+ while (dir)
+ dir = file.dirname(dir);
+
+ test.assertEqual(dir, "",
+ "dirname should return empty string when dir has no parent");
+};
+
+exports.testBasename = function(test) {
+ // Get the top-most path -- the path with no basename. E.g., on Unix-like
+ // systems this will be /. We'll use it below to build up some test paths.
+ // We have to go to this trouble because file.join() needs a legal path as a
+ // base case; join("foo", "bar") doesn't work unfortunately.
+ let topPath = profilePath;
+ let parentPath = file.dirname(topPath);
+ while (parentPath) {
+ topPath = parentPath;
+ parentPath = file.dirname(topPath);
+ }
+
+ let path = topPath;
+ test.assertEqual(file.basename(path), "",
+ "basename should work on paths with no components");
+
+ path = file.join(path, "foo");
+ test.assertEqual(file.basename(path), "foo",
+ "basename should work on paths with a single component");
+
+ path = file.join(path, "bar");
+ test.assertEqual(file.basename(path), "bar",
+ "basename should work on paths with multiple components");
+};
+
+exports.testList = function(test) {
+ let list = file.list(profilePath);
+ let found = [ true for each (name in list)
+ if (name === fileNameInProfile) ];
+
+ if (found.length > 1)
+ test.fail("a dir can't contain two files of the same name!");
+ test.assertEqual(found[0], true, "file.list() should work");
+
+ test.assertRaises(function() {
+ file.list(filePathInProfile);
+ }, ERRORS.NOT_A_DIRECTORY, "file.list() on non-dir should raise error");
+
+ test.assertRaises(function() {
+ file.list(file.join(dirPathInProfile, "does-not-exist"));
+ }, ERRORS.FILE_NOT_FOUND, "file.list() on nonexistent should raise error");
+};
+
+exports.testRead = function(test) {
+ let contents = file.read(filePathInProfile);
+ test.assertMatches(contents, /Compatibility/,
+ "file.read() should work");
+
+ test.assertRaises(function() {
+ file.read(file.join(dirPathInProfile, "does-not-exists"));
+ }, ERRORS.FILE_NOT_FOUND, "file.read() on nonexistent file should throw");
+
+ test.assertRaises(function() {
+ file.read(dirPathInProfile);
+ }, ERRORS.NOT_A_FILE, "file.read() on dir should throw");
+};
+
+exports.testJoin = function(test) {
+ let baseDir = file.dirname(filePathInProfile);
+
+ test.assertEqual(file.join(baseDir, fileNameInProfile),
+ filePathInProfile, "file.join() should work");
+};
+
+exports.testOpenNonexistentForRead = function (test) {
+ var filename = file.join(profilePath, 'does-not-exists');
+ test.assertRaises(function() {
+ file.open(filename);
+ }, ERRORS.FILE_NOT_FOUND, "file.open() on nonexistent file should throw");
+
+ test.assertRaises(function() {
+ file.open(filename, "r");
+ }, ERRORS.FILE_NOT_FOUND, "file.open('r') on nonexistent file should throw");
+
+ test.assertRaises(function() {
+ file.open(filename, "zz");
+ }, ERRORS.FILE_NOT_FOUND, "file.open('zz') on nonexistent file should throw");
+};
+
+exports.testOpenNonexistentForWrite = function (test) {
+ let filename = file.join(profilePath, 'open.txt');
+
+ let stream = file.open(filename, "w");
+ stream.close();
+
+ test.assert(file.exists(filename),
+ "file.exists() should return true after file.open('w')");
+ file.remove(filename);
+ test.assert(!file.exists(filename),
+ "file.exists() should return false after file.remove()");
+
+ stream = file.open(filename, "rw");
+ stream.close();
+
+ test.assert(file.exists(filename),
+ "file.exists() should return true after file.open('rw')");
+ file.remove(filename);
+ test.assert(!file.exists(filename),
+ "file.exists() should return false after file.remove()");
+};
+
+exports.testOpenDirectory = function (test) {
+ let dir = dirPathInProfile;
+ test.assertRaises(function() {
+ file.open(dir);
+ }, ERRORS.NOT_A_FILE, "file.open() on directory should throw");
+
+ test.assertRaises(function() {
+ file.open(dir, "w");
+ }, ERRORS.NOT_A_FILE, "file.open('w') on directory should throw");
+};
+
+exports.testOpenTypes = function (test) {
+ let filename = file.join(profilePath, 'open-types.txt');
+
+
+ // Do the opens first to create the data file.
+ var stream = file.open(filename, "w");
+ test.assert(stream instanceof textStreams.TextWriter,
+ "open(w) should return a TextWriter");
+ stream.close();
+
+ stream = file.open(filename, "wb");
+ test.assert(stream instanceof byteStreams.ByteWriter,
+ "open(wb) should return a ByteWriter");
+ stream.close();
+
+ stream = file.open(filename);
+ test.assert(stream instanceof textStreams.TextReader,
+ "open() should return a TextReader");
+ stream.close();
+
+ stream = file.open(filename, "r");
+ test.assert(stream instanceof textStreams.TextReader,
+ "open(r) should return a TextReader");
+ stream.close();
+
+ stream = file.open(filename, "b");
+ test.assert(stream instanceof byteStreams.ByteReader,
+ "open(b) should return a ByteReader");
+ stream.close();
+
+ stream = file.open(filename, "rb");
+ test.assert(stream instanceof byteStreams.ByteReader,
+ "open(rb) should return a ByteReader");
+ stream.close();
+
+ file.remove(filename);
+};
+
+exports.testMkpathRmdir = function (test) {
+ let basePath = profilePath;
+ let dirs = [];
+ for (let i = 0; i < 3; i++)
+ dirs.push("test-file-dir");
+
+ let paths = [];
+ for (let i = 0; i < dirs.length; i++) {
+ let args = [basePath].concat(dirs.slice(0, i + 1));
+ paths.unshift(file.join.apply(null, args));
+ }
+
+ for (let i = 0; i < paths.length; i++) {
+ test.assert(!file.exists(paths[i]),
+ "Sanity check: path should not exist: " + paths[i]);
+ }
+
+ file.mkpath(paths[0]);
+ test.assert(file.exists(paths[0]), "mkpath should create path: " + paths[0]);
+
+ for (let i = 0; i < paths.length; i++) {
+ file.rmdir(paths[i]);
+ test.assert(!file.exists(paths[i]),
+ "rmdir should remove path: " + paths[i]);
+ }
+};
+
+exports.testMkpathTwice = function (test) {
+ let dir = profilePath;
+ let path = file.join(dir, "test-file-dir");
+ test.assert(!file.exists(path),
+ "Sanity check: path should not exist: " + path);
+ file.mkpath(path);
+ test.assert(file.exists(path), "mkpath should create path: " + path);
+ file.mkpath(path);
+ test.assert(file.exists(path),
+ "After second mkpath, path should still exist: " + path);
+ file.rmdir(path);
+ test.assert(!file.exists(path), "rmdir should remove path: " + path);
+};
+
+exports.testMkpathExistingNondirectory = function (test) {
+ var fname = file.join(profilePath, 'conflict.txt');
+ file.open(fname, "w").close();
+ test.assert(file.exists(fname), "File should exist");
+ test.assertRaises(function() file.mkpath(fname),
+ /^The path already exists and is not a directory: .+$/,
+ "mkpath on file should raise error");
+ file.remove(fname);
+};
+
+exports.testRmdirNondirectory = function (test) {
+ var fname = file.join(profilePath, 'not-a-dir')
+ file.open(fname, "w").close();
+ test.assert(file.exists(fname), "File should exist");
+ test.assertRaises(function() {
+ file.rmdir(fname);
+ }, ERRORS.NOT_A_DIRECTORY, "rmdir on file should raise error");
+ file.remove(fname);
+ test.assert(!file.exists(fname), "File should not exist");
+ test.assertRaises(function () file.rmdir(fname),
+ ERRORS.FILE_NOT_FOUND,
+ "rmdir on non-existing file should raise error");
+};
+
+exports.testRmdirNonempty = function (test) {
+ let dir = profilePath;
+ let path = file.join(dir, "test-file-dir");
+ test.assert(!file.exists(path),
+ "Sanity check: path should not exist: " + path);
+ file.mkpath(path);
+ let filePath = file.join(path, "file");
+ file.open(filePath, "w").close();
+ test.assert(file.exists(filePath),
+ "Sanity check: path should exist: " + filePath);
+ test.assertRaises(function () file.rmdir(path),
+ /^The directory is not empty: .+$/,
+ "rmdir on non-empty directory should raise error");
+ file.remove(filePath);
+ file.rmdir(path);
+ test.assert(!file.exists(path), "Path should not exist");
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-frame-utils.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-frame-utils.js
new file mode 100644
index 0000000..268643c
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-frame-utils.js
@@ -0,0 +1,67 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+const { open } = require('api-utils/window/utils');
+const { create } = require('api-utils/frame/utils');
+
+exports['test frame creation'] = function(assert) {
+ let window = open('data:text/html,Window');
+ let frame = create(window.document);
+
+ assert.equal(frame.getAttribute('type'), 'content',
+ 'frame type is content');
+ assert.ok(frame.contentWindow, 'frame has contentWindow');
+ assert.equal(frame.contentWindow.location.href, 'about:blank',
+ 'by default "about:blank" is loaded');
+ assert.equal(frame.docShell.allowAuth, false, 'auth disabled by default');
+ assert.equal(frame.docShell.allowJavascript, false, 'js disabled by default');
+ assert.equal(frame.docShell.allowPlugins, false,
+ 'plugins disabled by default');
+ window.close();
+};
+
+exports['test fram has js disabled by default'] = function(assert, done) {
+ let window = open('data:text/html,window');
+ window.addEventListener('DOMContentLoaded', function windowReady() {
+ window.removeEventListener('DOMContentLoaded', windowReady, false);
+ let frame = create(window.document, {
+ uri: 'data:text/html,<script>document.documentElement.innerHTML' +
+ '= "J" + "S"</script>',
+ });
+ frame.contentWindow.addEventListener('DOMContentLoaded', function ready() {
+ frame.contentWindow.removeEventListener('DOMContentLoaded', ready, false);
+ assert.ok(!~frame.contentDocument.documentElement.innerHTML.indexOf('JS'),
+ 'JS was executed');
+
+ window.close();
+ done();
+ }, false);
+
+ }, false);
+};
+
+exports['test frame with js enabled'] = function(assert, done) {
+ let window = open('data:text/html,window');
+ window.addEventListener('DOMContentLoaded', function windowReady() {
+ window.removeEventListener('DOMContentLoaded', windowReady, false);
+ let frame = create(window.document, {
+ uri: 'data:text/html,<script>document.documentElement.innerHTML' +
+ '= "J" + "S"</script>',
+ allowJavascript: true
+ });
+ frame.contentWindow.addEventListener('DOMContentLoaded', function ready() {
+ frame.contentWindow.removeEventListener('DOMContentLoaded', ready, false);
+ assert.ok(~frame.contentDocument.documentElement.innerHTML.indexOf('JS'),
+ 'JS was executed');
+
+ window.close();
+ done();
+ }, false);
+
+ }, false);
+};
+
+require('test').run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-functional.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-functional.js
new file mode 100644
index 0000000..377a709
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-functional.js
@@ -0,0 +1,170 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const { setTimeout } = require('api-utils/timer');
+const utils = require('api-utils/functional');
+const { invoke, defer, curry, compose, memoize, once, delay, wrap } = utils;
+
+exports['test forwardApply'] = function(assert) {
+ function sum(b, c) this.a + b + c
+ assert.equal(invoke(sum, [2, 3], { a: 1 }), 6,
+ 'passed arguments and pseoude-variable are used');
+
+ assert.equal(invoke(sum.bind({ a: 2 }), [2, 3], { a: 1 }), 7,
+ 'bounded `this` pseoudo variable is used');
+}
+
+exports['test deferred function'] = function(assert, done) {
+ let nextTurn = false;
+ function sum(b, c) {
+ assert.ok(nextTurn, 'enqueued is called in next turn of event loop');
+ assert.equal(this.a + b + c, 6,
+ 'passed arguments an pseoude-variable are used');
+ done();
+ }
+
+ let fixture = { a: 1, method: defer(sum) }
+ fixture.method(2, 3);
+ nextTurn = true;
+};
+
+exports['test curry function'] = function(assert) {
+ function sum(b, c) this.a + b + c;
+
+ let foo = { a : 5 };
+
+ foo.sum7 = curry(sum, 7);
+ foo.sum8and4 = curry(sum, 8, 4);
+
+ assert.equal(foo.sum7(2), 14, 'curry one arguments works');
+
+ assert.equal(foo.sum8and4(), 17, 'curry both arguments works');
+};
+
+exports['test compose'] = function(assert) {
+ let greet = function(name) { return 'hi: ' + name; };
+ let exclaim = function(sentence) { return sentence + '!'; };
+
+ assert.equal(compose(exclaim, greet)('moe'), 'hi: moe!',
+ 'can compose a function that takes another');
+
+ assert.equal(compose(greet, exclaim)('moe'), 'hi: moe!',
+ 'in this case, the functions are also commutative');
+
+ let target = {
+ name: 'Joe',
+ greet: compose(function exclaim(sentence) {
+ return sentence + '!'
+ }, function(title) {
+ return 'hi : ' + title + ' ' + this.name;
+ })
+ }
+
+ assert.equal(target.greet('Mr'), 'hi : Mr Joe!',
+ 'this can be passed in');
+ assert.equal(target.greet.call({ name: 'Alex' }, 'Dr'), 'hi : Dr Alex!',
+ 'this can be applied');
+
+ let single = compose(function(value) {
+ return value + ':suffix';
+ });
+
+ assert.equal(single('text'), 'text:suffix', 'works with single function');
+
+ let identity = compose();
+ assert.equal(identity('bla'), 'bla', 'works with zero functions');
+};
+
+exports['test wrap'] = function(assert) {
+ let greet = function(name) { return 'hi: ' + name; };
+ let backwards = wrap(greet, function(f, name) {
+ return f(name) + ' ' + name.split('').reverse().join('');
+ });
+
+ assert.equal(backwards('moe'), 'hi: moe eom',
+ 'wrapped the saluation function');
+
+ let inner = function () { return 'Hello '; };
+ let target = {
+ name: 'Matteo',
+ hi: wrap(inner, function(f) { return f() + this.name; })
+ };
+
+ assert.equal(target.hi(), 'Hello Matteo', 'works with this');
+
+ function noop() { };
+ let wrapped = wrap(noop, function(f) {
+ return Array.slice(arguments);
+ });
+
+ let actual = wrapped([ 'whats', 'your' ], 'vector', 'victor');
+ assert.deepEqual(actual, [ noop, ['whats', 'your'], 'vector', 'victor' ],
+ 'works with fancy stuff');
+};
+
+exports['test memoize'] = function(assert) {
+ function fib(n) n < 2 ? n : fib(n - 1) + fib(n - 2)
+ let fibnitro = memoize(fib);
+
+ assert.equal(fib(10), 55,
+ 'a memoized version of fibonacci produces identical results');
+ assert.equal(fibnitro(10), 55,
+ 'a memoized version of fibonacci produces identical results');
+
+ function o(key, value) { return value; };
+ let oo = memoize(o), v1 = {}, v2 = {};
+
+
+ assert.equal(oo(1, v1), v1, 'returns value back');
+ assert.equal(oo(1, v2), v1, 'memoized by a first argument');
+ assert.equal(oo(2, v2), v2, 'returns back value if not memoized');
+ assert.equal(oo(2), v2, 'memoized new value');
+ assert.notEqual(oo(1), oo(2), 'values do not override');
+ assert.equal(o(3, v2), oo(2, 3), 'returns same value as un-memoized');
+
+ let get = memoize(function(attribute) this[attribute])
+ let target = { name: 'Bob', get: get }
+
+ assert.equal(target.get('name'), 'Bob', 'has correct `this`');
+ assert.equal(target.get.call({ name: 'Jack' }, 'name'), 'Bob',
+ 'name is memoized')
+ assert.equal(get('name'), 'Bob', 'once memoized can be called without this');
+};
+
+exports['test delay'] = function(assert, done) {
+ let delayed = false;
+ delay(function() {
+ assert.ok(delayed, 'delayed the function');
+ done();
+ }, 1);
+ delayed = true;
+};
+
+exports['test delay with this'] = function(assert, done) {
+ let context = {}
+ delay.call(context, function(name) {
+ assert.equal(this, context, 'this was passed in');
+ assert.equal(name, 'Tom', 'argument was passed in');
+ done();
+ }, 10, 'Tom');
+}
+
+exports['test once'] = function(assert) {
+ let n = 0;
+ let increment = once(function() { n ++; });
+
+ increment();
+ increment();
+
+ assert.equal(n, 1, 'only incremented once');
+
+ let target = { state: 0, update: once(function() this.state ++ ) };
+
+ target.update();
+ target.update();
+
+ assert.equal(target.state, 1, 'this was passed in and called only once');
+};
+
+require('test').run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-globals.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-globals.js
new file mode 100644
index 0000000..1d8caf0
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-globals.js
@@ -0,0 +1,22 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+Object.defineProperty(this, "global", { value: this });
+
+exports.testGlobals = function(test) {
+ // the only globals in module scope should be:
+ // module, exports, require, dump, console
+ test.assertObject(module, "have 'module', good");
+ test.assertObject(exports, "have 'exports', good");
+ test.assertFunction(require, "have 'require', good");
+ test.assertFunction(dump, "have 'dump', good");
+ test.assertObject(console, "have 'console', good");
+
+ // in particular, these old globals should no longer be present
+ test.assert(!('packaging' in global), "no 'packaging', good");
+ test.assert(!('memory' in global), "no 'memory', good");
+
+ test.assertMatches(module.uri, /test-globals\.js$/,
+ 'should contain filename');
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-hidden-frame.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-hidden-frame.js
new file mode 100644
index 0000000..2441c3e
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-hidden-frame.js
@@ -0,0 +1,51 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+let tests = {}, hiddenFrames, HiddenFrame;
+
+tests.testFrame = function(test) {
+ let url = "data:text/html,<!DOCTYPE%20html>";
+ test.waitUntilDone();
+ let hiddenFrame = hiddenFrames.add(HiddenFrame({
+ onReady: function () {
+ test.assertEqual(this.element.contentWindow.location, "about:blank",
+ "HiddenFrame loads about:blank by default.");
+
+ function onDOMReady() {
+ hiddenFrame.element.removeEventListener("DOMContentLoaded", onDOMReady,
+ false);
+ test.assertEqual(hiddenFrame.element.contentWindow.location, url,
+ "HiddenFrame loads the specified content.");
+ test.done();
+ }
+ this.element.addEventListener("DOMContentLoaded", onDOMReady, false);
+ this.element.setAttribute("src", url);
+ }
+ }));
+};
+
+let hiddenFrameSupported = true;
+
+try {
+ hiddenFrames = require("hidden-frame");
+ HiddenFrame = hiddenFrames.HiddenFrame;
+}
+catch(ex if ex.message == [
+ "The hidden-frame module currently supports only Firefox and Thunderbird. ",
+ "In the future, we would like it to support other applications, however. ",
+ "Please see https://bugzilla.mozilla.org/show_bug.cgi?id=546740 for more ",
+ "information."
+ ].join("")) {
+ hiddenFrameSupported = false;
+}
+
+if (hiddenFrameSupported) {
+ for (let test in tests)
+ exports[test] = tests[test];
+}
+else {
+ exports.testHiddenFrameNotSupported = function(test) {
+ test.pass("The hidden-frame module is not supported on this app.");
+ }
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-httpd.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-httpd.js
new file mode 100644
index 0000000..dc1adf1
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-httpd.js
@@ -0,0 +1,72 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const port = 8099;
+const file = require("api-utils/file");
+const { pathFor } = require("api-utils/system");
+
+exports.testBasicHTTPServer = function(test) {
+ let basePath = pathFor("TmpD");
+ let filePath = file.join(basePath, 'test-httpd.txt');
+ let content = "This is the HTTPD test file.\n";
+ let fileStream = file.open(filePath, 'w');
+ fileStream.write(content);
+ fileStream.close();
+
+ let { startServerAsync } = require("httpd");
+ let srv = startServerAsync(port, basePath);
+
+ test.waitUntilDone();
+
+ // Request this very file.
+ let Request = require('request').Request;
+ Request({
+ url: "http://localhost:" + port + "/test-httpd.txt",
+ onComplete: function (response) {
+ test.assertEqual(response.text, content);
+ done();
+ }
+ }).get();
+
+ function done() {
+ srv.stop(function() {
+ test.done();
+ });
+ }
+};
+
+exports.testDynamicServer = function (test) {
+ let content = "This is the HTTPD test file.\n";
+
+ let { startServerAsync } = require("httpd");
+ let srv = startServerAsync(port);
+
+ // See documentation here:
+ //http://doxygen.db48x.net/mozilla/html/interfacensIHttpServer.html#a81fc7e7e29d82aac5ce7d56d0bedfb3a
+ //http://doxygen.db48x.net/mozilla/html/interfacensIHttpRequestHandler.html
+ srv.registerPathHandler("/test-httpd.txt", function handle(request, response) {
+ // Add text content type, only to avoid error in `Request` API
+ response.setHeader("Content-Type", "text/plain", false);
+ response.write(content);
+ });
+
+ test.waitUntilDone();
+
+ // Request this very file.
+ let Request = require('request').Request;
+ Request({
+ url: "http://localhost:" + port + "/test-httpd.txt",
+ onComplete: function (response) {
+ test.assertEqual(response.text, content);
+ done();
+ }
+ }).get();
+
+ function done() {
+ srv.stop(function() {
+ test.done();
+ });
+ }
+
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-keyboard-observer.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-keyboard-observer.js
new file mode 100644
index 0000000..584f01b
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-keyboard-observer.js
@@ -0,0 +1,36 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { keyPress } = require("api-utils/dom/events/keys");
+const { Loader } = require("./helpers");
+
+exports["test unload keyboard observer"] = function(assert, done) {
+ let loader = Loader(module);
+ let element = loader.require("api-utils/window-utils").
+ activeBrowserWindow.document.documentElement;
+ let observer = loader.require("api-utils/keyboard/observer").
+ observer;
+ let called = 0;
+
+ observer.on("keypress", function () { called++; });
+
+ // dispatching "keypress" event to trigger observer listeners.
+ keyPress(element, "accel-%");
+
+ // Unload the module.
+ loader.unload();
+
+ // dispatching "keypress" even once again.
+ keyPress(element, "accel-%");
+
+ // Enqueuing asserts to make sure that assertion is not performed early.
+ require("timer").setTimeout(function () {
+ assert.equal(called, 1, "observer was called before unload only.");
+ done();
+ }, 0);
+};
+
+require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-keyboard-utils.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-keyboard-utils.js
new file mode 100644
index 0000000..1146a7b
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-keyboard-utils.js
@@ -0,0 +1,62 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const utils = require("keyboard/utils");
+const runtime = require("runtime");
+
+const isMac = runtime.OS === "Darwin";
+
+exports["test toString"] = function(assert) {
+ assert.equal(utils.toString({
+ key: "B",
+ modifiers: [ "Shift", "Ctrl" ]
+ }), "Shift-Ctrl-B", "toString does not normalizes JSON");
+
+ assert.equal(utils.toString({
+ key: "C",
+ modifiers: [],
+ }), "C", "Works with objects with empty array of modifiers");
+
+ assert.equal(utils.toString(Object.create((function Type() {}).prototype, {
+ key: { value: "d" },
+ modifiers: { value: [ "alt" ] },
+ method: { value: function() {} }
+ })), "alt-d", "Works with non-json objects");
+
+ assert.equal(utils.toString({
+ modifiers: [ "shift", "alt" ]
+ }), "shift-alt-", "works with only modifiers");
+};
+
+exports["test toJSON"] = function(assert) {
+ assert.deepEqual(utils.toJSON("Shift-Ctrl-B"), {
+ key: "b",
+ modifiers: [ "control", "shift" ]
+ }, "toJSON normalizes input");
+
+ assert.deepEqual(utils.toJSON("Meta-Alt-option-C"), {
+ key: "c",
+ modifiers: [ "alt", "meta" ]
+ }, "removes dublicates");
+
+ assert.deepEqual(utils.toJSON("AccEl+sHiFt+Z", "+"), {
+ key: "z",
+ modifiers: isMac ? [ "meta", "shift" ] : [ "control", "shift" ]
+ }, "normalizes OS specific keys and adjustes seperator");
+};
+
+exports["test normalize"] = function assert(assert) {
+ assert.equal(utils.normalize("Shift Ctrl A control ctrl", " "),
+ "control shift a", "removes reapeted modifiers");
+ assert.equal(utils.normalize("shift-ctrl-left"), "control-shift-left",
+ "normilizes non printed characters");
+
+ assert.throws(function() {
+ utils.normalize("shift-alt-b-z");
+ }, "throws if contains more then on non-modifier key");
+};
+
+require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-l10n-locale.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-l10n-locale.js
new file mode 100644
index 0000000..db559ba
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-l10n-locale.js
@@ -0,0 +1,141 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const { getPreferedLocales, findClosestLocale } = require("api-utils/l10n/locale");
+const prefs = require("preferences-service");
+const { Cc, Ci, Cu } = require("chrome");
+const { Services } = Cu.import("resource://gre/modules/Services.jsm");
+const BundleService = Cc["@mozilla.org/intl/stringbundle;1"].getService(Ci.nsIStringBundleService);
+
+const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS";
+const PREF_SELECTED_LOCALE = "general.useragent.locale";
+const PREF_ACCEPT_LANGUAGES = "intl.accept_languages";
+
+function assertPrefered(test, expected, msg) {
+ test.assertEqual(JSON.stringify(getPreferedLocales()), JSON.stringify(expected),
+ msg);
+}
+
+exports.testGetPreferedLocales = function(test) {
+ prefs.set(PREF_MATCH_OS_LOCALE, false);
+ prefs.set(PREF_SELECTED_LOCALE, "");
+ prefs.set(PREF_ACCEPT_LANGUAGES, "");
+ assertPrefered(test, ["en-us"],
+ "When all preferences are empty, we only have en-us");
+
+ prefs.set(PREF_SELECTED_LOCALE, "fr");
+ prefs.set(PREF_ACCEPT_LANGUAGES, "jp");
+ assertPrefered(test, ["fr", "jp", "en-us"],
+ "We first have useragent locale, then web one and finally en-US");
+
+ prefs.set(PREF_SELECTED_LOCALE, "en-US");
+ prefs.set(PREF_ACCEPT_LANGUAGES, "en-US");
+ assertPrefered(test, ["en-us"],
+ "We do not have duplicates");
+
+ prefs.set(PREF_SELECTED_LOCALE, "en-US");
+ prefs.set(PREF_ACCEPT_LANGUAGES, "fr");
+ assertPrefered(test, ["en-us", "fr"],
+ "en-US can be first if specified by higher priority preference");
+
+ // Reset what we changed
+ prefs.reset(PREF_MATCH_OS_LOCALE);
+ prefs.reset(PREF_SELECTED_LOCALE);
+ prefs.reset(PREF_ACCEPT_LANGUAGES);
+}
+
+// In some cases, mainly on Fennec and on Linux version,
+// `general.useragent.locale` is a special 'localized' value, like:
+// "chrome://global/locale/intl.properties"
+exports.testPreferedLocalizedLocale = function(test) {
+ prefs.set(PREF_MATCH_OS_LOCALE, false);
+ let bundleURL = "chrome://global/locale/intl.properties";
+ prefs.setLocalized(PREF_SELECTED_LOCALE, bundleURL);
+ let contentLocale = "ja";
+ prefs.set(PREF_ACCEPT_LANGUAGES, contentLocale);
+
+ // Read manually the expected locale value from the property file
+ let expectedLocale = BundleService.createBundle(bundleURL).
+ GetStringFromName(PREF_SELECTED_LOCALE).
+ toLowerCase();
+
+ // First add the useragent locale
+ let expectedLocaleList = [expectedLocale];
+
+ // Then the content locale
+ if (expectedLocaleList.indexOf(contentLocale) == -1)
+ expectedLocaleList.push(contentLocale);
+
+ // Add default "en-us" fallback if the main language is not already en-us
+ if (expectedLocaleList.indexOf("en-us") == -1)
+ expectedLocaleList.push("en-us");
+
+ assertPrefered(test, expectedLocaleList, "test localized pref value");
+
+ // Reset what we have changed
+ prefs.reset(PREF_MATCH_OS_LOCALE);
+ prefs.reset(PREF_SELECTED_LOCALE);
+ prefs.reset(PREF_ACCEPT_LANGUAGES);
+}
+
+exports.testPreferedOsLocale = function(test) {
+ prefs.set(PREF_MATCH_OS_LOCALE, true);
+ prefs.set(PREF_SELECTED_LOCALE, "");
+ prefs.set(PREF_ACCEPT_LANGUAGES, "");
+
+ let expectedLocale = Services.locale.getLocaleComponentForUserAgent().
+ toLowerCase();
+ let expectedLocaleList = [expectedLocale];
+
+ // Add default "en-us" fallback if the main language is not already en-us
+ if (expectedLocale != "en-us")
+ expectedLocaleList.push("en-us");
+
+ assertPrefered(test, expectedLocaleList, "Ensure that we select OS locale when related preference is set");
+
+ // Reset what we have changed
+ prefs.reset(PREF_MATCH_OS_LOCALE);
+ prefs.reset(PREF_SELECTED_LOCALE);
+ prefs.reset(PREF_ACCEPT_LANGUAGES);
+}
+
+exports.testFindClosestLocale = function(test) {
+ // Second param of findClosestLocale (aMatchLocales) have to be in lowercase
+ test.assertEqual(findClosestLocale([], []), null,
+ "When everything is empty we get null");
+
+ test.assertEqual(findClosestLocale(["en", "en-US"], ["en"]),
+ "en", "We always accept exact match first 1/5");
+ test.assertEqual(findClosestLocale(["en-US", "en"], ["en"]),
+ "en", "We always accept exact match first 2/5");
+ test.assertEqual(findClosestLocale(["en", "en-US"], ["en-us"]),
+ "en-US", "We always accept exact match first 3/5");
+ test.assertEqual(findClosestLocale(["ja-JP-mac", "ja", "ja-JP"], ["ja-jp"]),
+ "ja-JP", "We always accept exact match first 4/5");
+ test.assertEqual(findClosestLocale(["ja-JP-mac", "ja", "ja-JP"], ["ja-jp-mac"]),
+ "ja-JP-mac", "We always accept exact match first 5/5");
+
+ test.assertEqual(findClosestLocale(["en", "en-GB"], ["en-us"]),
+ "en", "We accept more generic locale, when there is no exact match 1/2");
+ test.assertEqual(findClosestLocale(["en-ZA", "en"], ["en-gb"]),
+ "en", "We accept more generic locale, when there is no exact match 2/2");
+
+ test.assertEqual(findClosestLocale(["ja-JP"], ["ja"]),
+ "ja-JP", "We accept more specialized locale, when there is no exact match 1/2");
+ // Better to select "ja" in this case but behave same as current AddonManager
+ test.assertEqual(findClosestLocale(["ja-JP-mac", "ja"], ["ja-jp"]),
+ "ja-JP-mac", "We accept more specialized locale, when there is no exact match 2/2");
+
+ test.assertEqual(findClosestLocale(["en-US"], ["en-us"]),
+ "en-US", "We keep the original one as result 1/2");
+ test.assertEqual(findClosestLocale(["en-us"], ["en-us"]),
+ "en-us", "We keep the original one as result 2/2");
+
+ test.assertEqual(findClosestLocale(["ja-JP-mac"], ["ja-jp-mac"]),
+ "ja-JP-mac", "We accept locale with 3 parts");
+ test.assertEqual(findClosestLocale(["ja-JP"], ["ja-jp-mac"]),
+ "ja-JP", "We accept locale with 2 parts from locale with 3 parts");
+ test.assertEqual(findClosestLocale(["ja"], ["ja-jp-mac"]),
+ "ja", "We accept locale with 1 part from locale with 3 parts");
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-l10n-plural-rules.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-l10n-plural-rules.js
new file mode 100644
index 0000000..e46ecf6
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-l10n-plural-rules.js
@@ -0,0 +1,82 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const { getRulesForLocale } = require("api-utils/l10n/plural-rules");
+
+// For more information, please visit unicode website:
+// http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
+
+function map(test, f, n, form) {
+ test.assertEqual(f(n), form, n + " maps to '" + form + "'");
+}
+
+exports.testFrench = function(test) {
+ let f = getRulesForLocale("fr");
+ map(test, f, -1, "other");
+ map(test, f, 0, "one");
+ map(test, f, 1, "one");
+ map(test, f, 1.5, "one");
+ map(test, f, 2, "other");
+ map(test, f, 100, "other");
+}
+
+exports.testEnglish = function(test) {
+ let f = getRulesForLocale("en");
+ map(test, f, -1, "other");
+ map(test, f, 0, "other");
+ map(test, f, 1, "one");
+ map(test, f, 1.5, "other");
+ map(test, f, 2, "other");
+ map(test, f, 100, "other");
+}
+
+exports.testArabic = function(test) {
+ let f = getRulesForLocale("ar");
+ map(test, f, -1, "other");
+ map(test, f, 0, "zero");
+ map(test, f, 0.5, "other");
+
+ map(test, f, 1, "one");
+ map(test, f, 1.5, "other");
+
+ map(test, f, 2, "two");
+ map(test, f, 2.5, "other");
+
+ map(test, f, 3, "few");
+ map(test, f, 3.5, "few"); // I'd expect it to be 'other', but the unicode.org
+ // algorithm computes 'few'.
+ map(test, f, 5, "few");
+ map(test, f, 10, "few");
+ map(test, f, 103, "few");
+ map(test, f, 105, "few");
+ map(test, f, 110, "few");
+ map(test, f, 203, "few");
+ map(test, f, 205, "few");
+ map(test, f, 210, "few");
+
+ map(test, f, 11, "many");
+ map(test, f, 50, "many");
+ map(test, f, 99, "many");
+ map(test, f, 111, "many");
+ map(test, f, 150, "many");
+ map(test, f, 199, "many");
+
+ map(test, f, 100, "other");
+ map(test, f, 101, "other");
+ map(test, f, 102, "other");
+ map(test, f, 200, "other");
+ map(test, f, 201, "other");
+ map(test, f, 202, "other");
+}
+
+exports.testJapanese = function(test) {
+ // Japanese doesn't have plural forms.
+ let f = getRulesForLocale("ja");
+ map(test, f, -1, "other");
+ map(test, f, 0, "other");
+ map(test, f, 1, "other");
+ map(test, f, 1.5, "other");
+ map(test, f, 2, "other");
+ map(test, f, 100, "other");
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-light-traits.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-light-traits.js
new file mode 100644
index 0000000..7c5ca42
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-light-traits.js
@@ -0,0 +1,11 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+exports["test traits from objects"] = require("./traits/object-tests");
+exports["test traits from descriptors"] = require("./traits/descriptor-tests");
+exports["test inheritance"] = require("./traits/inheritance-tests");
+
+require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-list.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-list.js
new file mode 100644
index 0000000..67e67aa
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-list.js
@@ -0,0 +1,207 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+function assertList(test, array, list) {
+ for (let i = 0, ii = array.length; i < ii; i < ii, i++) {
+ test.assertEqual(
+ array.length,
+ list.length,
+ 'list must contain same amount of elements as array'
+ );
+ test.assertEqual(
+ 'List(' + array + ')',
+ list + '',
+ 'toString must output array like result'
+ );
+ test.assert(
+ i in list,
+ 'must contain element with index: ' + i
+ );
+ test.assertEqual(
+ array[i],
+ list[i],
+ 'element with index: ' + i + ' should match'
+ );
+ }
+}
+
+const { List } = require('api-utils/list');
+
+exports['test:test for'] = function(test) {
+ let fixture = List(3, 2, 1);
+
+ test.assertEqual(3, fixture.length, 'length is 3');
+ let i = 0;
+ for (let key in fixture) {
+ test.assertEqual(i++, key, 'key should match');
+ }
+};
+
+exports['test:test for each'] = function(test) {
+ let fixture = new List(3, 2, 1);
+
+ test.assertEqual(3, fixture.length, 'length is 3');
+ let i = 3;
+ for each (let value in fixture) {
+ test.assertEqual(i--, value, 'value should match');
+ }
+};
+
+exports['test: for each using Iterator'] = function(test) {
+ let fixture = new List(3, 2, 1);
+
+ test.assertEqual(3, fixture.length, 'length is 3');
+ let v = 3, k = 0;
+ for each (let [key, value] in Iterator(fixture)) {
+ test.assertEqual(k++, key, 'key should match');
+ test.assertEqual(v--, value, 'value should match');
+ }
+};
+
+exports['test:test toString'] = function(test) {
+ let fixture = List(3, 2, 1);
+
+ test.assertEqual(
+ 'List(3,2,1)',
+ fixture + '',
+ 'toString must output array like result'
+ )
+};
+
+exports['test:test constructor with apply'] = function(test) {
+ let array = ['a', 'b', 'c'];
+ let fixture = List.apply(null, array);
+
+ test.assertEqual(
+ 3,
+ fixture.length,
+ 'should have applied arguments'
+ );
+};
+
+exports['test:direct element access'] = function(test) {
+ let array = [1, 'foo', 2, 'bar', {}, 'bar', function a() {}, test, 1];
+ let fixture = List.apply(null, array);
+ array.splice(5, 1);
+ array.splice(7, 1);
+
+ test.assertEqual(
+ array.length,
+ fixture.length,
+ 'list should omit duplicate elements'
+ );
+
+ test.assertEqual(
+ 'List(' + array + ')',
+ fixture.toString(),
+ 'elements should not be rearranged'
+ );
+
+ for (let key in array) {
+ test.assert(key in fixture,'should contain key for index:' + key);
+ test.assertEqual(
+ array[key],
+ fixture[key],
+ 'values should match for: ' + key
+ );
+ }
+};
+
+exports['test:removing adding elements'] = function(test) {
+ let array = [1, 'foo', 2, 'bar', {}, 'bar', function a() {}, test, 1];
+ let fixture = List.compose({
+ add: function() this._add.apply(this, arguments),
+ remove: function() this._remove.apply(this, arguments),
+ clear: function() this._clear()
+ }).apply(null, array);
+ array.splice(5, 1);
+ array.splice(7, 1);
+
+ assertList(test, array, fixture);
+
+ array.splice(array.indexOf(2), 1);
+ fixture.remove(2);
+ assertList(test, array, fixture);
+
+ array.splice(array.indexOf('foo'), 1);
+ fixture.remove('foo');
+ array.splice(array.indexOf(1), 1);
+ fixture.remove(1);
+ array.push('foo');
+ fixture.add('foo');
+ assertList(test, array, fixture);
+
+ array.splice(0);
+ fixture.clear(0);
+ assertList(test, array, fixture);
+
+ array.push(1, 'foo', 2, 'bar', 3);
+ fixture.add(1);
+ fixture.add('foo');
+ fixture.add(2);
+ fixture.add('bar');
+ fixture.add(3);
+
+ assertList(test, array, fixture);
+};
+
+exports['test: remove does not leave invalid numerical properties'] = function(test) {
+ let fixture = List.compose({
+ remove: function() this._remove.apply(this, arguments),
+ }).apply(null, [1, 2, 3]);
+
+ fixture.remove(1);
+ test.assertEqual(fixture[fixture.length], undefined);
+}
+
+exports['test:add list item from Iterator'] = function(test) {
+ let array = [1, 2, 3, 4], sum = 0, added = false;
+
+ let fixture = List.compose({
+ add: function() this._add.apply(this, arguments),
+ }).apply(null, array);
+
+ for each (let item in fixture) {
+ sum += item;
+
+ if (!added) {
+ fixture.add(5);
+ added = true;
+ }
+ }
+
+ test.assertEqual(sum, 1 + 2 + 3 + 4);
+};
+
+exports['test:remove list item from Iterator'] = function(test) {
+ let array = [1, 2, 3, 4], sum = 0;
+
+ let fixture = List.compose({
+ remove: function() this._remove.apply(this, arguments),
+ }).apply(null, array);
+
+ for each (let item in fixture) {
+ sum += item;
+ fixture.remove(item);
+ }
+
+ test.assertEqual(sum, 1 + 2 + 3 + 4);
+};
+
+exports['test:clear list from Iterator'] = function(test) {
+ let array = [1, 2, 3, 4], sum = 0;
+
+ let fixture = List.compose({
+ clear: function() this._clear()
+ }).apply(null, array);
+
+ for each (let item in fixture) {
+ sum += item;
+ fixture.clear();
+ }
+
+ test.assertEqual(sum, 1 + 2 + 3 + 4);
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-loader.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-loader.js
new file mode 100644
index 0000000..82d97ba
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-loader.js
@@ -0,0 +1,35 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const { Loader } = require("./helpers");
+
+exports.testLoader = function(test) {
+ var prints = [];
+ function print(message) {
+ prints.push(message);
+ }
+
+ var loader = Loader(module, { dump: print, foo: 1 });
+
+ var fixture = loader.require('./loader/fixture');
+
+ test.assertEqual(fixture.foo, 1, "custom globals must work.");
+
+ test.assertEqual(prints[0], "info: testing 1 2,3,4\n",
+ "global console must work.");
+
+ var unloadsCalled = '';
+
+ loader.require("unload").when(function() {
+ unloadsCalled += 'a';
+ });
+ loader.require("unload.js").when(function() {
+ unloadsCalled += 'b';
+ });
+
+ loader.unload();
+
+ test.assertEqual(unloadsCalled, 'ba',
+ "loader.unload() must call cb's in LIFO order.");
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-match-pattern.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-match-pattern.js
new file mode 100644
index 0000000..9cedf66
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-match-pattern.js
@@ -0,0 +1,127 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const { MatchPattern } = require("match-pattern");
+
+exports.testMatchPatternTestTrue = function(test) {
+ function ok(pattern, url) {
+ let mp = new MatchPattern(pattern);
+ test.assert(mp.test(url), pattern + " should match " + url);
+ }
+
+ ok("*", "http://example.com");
+ ok("*", "https://example.com");
+ ok("*", "ftp://example.com");
+
+ ok("*.example.com", "http://example.com");
+ ok("*.example.com", "http://hamburger.example.com");
+ ok("*.example.com", "http://hotdog.hamburger.example.com");
+
+ ok("http://example.com*", "http://example.com");
+ ok("http://example.com*", "http://example.com/");
+ ok("http://example.com/*", "http://example.com/");
+ ok("http://example.com/*", "http://example.com/potato-salad");
+ ok("http://example.com/pickles/*", "http://example.com/pickles/");
+ ok("http://example.com/pickles/*", "http://example.com/pickles/lemonade");
+
+ ok("http://example.com", "http://example.com");
+ ok("http://example.com/ice-cream", "http://example.com/ice-cream");
+
+ ok(/.*zilla.*/, "https://bugzilla.redhat.com/show_bug.cgi?id=569753");
+ ok(/https:.*zilla.*/, "https://bugzilla.redhat.com/show_bug.cgi?id=569753");
+};
+
+exports.testMatchPatternTestFalse = function(test) {
+ function ok(pattern, url) {
+ let mp = new MatchPattern(pattern);
+ test.assert(!mp.test(url), pattern + " should not match " + url);
+ }
+
+ ok("*", null);
+ ok("*", "");
+ ok("*", "bogus");
+ ok("*", "chrome://browser/content/browser.xul");
+ ok("*", "nttp://example.com");
+
+ ok("*.example.com", null);
+ ok("*.example.com", "");
+ ok("*.example.com", "bogus");
+ ok("*.example.com", "http://example.net");
+ ok("*.example.com", "http://foo.com");
+ ok("*.example.com", "http://example.com.foo");
+ ok("*.example2.com", "http://example.com");
+
+ ok("http://example.com/*", null);
+ ok("http://example.com/*", "");
+ ok("http://example.com/*", "bogus");
+ ok("http://example.com/*", "http://example.com");
+ ok("http://example.com/*", "http://foo.com/");
+
+ ok("http://example.com", null);
+ ok("http://example.com", "");
+ ok("http://example.com", "bogus");
+ ok("http://example.com", "http://example.com/");
+
+ ok(/zilla.*/, "https://bugzilla.redhat.com/show_bug.cgi?id=569753");
+ ok(/.*zilla/, "https://bugzilla.redhat.com/show_bug.cgi?id=569753");
+ ok(/https:.*zilla/, "https://bugzilla.redhat.com/show_bug.cgi?id=569753");
+};
+
+exports.testMatchPatternErrors = function(test) {
+ test.assertRaises(
+ function() new MatchPattern("*.google.com/*"),
+ /There can be at most one/,
+ "MatchPattern throws when supplied multiple '*'"
+ );
+
+ test.assertRaises(
+ function() new MatchPattern("google.com"),
+ /expected to be either an exact URL/,
+ "MatchPattern throws when the wildcard doesn't use '*' and doesn't " +
+ "look like a URL"
+ );
+
+ test.assertRaises(
+ function() new MatchPattern("http://google*.com"),
+ /expected to be the first or the last/,
+ "MatchPattern throws when a '*' is in the middle of the wildcard"
+ );
+
+ test.assertRaises(
+ function() new MatchPattern(/ /g),
+ /^A RegExp match pattern cannot be set to `global` \(i\.e\. \/\/g\)\.$/,
+ "MatchPattern throws on a RegExp set to `global` (i.e. //g)."
+ );
+
+ test.assertRaises(
+ function() new MatchPattern(/ /i),
+ /^A RegExp match pattern cannot be set to `ignoreCase` \(i\.e\. \/\/i\)\.$/,
+ "MatchPattern throws on a RegExp set to `ignoreCase` (i.e. //i)."
+ );
+
+ test.assertRaises(
+ function() new MatchPattern( / /m ),
+ /^A RegExp match pattern cannot be set to `multiline` \(i\.e\. \/\/m\)\.$/,
+ "MatchPattern throws on a RegExp set to `multiline` (i.e. //m)."
+ );
+};
+
+exports.testMatchPatternInternals = function(test) {
+ test.assertEqual(
+ new MatchPattern("http://google.com/test").exactURL,
+ "http://google.com/test"
+ );
+
+ test.assertEqual(
+ new MatchPattern("http://google.com/test/*").urlPrefix,
+ "http://google.com/test/"
+ );
+
+ test.assertEqual(
+ new MatchPattern("*.example.com").domain,
+ "example.com"
+ );
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-memory.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-memory.js
new file mode 100644
index 0000000..99e1682
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-memory.js
@@ -0,0 +1,19 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var memory = require("api-utils/memory");
+
+exports.testMemory = function(test) {
+ test.pass("Skipping this test until Gecko memory debugging issues " +
+ "are resolved (see bug 592774).");
+ return;
+
+ var obj = {};
+ memory.track(obj, "testMemory.testObj");
+ var objs = memory.getObjects("testMemory.testObj");
+ test.assertEqual(objs[0].weakref.get(), obj);
+ obj = null;
+ memory.gc();
+ test.assertEqual(objs[0].weakref.get(), null);
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-message-manager.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-message-manager.js
new file mode 100644
index 0000000..386d3bd
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-message-manager.js
@@ -0,0 +1,600 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Loader } = require('./helpers');
+
+function createMessageManager() {
+ let loader = Loader(module);
+ let { MessageManager } = loader.require("api-utils/message-manager");
+ let frame = loader.sandbox("api-utils/message-manager").frame;
+
+ return [new MessageManager, frame];
+}
+
+
+exports["test MessageManager addMessageListener"] =
+ function(assert) {
+ let [mm, frame] = createMessageManager();
+ let remoteFrame = frame(mm).receiver;
+
+ let listeners = frame(mm).listeners;
+ let remoteListeners = frame(remoteFrame).listeners;
+
+ let topic = "message-topic";
+
+ let listener = function () {};
+
+ assert.equal(topic in listeners, false,
+ "No listeners for MessageManager");
+ assert.equal(topic in remoteListeners, false,
+ "No listeners for Remote Frame");
+
+ mm.addMessageListener(topic, listener);
+
+ assert.deepEqual(listeners[topic], [listener],
+ "Listener is added properly");
+ assert.equal(topic in remoteListeners, false,
+ "No listeners for Remote Frame");
+ }
+
+
+exports["test MessageManager addMessageListener with duplicates"] =
+ function(assert) {
+ let [mm, frame] = createMessageManager();
+ let topic = "message-topic";
+ let listeners = frame(mm).listeners;
+
+ let listener = function () {};
+
+ mm.addMessageListener(topic, listener);
+ mm.addMessageListener(topic, listener);
+ mm.addMessageListener(topic, listener);
+
+ assert.deepEqual(listeners[topic], [listener],
+ "Same listener is added only once");
+ }
+
+
+exports["test MessageManager addMessageListener exceptions"] =
+ function(assert) {
+ const BAD_LISTENER = "The event listener must be a function.";
+
+ let [mm, frame] = createMessageManager();
+ let listeners = frame(mm).listeners;
+ let topic = "message-topic";
+
+ assert.throws(
+ function() mm.addMessageListener(),
+ BAD_LISTENER
+ );
+
+ assert.throws(
+ function() mm.addMessageListener(topic),
+ BAD_LISTENER
+ );
+
+ assert.throws(
+ function() mm.addMessageListener(topic, "something-else"),
+ BAD_LISTENER
+ );
+ }
+
+exports["test MessageManager removeMessageListener"] =
+ function(assert) {
+ let [mm, frame] = createMessageManager();
+ let topic = "message-topic";
+ let listeners = frame(mm).listeners;
+
+ let listenerA = function () {};
+ let listenerB = function () {};
+ let listenerC = function () {};
+
+ mm.removeMessageListener(topic, listenerA);
+
+ assert.deepEqual(listeners, {},
+ "No listeners yet");
+
+ mm.addMessageListener(topic, listenerA);
+ mm.addMessageListener(topic, listenerB);
+ mm.addMessageListener(topic, listenerC);
+
+ mm.removeMessageListener(topic, listenerB);
+
+ assert.deepEqual(listeners[topic], [listenerA, listenerC],
+ "Listener is removed properly");
+ }
+
+
+exports["test MessageManager loadFrameScript with data URL"] =
+ function(assert) {
+ let [mm, frame] = createMessageManager();
+
+ let remoteFrame = frame(mm).receiver;
+
+ assert.equal("TEST_VALUE" in remoteFrame, false,
+ "TEST_VALUE is not defined in Remote Frame");
+
+ mm.loadFrameScript("data:, const TEST_VALUE = 77;", true);
+
+ assert.equal(remoteFrame.TEST_VALUE, 77,
+ "TEST_VALUE is properly defined in Remote Frame");
+ }
+
+
+exports["test MessageManager loadFrameScript with a File"] =
+ function(assert) {
+ let [mm, frame] = createMessageManager();
+
+ let remoteFrame = frame(mm).receiver;
+
+ assert.equal("TEST_VALUE" in remoteFrame, false,
+ "TEST_VALUE is not defined in Remote Frame");
+
+ mm.loadFrameScript(require("self").data.url("test-message-manager.js"), true);
+
+ assert.equal(remoteFrame.TEST_VALUE, 11,
+ "TEST_VALUE is properly defined in Remote Frame");
+ }
+
+exports["test MessageManager loadFrameScript exception"] =
+ function(assert) {
+ let [mm, frame] = createMessageManager();
+
+ let remoteFrame = frame(mm).receiver;
+
+
+ assert.throws(
+ function() mm.loadFrameScript("data:, const TEST_VALUE = 77;"),
+ "Not enough arguments"
+ );
+
+ }
+
+exports["test Remote Frame addMessageListener"] =
+ function(assert) {
+ let [mm, frame] = createMessageManager();
+ let remoteFrame = frame(mm).receiver;
+
+ let listeners = frame(remoteFrame).listeners;
+ let managerListeners = frame(mm).listeners;
+
+ let topic = "message-topic";
+
+ let listener = function () {};
+
+ assert.equal(topic in listeners, false,
+ "No listeners for Remote Frame");
+ assert.equal(topic in managerListeners, false,
+ "No listeners for MessageManager");
+
+ remoteFrame.addMessageListener(topic, listener);
+
+ assert.deepEqual(listeners[topic], [listener],
+ "Listener is added properly");
+ assert.equal(topic in managerListeners, false,
+ "No listeners for MessageManager");
+ }
+
+
+exports["test Remote Frame addMessageListener with duplicates"] =
+ function(assert) {
+ let [mm, frame] = createMessageManager();
+
+ let remoteFrame = frame(mm).receiver;
+ let listeners = frame(remoteFrame).listeners;
+ let topic = "message-topic";
+
+ let listener = function () {};
+
+ assert.equal(topic in listeners, false,
+ "No listeners in Remote Frame");
+
+ remoteFrame.addMessageListener(topic, listener);
+ remoteFrame.addMessageListener(topic, listener);
+ remoteFrame.addMessageListener(topic, listener);
+
+ assert.deepEqual(listeners[topic], [listener],
+ "Listener is added properly");
+ }
+
+
+exports["test Remote Frame addMessageListener exceptions"] =
+ function(assert) {
+ const BAD_LISTENER = "The event listener must be a function.";
+
+ let [mm, frame] = createMessageManager();
+ let remoteFrame = frame(mm).receiver;
+ let listeners = frame(remoteFrame).listeners;
+ let topic = "message-topic";
+
+ assert.throws(
+ function() mm.addMessageListener(),
+ BAD_LISTENER
+ );
+
+ assert.throws(
+ function() mm.addMessageListener(topic),
+ BAD_LISTENER
+ );
+
+ assert.throws(
+ function() mm.addMessageListener(topic, "something-else"),
+ BAD_LISTENER
+ );
+ }
+
+
+exports["test Remote Frame removeMessageListener"] =
+ function(assert) {
+ let [mm, frame] = createMessageManager();
+
+ let remoteFrame = frame(mm).receiver;
+ let listeners = frame(remoteFrame).listeners;
+
+ let topic = "message-topic";
+
+ let listenerA = function () {};
+ let listenerB = function () {};
+ let listenerC = function () {};
+
+ remoteFrame.removeMessageListener(topic, listenerA);
+
+ assert.deepEqual(listeners, {},
+ "No listeners yet");
+
+ remoteFrame.addMessageListener(topic, listenerA);
+ remoteFrame.addMessageListener(topic, listenerB);
+ remoteFrame.addMessageListener(topic, listenerC);
+
+ remoteFrame.removeMessageListener(topic, listenerB);
+
+ assert.deepEqual(listeners[topic], [listenerA, listenerC],
+ "Listener is removed properly");
+ }
+
+
+exports["test MessageManager sendAsyncMessage"] =
+ function(assert, done) {
+ let [mm, frame] = createMessageManager();
+
+ let remoteFrame = frame(mm).receiver;
+ let calls = 0;
+
+ let topic = "message-topic";
+
+ let listener = function(data) {
+ calls++;
+
+ assert.deepEqual(data, {
+ sync : false,
+ name : topic,
+ json : {foo : "bar"},
+ target : null
+ }, "Data received as expected");
+
+ assert.equal(calls, 1,
+ "Listener called once");
+
+ done();
+ }
+
+ remoteFrame.addMessageListener(topic, listener);
+
+ let response = mm.sendAsyncMessage(topic, {foo : "bar"});
+
+ assert.strictEqual(response, undefined,
+ "No response for async messages");
+
+ assert.equal(calls, 0,
+ "Listener not called yet");
+ }
+
+exports["test MessageManager sendAsyncMessage without listeners"] =
+ function(assert) {
+ let [mm, frame] = createMessageManager();
+
+ let remoteFrame = frame(mm).receiver;
+
+ let topic = "message-topic";
+
+ let response = mm.sendAsyncMessage(topic, {foo : "bar"});
+
+ assert.strictEqual(response, undefined,
+ "No response for async messages");
+ }
+
+
+exports["test MessageManager sendAsyncMessage without arguments"] =
+ function(assert, done) {
+ let [mm, frame] = createMessageManager();
+
+ let remoteFrame = frame(mm).receiver;
+ let calls = 0;
+
+ let topic = "message-topic";
+
+ let listener = function(data) {
+ calls++;
+
+ assert.deepEqual(data, {
+ sync : false,
+ name : topic,
+ json : null,
+ target : null
+ }, "Data received as expected");
+
+ assert.equal(calls, 1,
+ "Listener called once");
+
+ done();
+ }
+
+ remoteFrame.addMessageListener(topic, listener);
+
+ mm.sendAsyncMessage();
+
+ mm.sendAsyncMessage(topic);
+
+ assert.equal(calls, 0,
+ "Listener not called yet");
+ }
+
+
+exports["test Remote Frame sendAsyncMessage"] =
+ function(assert, done) {
+ let [mm, frame] = createMessageManager();
+
+ let remoteFrame = frame(mm).receiver;
+ let calls = 0;
+
+ let topic = "message-topic";
+
+ let listener = function(data) {
+ calls++;
+
+ assert.deepEqual(data, {
+ sync : false,
+ name : topic,
+ json : {foo : "bar"},
+ target : null
+ }, "Data received as expected");
+
+ assert.equal(calls, 1,
+ "Listener called once");
+
+ done();
+ }
+
+ mm.addMessageListener(topic, listener);
+
+ let response = remoteFrame.sendAsyncMessage(topic, {foo : "bar"});
+
+ assert.strictEqual(response, undefined,
+ "No response for async messages");
+
+ assert.equal(calls, 0,
+ "Listener not called yet");
+ }
+
+
+exports["test Remote Frame sendAsyncMessage without arguments"] =
+ function(assert, done) {
+ let [mm, frame] = createMessageManager();
+
+ let remoteFrame = frame(mm).receiver;
+ let calls = 0;
+
+ let topic = "message-topic";
+
+ let listener = function(data) {
+ calls++;
+
+ assert.deepEqual(data, {
+ sync : false,
+ name : topic,
+ json : null,
+ target : null
+ }, "Data received as expected");
+
+ assert.equal(calls, 1,
+ "Listener called once");
+
+ done();
+ }
+
+ mm.addMessageListener(topic, listener);
+
+ remoteFrame.sendAsyncMessage();
+
+ remoteFrame.sendAsyncMessage(topic);
+
+ assert.equal(calls, 0,
+ "Listener not called yet");
+ }
+
+exports["test Remote Frame sendAsyncMessage without listeners"] =
+ function(assert) {
+ let [mm, frame] = createMessageManager();
+
+ let remoteFrame = frame(mm).receiver;
+
+ let topic = "message-topic";
+
+ let response = remoteFrame.sendAsyncMessage(topic, {foo : "bar"});
+
+ assert.strictEqual(response, undefined,
+ "No response for async messages");
+ }
+
+exports["test Remote Frame sendSyncMessage"] =
+ function(assert) {
+ let [mm, frame] = createMessageManager();
+
+ let remoteFrame = frame(mm).receiver;
+
+ let topic = "message-topic";
+
+ let expectedData = {
+ sync : true,
+ name : topic,
+ json : {foo : "bar"},
+ target : null
+ }
+
+ let listenerA = function(data) {
+ assert.deepEqual(data, expectedData,
+ "Data received as expected");
+
+ return "my value";
+ }
+
+ let listenerB = function(data) {
+ assert.deepEqual(data, expectedData,
+ "Data received as expected");
+
+ return {complex : "object", method : function() "not allowed"};
+ }
+
+ let listenerC = function(data) {
+ assert.deepEqual(data, expectedData,
+ "Data received as expected");
+ }
+
+ mm.addMessageListener(topic, listenerA);
+ mm.addMessageListener(topic, listenerB);
+ mm.addMessageListener(topic, listenerC);
+
+ let response = remoteFrame.sendSyncMessage(topic, {foo : "bar"});
+
+ assert.deepEqual(response, ["my value", {complex : "object"}, undefined],
+ "Response from sync messages as expected");
+ }
+
+exports["test Remote Frame sendSyncMessage without arguments"] =
+ function(assert) {
+ let [mm, frame] = createMessageManager();
+
+ let remoteFrame = frame(mm).receiver;
+
+ let topic = "message-topic";
+
+ let expectedData = {
+ sync : true,
+ name : topic,
+ json : null,
+ target : null
+ }
+
+ let listener = function(data) {
+ assert.deepEqual(data, expectedData,
+ "Data received as expected");
+ }
+
+ mm.addMessageListener(topic, listener);
+
+ let response = remoteFrame.sendSyncMessage();
+
+ assert.deepEqual(response, [],
+ "Empty response as expected");
+
+ let response = remoteFrame.sendSyncMessage(topic);
+
+ assert.deepEqual(response, [undefined],
+ "Response from sync messages as expected");
+ }
+
+exports["test Remote Frame sendSyncMessage without listeners"] =
+ function(assert) {
+ let [mm, frame] = createMessageManager();
+
+ let remoteFrame = frame(mm).receiver;
+ let obj = {foo : "bar"};
+
+ let topic = "message-topic";
+
+ let response = remoteFrame.sendSyncMessage(topic, obj);
+
+ assert.deepEqual(response, [],
+ "Response from sync messages as expected");
+ }
+
+
+exports["test Message Manager / Remote Frame async pipeline"] =
+ function(assert, done) {
+ let [mm] = createMessageManager();
+
+ let expectedMessages = ["alpha:remote", "alpha", "omega:remote", "omega"];
+
+ mm.addMessageListener("handshake", function (data) {
+ let messages = data.json.concat("alpha");
+
+ mm.sendAsyncMessage("shutdown", messages);
+ });
+
+ mm.addMessageListener("shutdown", function (data) {
+ let messages = data.json.concat("omega");
+
+ assert.deepEqual(messages, expectedMessages,
+ "messages delivered in the expected order");
+
+ done();
+ });
+
+ mm.loadFrameScript(
+ "data:, \
+ addMessageListener('handshake', function (data) {\
+ let messages = data.json.concat('alpha:remote');\
+ sendAsyncMessage('handshake', messages);\
+ });\
+ addMessageListener('shutdown', function (data) {\
+ let messages = data.json.concat('omega:remote');\
+ sendAsyncMessage('shutdown', messages);\
+ });\
+ ", true);
+
+ mm.sendAsyncMessage("handshake", []);
+ }
+
+
+exports["test Message Manager / Remote Frame async / sync pipeline"] =
+ function(assert, done) {
+ let [mm] = createMessageManager();
+
+ let expectedMessages = ["alpha:remote", "alpha", "omega:remote", "omega"];
+
+ mm.addMessageListener("handshake",
+ function (data) data.json.concat("alpha")
+ );
+
+ mm.addMessageListener("shutdown",
+ function (data) data.json.concat("omega")
+ );
+
+ mm.addMessageListener("verify", function (data) {
+
+ assert.deepEqual(data.json, expectedMessages,
+ "messages delivered in the expected order");
+
+ done();
+ });
+
+ mm.loadFrameScript(
+ "data:, \
+ addMessageListener('handshake', function (data) {\
+ let messages = data.json.concat('alpha:remote');\
+ \
+ messages = sendSyncMessage('handshake', messages)[0];\
+ messages.push('omega:remote');\
+ messages = sendSyncMessage('shutdown', messages)[0];\
+ \
+ sendSyncMessage('verify', messages);\
+ });\
+ ", true);
+
+ mm.sendAsyncMessage("handshake", []);
+ }
+
+require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-modules.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-modules.js
new file mode 100644
index 0000000..2868560
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-modules.js
@@ -0,0 +1,148 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.testDefine = function(test) {
+ let tiger = require('./modules/tiger');
+ test.assertEqual(tiger.name, 'tiger', 'name proprety was exported properly');
+ test.assertEqual(tiger.type, 'cat', 'property form other module exported');
+};
+
+exports.testDefineInoresNonFactory = function(test) {
+ let mod = require('./modules/async2');
+ test.assertEqual(mod.name, 'async2', 'name proprety was exported properly');
+ test.assertNotEqual(mod.traditional2Name, 'traditional2', '1st is ignored');
+};
+/* Disable test that require AMD specific functionality:
+
+// define() that exports a function as the module value,
+// specifying a module name.
+exports.testDefExport = function(test) {
+ var add = require('modules/add');
+ test.assertEqual(add(1, 1), 2, 'Named define() exporting a function');
+};
+
+// define() that exports function as a value, but is anonymous
+exports.testAnonDefExport = function (test) {
+ var subtract = require('modules/subtract');
+ test.assertEqual(subtract(4, 2), 2,
+ 'Anonymous define() exporting a function');
+}
+
+// using require([], function () {}) to load modules.
+exports.testSimpleRequire = function (test) {
+ require(['modules/blue', 'modules/orange'], function (blue, orange) {
+ test.assertEqual(blue.name, 'blue', 'Simple require for blue');
+ test.assertEqual(orange.name, 'orange', 'Simple require for orange');
+ test.assertEqual(orange.parentType, 'color',
+ 'Simple require dependency check for orange');
+ });
+}
+
+// using nested require([]) calls.
+exports.testSimpleRequireNested = function (test) {
+ require(['modules/blue', 'modules/orange', 'modules/green'],
+ function (blue, orange, green) {
+
+ require(['modules/orange', 'modules/red'], function (orange, red) {
+ test.assertEqual(red.name, 'red', 'Simple require for red');
+ test.assertEqual(red.parentType, 'color',
+ 'Simple require dependency check for red');
+ test.assertEqual(blue.name, 'blue', 'Simple require for blue');
+ test.assertEqual(orange.name, 'orange', 'Simple require for orange');
+ test.assertEqual(orange.parentType, 'color',
+ 'Simple require dependency check for orange');
+ test.assertEqual(green.name, 'green', 'Simple require for green');
+ test.assertEqual(green.parentType, 'color',
+ 'Simple require dependency check for green');
+ });
+
+ });
+}
+
+// requiring a traditional module, that uses async, that use traditional and
+// async, with a circular reference
+exports.testMixedCircular = function (test) {
+ var t = require('modules/traditional1');
+ test.assertEqual(t.name, 'traditional1', 'Testing name');
+ test.assertEqual(t.traditional2Name, 'traditional2',
+ 'Testing dependent name');
+ test.assertEqual(t.traditional1Name, 'traditional1', 'Testing circular name');
+ test.assertEqual(t.async2Name, 'async2', 'Testing async2 name');
+ test.assertEqual(t.async2Traditional2Name, 'traditional2',
+ 'Testing nested traditional2 name');
+}
+
+// Testing define()(function(require) {}) with some that use exports,
+// some that use return.
+exports.testAnonExportsReturn = function (test) {
+ var lion = require('modules/lion');
+ require(['modules/tiger', 'modules/cheetah'], function (tiger, cheetah) {
+ test.assertEqual('lion', lion, 'Check lion name');
+ test.assertEqual('tiger', tiger.name, 'Check tiger name');
+ test.assertEqual('cat', tiger.type, 'Check tiger type');
+ test.assertEqual('cheetah', cheetah(), 'Check cheetah name');
+ });
+}
+
+// circular dependency
+exports.testCircular = function (test) {
+ var pollux = require('modules/pollux'),
+ castor = require('modules/castor');
+
+ test.assertEqual(pollux.name, 'pollux', 'Pollux\'s name');
+ test.assertEqual(pollux.getCastorName(),
+ 'castor', 'Castor\'s name from Pollux.');
+ test.assertEqual(castor.name, 'castor', 'Castor\'s name');
+ test.assertEqual(castor.getPolluxName(), 'pollux',
+ 'Pollux\'s name from Castor.');
+}
+
+// test a bad module that asks for exports but also does a define() return
+exports.testBadExportAndReturn = function (test) {
+ var passed = false;
+ try {
+ var bad = require('modules/badExportAndReturn');
+ } catch(e) {
+ passed = /cannot use exports and also return/.test(e.toString());
+ }
+ test.assertEqual(passed, true, 'Make sure exports and return fail');
+}
+
+// test a bad circular dependency, where an exported value is needed, but
+// the return value happens too late, a module already asked for the exported
+// value.
+exports.testBadExportAndReturnCircular = function (test) {
+ var passed = false;
+ try {
+ var bad = require('modules/badFirst');
+ } catch(e) {
+ passed = /after another module has referenced its exported value/
+ .test(e.toString());
+ }
+ test.assertEqual(passed, true, 'Make sure return after an exported ' +
+ 'value is grabbed by another module fails.');
+}
+
+// only allow one define call per file.
+exports.testOneDefine = function (test) {
+ var passed = false;
+ try {
+ var dupe = require('modules/dupe');
+ } catch(e) {
+ passed = /Only one call to define/.test(e.toString());
+ }
+ test.assertEqual(passed, true, 'Only allow one define call per module');
+}
+
+// only allow one define call per file, testing a bad nested define call.
+exports.testOneDefineNested = function (test) {
+ var passed = false;
+ try {
+ var dupe = require('modules/dupeNested');
+ } catch(e) {
+ passed = /Only one call to define/.test(e.toString());
+ }
+ test.assertEqual(passed, true, 'Only allow one define call per module');
+}
+*/
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-namespace.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-namespace.js
new file mode 100644
index 0000000..cb69bb0
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-namespace.js
@@ -0,0 +1,95 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+let { Namespace, ns } = require("api-utils/namespace");
+let { Cc, Ci, Cu } = require("chrome");
+let { setTimeout } = require("api-utils/timer")
+
+exports["test post GC references"] = function (assert, done) {
+ // Test temporary workaround for a bug 673468.
+ var target = {}, local = ns()
+ local(target).there = true
+
+ assert.equal(local(target).there, true, "namespaced preserved");
+
+ setTimeout(function() {
+ Cu.forceGC();
+ assert.equal(local(target).there, true, "namespace is preserved post GC");
+ done();
+ }, 300);
+};
+
+exports["test namsepace basics"] = function(assert) {
+ var privates = Namespace();
+ var object = { foo: function foo() { return "hello foo"; } };
+
+ assert.notEqual(privates(object), object,
+ "namespaced object is not the same");
+ assert.ok(!('foo' in privates(object)),
+ "public properties are not in the namespace");
+
+ assert.equal(privates(object), privates(object),
+ "same namespaced object is returned on each call");
+};
+
+exports["test namespace overlays"] = function(assert) {
+ var _ = new Namespace();
+ var object = { foo: 'foo' };
+
+ _(object).foo = 'bar';
+
+ assert.equal(_(object).foo, "bar",
+ "namespaced property `foo` changed value");
+
+ assert.equal(object.foo, "foo",
+ "public property `foo` has original value");
+
+ object.foo = "baz";
+ assert.equal(_(object).foo, "bar",
+ "property changes do not affect namespaced properties");
+
+ object.bar = "foo";
+ assert.ok(!("bar" in _(object)),
+ "new public properties are not reflected in namespace");
+};
+
+exports["test shared namespaces"] = function(assert) {
+ var _ = new Namespace({ hello: 'hello world' });
+
+ var f1 = { hello: 1 };
+ var f2 = { foo: 'foo' };
+
+ assert.equal(_(f1).hello, _(f2).hello, "namespace can be shared");
+ assert.notEqual(f1.hello, _(f1).hello, "shared namespace can overlay");
+ assert.notEqual(f2.hello, _(f2).hello, "target is not affected");
+
+ _(f1).hello = 2;
+
+ assert.notEqual(_(f1).hello, _(f2).hello,
+ "namespaced property can be overided");
+ assert.equal(_(f2).hello, _({}).hello, "namespace does not change");
+};
+
+exports["test multi namespace"] = function(assert) {
+ var n1 = new Namespace();
+ var n2 = new Namespace();
+ var object = { baz: 1 };
+ n1(object).foo = 1;
+ n2(object).foo = 2;
+ n1(object).bar = n2(object).bar = 3;
+
+ assert.notEqual(n1(object).foo, n2(object).foo,
+ "object can have multiple namespaces");
+ assert.equal(n1(object).bar, n2(object).bar,
+ "object can have matching props in diff namespaces");
+};
+
+exports["test ns alias"] = function(assert) {
+ assert.strictEqual(ns, Namespace,
+ "ns is an alias of Namespace");
+}
+
+require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-observer-service.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-observer-service.js
new file mode 100644
index 0000000..222ae22
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-observer-service.js
@@ -0,0 +1,77 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var observers = require("api-utils/observer-service");
+var {Cc,Ci} = require("chrome");
+const { Loader } = require("./helpers");
+
+exports.testUnloadAndErrorLogging = function(test) {
+ var prints = [];
+ var loader = Loader(module, { dump: function print(message) {
+ prints.push(message);
+ }});
+ var sbobsvc = loader.require("api-utils/observer-service");
+
+ var timesCalled = 0;
+ var cb = function(subject, data) {
+ timesCalled++;
+ };
+ var badCb = function(subject, data) {
+ throw new Error("foo");
+ };
+ sbobsvc.add("blarg", cb);
+ observers.notify("blarg", "yo yo");
+ test.assertEqual(timesCalled, 1);
+ sbobsvc.add("narg", badCb);
+ observers.notify("narg", "yo yo");
+ var lines = prints[0].split("\n");
+ test.assertEqual(lines[0], "error: An exception occurred.");
+ test.assertEqual(lines[1], "Traceback (most recent call last):");
+ test.assertEqual(lines.slice(-2)[0], "Error: foo");
+
+ loader.unload();
+ observers.notify("blarg", "yo yo");
+ test.assertEqual(timesCalled, 1);
+};
+
+exports.testObserverService = function(test) {
+ var ios = Cc['@mozilla.org/network/io-service;1']
+ .getService(Ci.nsIIOService);
+ var service = Cc["@mozilla.org/observer-service;1"].
+ getService(Ci.nsIObserverService);
+ var uri = ios.newURI("http://www.foo.com", null, null);
+ var timesCalled = 0;
+ var lastSubject = null;
+ var lastData = null;
+
+ var cb = function(subject, data) {
+ timesCalled++;
+ lastSubject = subject;
+ lastData = data;
+ };
+
+ observers.add("blarg", cb);
+ service.notifyObservers(uri, "blarg", "some data");
+ test.assertEqual(timesCalled, 1,
+ "observer-service.add() should call callback");
+ test.assertEqual(lastSubject, uri,
+ "observer-service.add() should pass subject");
+ test.assertEqual(lastData, "some data",
+ "observer-service.add() should pass data");
+
+ function customSubject() {}
+ function customData() {}
+ observers.notify("blarg", customSubject, customData);
+ test.assertEqual(timesCalled, 2,
+ "observer-service.notify() should work");
+ test.assertEqual(lastSubject, customSubject,
+ "observer-service.notify() should pass+wrap subject");
+ test.assertEqual(lastData, customData,
+ "observer-service.notify() should pass data");
+
+ observers.remove("blarg", cb);
+ service.notifyObservers(null, "blarg", "some data");
+ test.assertEqual(timesCalled, 2,
+ "observer-service.remove() should work");
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-passwords-utils.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-passwords-utils.js
new file mode 100644
index 0000000..ab758ed
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-passwords-utils.js
@@ -0,0 +1,142 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { store, search, remove } = require("passwords/utils");
+
+exports["test store requires `password` field"] = function(assert) {
+ assert.throws(function() {
+ store({ username: "foo", realm: "bar" });
+ }, "`password` is required");
+};
+
+exports["test store requires `username` field"] = function(assert) {
+ assert.throws(function() {
+ store({ password: "foo", realm: "bar" });
+ }, "`username` is required");
+};
+
+exports["test store requires `realm` field"] = function(assert) {
+ assert.throws(function() {
+ store({ username: "foo", password: "bar" });
+ }, "`password` is required");
+};
+
+exports["test can't store same login twice"] = function(assert) {
+ let options = { username: "user", password: "pass", realm: "realm" };
+ store(options);
+ assert.throws(function() {
+ store(options);
+ }, "can't store same pass twice");
+ remove(options);
+};
+
+exports["test remove throws if no login found"] = function(assert) {
+ assert.throws(function() {
+ remove({ username: "foo", password: "bar", realm: "baz" });
+ }, "can't remove unstored credentials");
+};
+
+exports["test addon associated credentials"] = function(assert) {
+ let options = { username: "foo", password: "bar", realm: "baz" };
+ store(options);
+
+ assert.ok(search().length, "credential was stored");
+ assert.ok(search(options).length, "stored credential found");
+ assert.ok(search({ username: options.username }).length, "found by username");
+ assert.ok(search({ password: options.password }).length, "found by password");
+ assert.ok(search({ realm: options.realm }).length, "found by realm");
+
+ let credential = search(options)[0];
+ assert.equal(credential.url.indexOf("addon:"), 0,
+ "`addon:` uri is used for add-on associated credentials");
+ assert.equal(credential.username, options.username, "username matches");
+ assert.equal(credential.password, options.password, "password matches");
+ assert.equal(credential.realm, options.realm, "realm matches");
+ assert.equal(credential.formSubmitURL, null,
+ "`formSubmitURL` is `null` for add-on associated credentials");
+ assert.equal(credential.usernameField, "", "usernameField is empty");
+ assert.equal(credential.passwordField, "", "passwordField is empty");
+
+ remove(search(options)[0]);
+ assert.ok(!search(options).length, "remove worked");
+};
+
+exports["test web page associated credentials"] = function(assert) {
+ let options = {
+ url: "http://www.example.com",
+ formSubmitURL: "http://login.example.com",
+ username: "user",
+ password: "pass",
+ usernameField: "user-f",
+ passwordField: "pass-f"
+ };
+ store({
+ url: "http://www.example.com/login",
+ formSubmitURL: "http://login.example.com/foo/authenticate.cgi",
+ username: options.username,
+ password: options.password,
+ usernameField: options.usernameField,
+ passwordField: options.passwordField
+ });
+
+ assert.ok(search().length, "credential was stored");
+ assert.ok(search(options).length, "stored credential found");
+ assert.ok(search({ username: options.username }).length, "found by username");
+ assert.ok(search({ password: options.password }).length, "found by password");
+ assert.ok(search({ formSubmitURL: options.formSubmitURL }).length,
+ "found by formSubmitURL");
+ assert.ok(search({ usernameField: options.usernameField }).length,
+ "found by usernameField");
+ assert.ok(search({ passwordField: options.passwordField }).length,
+ "found by passwordField");
+
+ let credential = search(options)[0];
+ assert.equal(credential.url, options.url, "url matches");
+ assert.equal(credential.username, options.username, "username matches");
+ assert.equal(credential.password, options.password, "password matches");
+ assert.equal(credential.realm, null, "realm is ");
+ assert.equal(credential.formSubmitURL, options.formSubmitURL,
+ "`formSubmitURL` matches");
+ assert.equal(credential.usernameField, options.usernameField,
+ "usernameField matches");
+ assert.equal(credential.passwordField, options.passwordField,
+ "passwordField matches");
+
+ remove(search(options)[0]);
+ assert.ok(!search(options).length, "remove worked");
+};
+
+exports["test site authentication credentials"] = function(assert) {
+ let options = {
+ url: "http://test.authentication.com",
+ username: "u",
+ password: "p",
+ realm: "r"
+ };
+
+ store(options);
+ assert.ok(search().length, "credential was stored");
+ assert.ok(search(options).length, "stored credential found");
+ assert.ok(search({ username: options.username }).length, "found by username");
+ assert.ok(search({ password: options.password }).length, "found by password");
+ assert.ok(search({ realm: options.realm }).length, "found by realm");
+ assert.ok(search({ url: options.url }).length, "found by url");
+
+ let credential = search(options)[0];
+ assert.equal(credential.url, options.url, "url matches");
+ assert.equal(credential.username, options.username, "username matches");
+ assert.equal(credential.password, options.password, "password matches");
+ assert.equal(credential.realm, options.realm, "realm matches");
+ assert.equal(credential.formSubmitURL, null,
+ "`formSubmitURL` is `null` for site authentication credentials");
+ assert.equal(credential.usernameField, "", "usernameField is empty");
+ assert.equal(credential.passwordField, "", "passwordField is empty");
+
+ remove(search(options)[0]);
+ assert.ok(!search(options).length, "remove worked");
+};
+
+require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-plain-text-console.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-plain-text-console.js
new file mode 100644
index 0000000..40fb519
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-plain-text-console.js
@@ -0,0 +1,68 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.testPlainTextConsole = function(test) {
+ var prints = [];
+ function print(message) {
+ prints.push(message);
+ }
+ function lastPrint() {
+ var last = prints.slice(-1)[0];
+ prints = [];
+ return last;
+ }
+
+ var Console = require("plain-text-console").PlainTextConsole;
+ var con = new Console(print);
+
+ test.pass("PlainTextConsole instantiates");
+
+ con.log('testing', 1, [2, 3, 4]);
+ test.assertEqual(lastPrint(), "info: testing 1 2,3,4\n",
+ "PlainTextConsole.log() must work.");
+
+ con.info('testing', 1, [2, 3, 4]);
+ test.assertEqual(lastPrint(), "info: testing 1 2,3,4\n",
+ "PlainTextConsole.info() must work.");
+
+ con.warn('testing', 1, [2, 3, 4]);
+ test.assertEqual(lastPrint(), "warning: testing 1 2,3,4\n",
+ "PlainTextConsole.warn() must work.");
+
+ con.error('testing', 1, [2, 3, 4]);
+ test.assertEqual(lastPrint(), "error: testing 1 2,3,4\n",
+ "PlainTextConsole.error() must work.");
+
+ con.debug('testing', 1, [2, 3, 4]);
+ test.assertEqual(lastPrint(), "debug: testing 1 2,3,4\n",
+ "PlainTextConsole.debug() must work.");
+
+ con.log('testing', undefined);
+ test.assertEqual(lastPrint(), "info: testing undefined\n",
+ "PlainTextConsole.log() must stringify undefined.");
+
+ con.log('testing', null);
+ test.assertEqual(lastPrint(), "info: testing null\n",
+ "PlainTextConsole.log() must stringify null.");
+
+ con.log("testing", { toString: function() "obj.toString()" });
+ test.assertEqual(lastPrint(), "info: testing obj.toString()\n",
+ "PlainTextConsole.log() must stringify custom toString.");
+
+ con.log("testing", { toString: function() { throw "fail!"; } });
+ test.assertEqual(lastPrint(), "info: testing <toString() error>\n",
+ "PlainTextConsole.log() must stringify custom bad toString.");
+
+ con.exception(new Error("blah"));
+ var tbLines = prints[0].split("\n");
+ test.assertEqual(tbLines[0], "error: An exception occurred.");
+ test.assertEqual(tbLines[1], "Traceback (most recent call last):");
+ test.assertEqual(tbLines.slice(-2)[0], "Error: blah");
+
+ prints = [];
+ con.trace();
+ tbLines = prints[0].split("\n");
+ test.assertEqual(tbLines[0], "info: Traceback (most recent call last):");
+ test.assertEqual(tbLines.slice(-2)[0].trim(), "con.trace();");
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-preferences-service.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-preferences-service.js
new file mode 100644
index 0000000..857357e
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-preferences-service.js
@@ -0,0 +1,112 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const prefs = require("preferences-service");
+const { Cc, Ci, Cu } = require("chrome");
+const BundleService = Cc["@mozilla.org/intl/stringbundle;1"].getService(Ci.nsIStringBundleService);
+
+exports.testReset = function(test) {
+ prefs.reset("test_reset_pref");
+ test.assertEqual(prefs.has("test_reset_pref"), false);
+ test.assertEqual(prefs.isSet("test_reset_pref"), false);
+ prefs.set("test_reset_pref", 5);
+ test.assertEqual(prefs.has("test_reset_pref"), true);
+ test.assertEqual(prefs.isSet("test_reset_pref"), true);
+};
+
+exports.testGetAndSet = function(test) {
+ let svc = Cc["@mozilla.org/preferences-service;1"].
+ getService(Ci.nsIPrefService).
+ getBranch(null);
+ svc.setCharPref("test_get_string_pref", "a normal string");
+ test.assertEqual(prefs.get("test_get_string_pref"), "a normal string",
+ "preferences-service should read from " +
+ "application-wide preferences service");
+
+ prefs.set("test_set_get_pref.integer", 1);
+ test.assertEqual(prefs.get("test_set_get_pref.integer"), 1,
+ "set/get integer preference should work");
+
+ prefs.set("test_set_get_number_pref", 42);
+ test.assertRaises(
+ function() { prefs.set("test_set_get_number_pref", 3.14159); },
+ "cannot store non-integer number: 3.14159",
+ "setting a float preference should raise an error"
+ );
+ test.assertEqual(prefs.get("test_set_get_number_pref"), 42,
+ "bad-type write attempt should not overwrite");
+
+ // 0x80000000 (no), 0x7fffffff (yes), -0x80000000 (yes), -0x80000001 (no)
+ test.assertRaises(
+ function() { prefs.set("test_set_get_number_pref", Math.pow(2, 31)); },
+ ("you cannot set the test_set_get_number_pref pref to the number " +
+ "2147483648, as number pref values must be in the signed 32-bit " +
+ "integer range -(2^31) to 2^31-1. To store numbers outside that " +
+ "range, store them as strings."),
+ "setting an int pref outside the range -(2^31) to 2^31-1 shouldn't work"
+ );
+ test.assertEqual(prefs.get("test_set_get_number_pref"), 42,
+ "out-of-range write attempt should not overwrite 1");
+ prefs.set("test_set_get_number_pref", Math.pow(2, 31)-1);
+ test.assertEqual(prefs.get("test_set_get_number_pref"), 0x7fffffff,
+ "in-range write attempt should work 1");
+ prefs.set("test_set_get_number_pref", -Math.pow(2, 31));
+ test.assertEqual(prefs.get("test_set_get_number_pref"), -0x80000000,
+ "in-range write attempt should work 2");
+ test.assertRaises(
+ function() { prefs.set("test_set_get_number_pref", -0x80000001); },
+ ("you cannot set the test_set_get_number_pref pref to the number " +
+ "-2147483649, as number pref values must be in the signed 32-bit " +
+ "integer range -(2^31) to 2^31-1. To store numbers outside that " +
+ "range, store them as strings."),
+ "setting an int pref outside the range -(2^31) to 2^31-1 shouldn't work"
+ );
+ test.assertEqual(prefs.get("test_set_get_number_pref"), -0x80000000,
+ "out-of-range write attempt should not overwrite 2");
+
+
+ prefs.set("test_set_get_pref.string", "foo");
+ test.assertEqual(prefs.get("test_set_get_pref.string"), "foo",
+ "set/get string preference should work");
+
+ prefs.set("test_set_get_pref.boolean", true);
+ test.assertEqual(prefs.get("test_set_get_pref.boolean"), true,
+ "set/get boolean preference should work");
+
+ prefs.set("test_set_get_unicode_pref", String.fromCharCode(960));
+ test.assertEqual(prefs.get("test_set_get_unicode_pref"),
+ String.fromCharCode(960),
+ "set/get unicode preference should work");
+
+ var unsupportedValues = [null, [], undefined];
+ unsupportedValues.forEach(
+ function(value) {
+ test.assertRaises(
+ function() { prefs.set("test_set_pref", value); },
+ ("can't set pref test_set_pref to value '" + value + "'; " +
+ "it isn't a string, integer, or boolean"),
+ "Setting a pref to " + uneval(value) + " should raise error"
+ );
+ });
+};
+
+exports.testGetSetLocalized = function(test) {
+ let prefName = "general.useragent.locale";
+
+ // Ensure that "general.useragent.locale" is a 'localized' pref
+ let bundleURL = "chrome://global/locale/intl.properties";
+ prefs.setLocalized(prefName, bundleURL);
+
+ // Fetch the expected value directly from the property file
+ let expectedValue = BundleService.createBundle(bundleURL).
+ GetStringFromName(prefName).
+ toLowerCase();
+
+ test.assertEqual(prefs.getLocalized(prefName).toLowerCase(),
+ expectedValue,
+ "get localized preference");
+
+ // Undo our modification
+ prefs.reset(prefName);
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-process.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-process.js
new file mode 100644
index 0000000..43d0864
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-process.js
@@ -0,0 +1,36 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Loader } = require("./helpers");
+const { jetpackID } = require('@packaging');
+
+// bug 707562: '#' char in packaging was causing loader to be undefined
+exports.testBug707562 = function(test) {
+ test.waitUntilDone();
+
+ let packaging = JSON.parse(JSON.stringify(require("@packaging")));
+ packaging.metadata["api-utils"].author = "###";
+
+ let loader = Loader(module, {}, packaging);
+ let process = loader.require("process");
+
+ // has spawn?
+ test.assert(process.spawn, "'process' module exports 'spawn' method.");
+
+ let promise = process.spawn("testID", "");
+ test.assertFunction(promise, "spawn makes a promise.");
+
+ promise(function(addon) {
+ addon.channel("TEST:LOADED").input(function(data) {
+ test.assert(data, "The loader was successfully created!");
+ loader.unload();
+ test.done();
+ });
+
+ addon.loadScript('data:,sendAsyncMessage("'+jetpackID+':TEST:LOADED", !!this.loader);', false);
+ test.pass("spawn's promise was delivered! (which means a addon process object is available)).");
+ });
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-promise.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-promise.js
new file mode 100644
index 0000000..fc7706f
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-promise.js
@@ -0,0 +1,311 @@
+/* vim:set ts=2 sw=2 sts=2 expandtab */
+/*jshint asi: true undef: true es5: true node: true devel: true
+ forin: true */
+/*global define: true */
+
+'use strict';
+
+var core = require('api-utils/promise'),
+ defer = core.defer, resolve = core.resolve, reject = core.reject,
+ promised = core.promised
+
+exports['test all observers are notified'] = function(assert, done) {
+ var expected = 'Taram pam param!'
+ var deferred = defer()
+ var pending = 10, i = 0
+
+ function resolved(value) {
+ assert.equal(value, expected, 'value resolved as expected: #' + pending)
+ if (!--pending) done()
+ }
+
+ while (i++ < pending) deferred.promise.then(resolved)
+
+ deferred.resolve(expected)
+}
+
+exports['test exceptions dont stop notifications'] = function(assert, done) {
+ var threw = false, boom = Error('Boom!')
+ var deferred = defer()
+
+ var promise2 = deferred.promise.then(function() {
+ threw = true
+ throw boom
+ })
+
+ deferred.promise.then(function() {
+ assert.ok(threw, 'observer is called even though previos one threw')
+ promise2.then(function() {
+ assert.fail('should not resolve')
+ }, function(reason) {
+ assert.equal(reason, boom, 'rejects to thrown error')
+ done()
+ })
+ })
+
+ deferred.resolve('go!')
+}
+
+exports['test subsequent resolves are ignored'] = function(assert, done) {
+ var deferred = defer()
+ deferred.resolve(1)
+ deferred.resolve(2)
+ deferred.reject(3)
+
+ deferred.promise.then(function(actual) {
+ assert.equal(actual, 1, 'resolves to first value')
+ }, function() {
+ assert.fail('must not reject')
+ })
+ deferred.promise.then(function(actual) {
+ assert.equal(actual, 1, 'subsequent resolutions are ignored')
+ done()
+ }, function() {
+ assert.fail('must not reject')
+ })
+}
+
+exports['test subsequent rejections are ignored'] = function(assert, done) {
+ var deferred = defer()
+ deferred.reject(1)
+ deferred.resolve(2)
+ deferred.reject(3)
+
+ deferred.promise.then(function(actual) {
+ assert.fail('must not resolve')
+ }, function(actual) {
+ assert.equal(actual, 1, 'must reject to first')
+ })
+ deferred.promise.then(function(actual) {
+ assert.fail('must not resolve')
+ }, function(actual) {
+ assert.equal(actual, 1, 'must reject to first')
+ done()
+ })
+}
+
+exports['test error recovery'] = function(assert, done) {
+ var boom = Error('Boom!')
+ var deferred = defer()
+
+ deferred.promise.then(function() {
+ assert.fail('rejected promise should not resolve')
+ }, function(reason) {
+ assert.equal(reason, boom, 'rejection reason delivered')
+ return 'recovery'
+ }).then(function(value) {
+ assert.equal(value, 'recovery', 'error handled by a handler')
+ done()
+ })
+
+ deferred.reject(boom)
+}
+
+
+exports['test error recovery with promise'] = function(assert, done) {
+ var deferred = defer()
+
+ deferred.promise.then(function() {
+ assert.fail('must reject')
+ }, function(actual) {
+ assert.equal(actual, 'reason', 'rejected')
+ var deferred = defer()
+ deferred.resolve('recovery')
+ return deferred.promise
+ }).then(function(actual) {
+ assert.equal(actual, 'recovery', 'recorvered via promise')
+ var deferred = defer()
+ deferred.reject('error')
+ return deferred.promise
+ }).then(null, function(actual) {
+ assert.equal(actual, 'error', 'rejected via promise')
+ var deferred = defer()
+ deferred.reject('end')
+ return deferred.promise
+ }).then(null, function(actual) {
+ assert.equal(actual, 'end', 'rejeced via promise')
+ done()
+ })
+
+ deferred.reject('reason')
+}
+
+exports['test propagation'] = function(assert, done) {
+ var d1 = defer(), d2 = defer(), d3 = defer()
+
+ d1.promise.then(function(actual) {
+ assert.equal(actual, 'expected', 'resolves to expected value')
+ done()
+ })
+
+ d1.resolve(d2.promise)
+ d2.resolve(d3.promise)
+ d3.resolve('expected')
+}
+
+exports['test chaining'] = function(assert, done) {
+ var boom = Error('boom'), brax = Error('braxXXx')
+ var deferred = defer()
+
+ deferred.promise.then().then().then(function(actual) {
+ assert.equal(actual, 2, 'value propagates unchanged')
+ return actual + 2
+ }).then(null, function(reason) {
+ assert.fail('should not reject')
+ }).then(function(actual) {
+ assert.equal(actual, 4, 'value propagates through if not handled')
+ throw boom
+ }).then(function(actual) {
+ assert.fail('exception must reject promise')
+ }).then().then(null, function(actual) {
+ assert.equal(actual, boom, 'reason propagates unchanged')
+ throw brax
+ }).then().then(null, function(actual) {
+ assert.equal(actual, brax, 'reason changed becase of exception')
+ return 'recovery'
+ }).then(function(actual) {
+ assert.equal(actual, 'recovery', 'recovered from error')
+ done()
+ })
+
+ deferred.resolve(2)
+}
+
+
+exports['test reject'] = function(assert, done) {
+ var expected = Error('boom')
+
+ reject(expected).then(function() {
+ assert.fail('should reject')
+ }, function(actual) {
+ assert.equal(actual, expected, 'rejected with expected reason')
+ }).then(function() {
+ done()
+ })
+}
+
+exports['test resolve to rejected'] = function(assert, done) {
+ var expected = Error('boom')
+ var deferred = defer()
+
+ deferred.promise.then(function() {
+ assert.fail('should reject')
+ }, function(actual) {
+ assert.equal(actual, expected, 'rejected with expected failure')
+ }).then(function() {
+ done()
+ })
+
+ deferred.resolve(reject(expected))
+}
+
+exports['test resolve'] = function(assert, done) {
+ var expected = 'value'
+ resolve(expected).then(function(actual) {
+ assert.equal(actual, expected, 'resolved as expected')
+ }).then(function() {
+ done()
+ })
+}
+
+exports['test resolve with prototype'] = function(assert, done) {
+ var seventy = resolve(70, {
+ subtract: function subtract(y) {
+ return this.then(function(x) { return x - y })
+ }
+ })
+
+ seventy.subtract(17).then(function(actual) {
+ assert.equal(actual, 70 - 17, 'resolves to expected')
+ done()
+ })
+}
+
+exports['test promised with normal args'] = function(assert, done) {
+ var sum = promised(function(x, y) { return x + y })
+
+ sum(7, 8).then(function(actual) {
+ assert.equal(actual, 7 + 8, 'resolves as expected')
+ done()
+ })
+}
+
+exports['test promised with promise args'] = function(assert, done) {
+ var sum = promised(function(x, y) { return x + y })
+ var deferred = defer()
+
+ sum(11, deferred.promise).then(function(actual) {
+ assert.equal(actual, 11 + 24, 'resolved as expected')
+ done()
+ })
+
+ deferred.resolve(24)
+}
+
+exports['test promised with prototype'] = function(assert, done) {
+ var deferred = defer()
+ var numeric = {}
+ numeric.subtract = promised(function(y) { return this - y }, numeric)
+
+ var sum = promised(function(x, y) { return x + y }, numeric)
+
+ sum(7, 70).
+ subtract(14).
+ subtract(deferred.promise).
+ subtract(5).
+ then(function(actual) {
+ assert.equal(actual, 7 + 70 - 14 - 23 - 5, 'resolved as expected')
+ done()
+ })
+
+ deferred.resolve(23)
+}
+
+exports['test promised error handleing'] = function(assert, done) {
+ var expected = Error('boom')
+ var f = promised(function() {
+ throw expected
+ })
+
+ f().then(function() {
+ assert.fail('should reject')
+ }, function(actual) {
+ assert.equal(actual, expected, 'rejected as expected')
+ done()
+ })
+}
+
+exports['test return promise form promised'] = function(assert, done) {
+ var f = promised(function() {
+ return resolve(17)
+ })
+
+ f().then(function(actual) {
+ assert.equal(actual, 17, 'resolves to a promise resolution')
+ done()
+ })
+}
+
+exports['test promised returning failure'] = function(assert, done) {
+ var expected = Error('boom')
+ var f = promised(function() {
+ return reject(expected)
+ })
+
+ f().then(function() {
+ assert.fail('must reject')
+ }, function(actual) {
+ assert.equal(actual, expected, 'rejects with expected reason')
+ done()
+ })
+}
+
+exports['test promised are greedy'] = function(assert, done) {
+ var runs = 0
+ var f = promised(function() { ++runs })
+ var promise = f()
+ assert.equal(runs, 1, 'promised runs task right away')
+ done()
+}
+
+require("test").run(exports)
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-querystring.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-querystring.js
new file mode 100644
index 0000000..30b2729
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-querystring.js
@@ -0,0 +1,206 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+"use strict";
+
+// test using assert
+var qs = require('api-utils/querystring');
+
+// folding block, commented to pass gjslint
+// {{{
+// [ wonkyQS, canonicalQS, obj ]
+var qsTestCases = [
+ ['foo=918854443121279438895193',
+ 'foo=918854443121279438895193',
+ {'foo': '918854443121279438895193'}],
+ ['foo=bar', 'foo=bar', {'foo': 'bar'}],
+ //['foo=bar&foo=quux', 'foo=bar&foo=quux', {'foo': ['bar', 'quux']}],
+ ['foo=1&bar=2', 'foo=1&bar=2', {'foo': '1', 'bar': '2'}],
+ // ['my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F',
+ // 'my%20weird%20field=q1!2%22\'w%245%267%2Fz8)%3F',
+ // {'my weird field': 'q1!2"\'w$5&7/z8)?' }],
+ ['foo%3Dbaz=bar', 'foo%3Dbaz=bar', {'foo=baz': 'bar'}],
+ ['foo=baz=bar', 'foo=baz%3Dbar', {'foo': 'baz=bar'}],
+ /*
+ ['str=foo&arr=1&arr=2&arr=3&somenull=&undef=',
+ 'str=foo&arr=1&arr=2&arr=3&somenull=&undef=',
+ { 'str': 'foo',
+ 'arr': ['1', '2', '3'],
+ 'somenull': '',
+ 'undef': ''}],
+ */
+ //[' foo = bar ', '%20foo%20=%20bar%20', {' foo ': ' bar '}],
+ // disable test that fails ['foo=%zx', 'foo=%25zx', {'foo': '%zx'}],
+ ['foo=%EF%BF%BD', 'foo=%EF%BF%BD', {'foo': '\ufffd' }]
+];
+
+// [ wonkyQS, canonicalQS, obj ]
+var qsColonTestCases = [
+ ['foo:bar', 'foo:bar', {'foo': 'bar'}],
+ //['foo:bar;foo:quux', 'foo:bar;foo:quux', {'foo': ['bar', 'quux']}],
+ ['foo:1&bar:2;baz:quux',
+ 'foo:1%26bar%3A2;baz:quux',
+ {'foo': '1&bar:2', 'baz': 'quux'}],
+ ['foo%3Abaz:bar', 'foo%3Abaz:bar', {'foo:baz': 'bar'}],
+ ['foo:baz:bar', 'foo:baz%3Abar', {'foo': 'baz:bar'}]
+];
+
+// [wonkyObj, qs, canonicalObj]
+var extendedFunction = function() {};
+extendedFunction.prototype = {a: 'b'};
+var qsWeirdObjects = [
+ //[{regexp: /./g}, 'regexp=', {'regexp': ''}],
+ //[{regexp: new RegExp('.', 'g')}, 'regexp=', {'regexp': ''}],
+ //[{fn: function() {}}, 'fn=', {'fn': ''}],
+ //[{fn: new Function('')}, 'fn=', {'fn': ''}],
+ //[{math: Math}, 'math=', {'math': ''}],
+ //[{e: extendedFunction}, 'e=', {'e': ''}],
+ //[{d: new Date()}, 'd=', {'d': ''}],
+ //[{d: Date}, 'd=', {'d': ''}],
+ //[{f: new Boolean(false), t: new Boolean(true)}, 'f=&t=', {'f': '', 't': ''}],
+ [{f: false, t: true}, 'f=false&t=true', {'f': 'false', 't': 'true'}],
+ //[{n: null}, 'n=', {'n': ''}],
+ //[{nan: NaN}, 'nan=', {'nan': ''}],
+ //[{inf: Infinity}, 'inf=', {'inf': ''}]
+];
+// }}}
+
+var qsNoMungeTestCases = [
+ ['', {}],
+ //['foo=bar&foo=baz', {'foo': ['bar', 'baz']}],
+ ['blah=burp', {'blah': 'burp'}],
+ //['gragh=1&gragh=3&goo=2', {'gragh': ['1', '3'], 'goo': '2'}],
+ ['frappucino=muffin&goat%5B%5D=scone&pond=moose',
+ {'frappucino': 'muffin', 'goat[]': 'scone', 'pond': 'moose'}],
+ ['trololol=yes&lololo=no', {'trololol': 'yes', 'lololo': 'no'}]
+];
+
+exports['test basic'] = function(assert) {
+ assert.strictEqual('918854443121279438895193',
+ qs.parse('id=918854443121279438895193').id,
+ 'prase id=918854443121279438895193');
+};
+
+exports['test that the canonical qs is parsed properly'] = function(assert) {
+ qsTestCases.forEach(function(testCase) {
+ assert.deepEqual(testCase[2], qs.parse(testCase[0]),
+ 'parse ' + testCase[0]);
+ });
+};
+
+
+exports['test that the colon test cases can do the same'] = function(assert) {
+ qsColonTestCases.forEach(function(testCase) {
+ assert.deepEqual(testCase[2], qs.parse(testCase[0], ';', ':'),
+ 'parse ' + testCase[0] + ' -> ; :');
+ });
+};
+
+exports['test the weird objects, that they get parsed properly'] = function(assert) {
+ qsWeirdObjects.forEach(function(testCase) {
+ assert.deepEqual(testCase[2], qs.parse(testCase[1]),
+ 'parse ' + testCase[1]);
+ });
+};
+
+exports['test non munge test cases'] = function(assert) {
+ qsNoMungeTestCases.forEach(function(testCase) {
+ //console.log(testCase[0], JSON.stringify(testCase[1]), qs.stringify(testCase[1], '&', '=', false));
+ assert.deepEqual(testCase[0], qs.stringify(testCase[1], '&', '=', false),
+ 'stringify ' + JSON.stringify(testCase[1]) + ' -> & =');
+ });
+};
+
+exports['test the nested qs-in-qs case'] = function(assert) {
+ var f = qs.parse('a=b&q=x%3Dy%26y%3Dz');
+ f.q = qs.parse(f.q);
+ assert.deepEqual(f, { a: 'b', q: { x: 'y', y: 'z' } },
+ 'parse a=b&q=x%3Dy%26y%3Dz');
+};
+
+exports['test nested in colon'] = function(assert) {
+ var f = qs.parse('a:b;q:x%3Ay%3By%3Az', ';', ':');
+ f.q = qs.parse(f.q, ';', ':');
+ assert.deepEqual(f, { a: 'b', q: { x: 'y', y: 'z' } },
+ 'parse a:b;q:x%3Ay%3By%3Az -> ; :');
+};
+
+exports['test stringifying'] = function(assert) {
+ qsTestCases.forEach(function(testCase) {
+ assert.equal(testCase[1], qs.stringify(testCase[2]),
+ 'stringify ' + JSON.stringify(testCase[2]));
+ });
+
+ qsColonTestCases.forEach(function(testCase) {
+ assert.equal(testCase[1], qs.stringify(testCase[2], ';', ':'),
+ 'stringify ' + JSON.stringify(testCase[2]) + ' -> ; :');
+ });
+
+ qsWeirdObjects.forEach(function(testCase) {
+ assert.equal(testCase[1], qs.stringify(testCase[0]),
+ 'stringify ' + JSON.stringify(testCase[0]));
+ });
+};
+
+exports['test stringifying nested'] = function(assert) {
+ var f = qs.stringify({
+ a: 'b',
+ q: qs.stringify({
+ x: 'y',
+ y: 'z'
+ })
+ });
+ assert.equal(f, 'a=b&q=x%3Dy%26y%3Dz',
+ JSON.stringify({
+ a: 'b',
+ 'qs.stringify -> q': {
+ x: 'y',
+ y: 'z'
+ }
+ }));
+
+ var threw = false;
+ try { qs.parse(undefined); } catch(error) { threw = true; }
+ assert.ok(!threw, "does not throws on undefined");
+};
+
+exports['test nested in colon'] = function(assert) {
+ var f = qs.stringify({
+ a: 'b',
+ q: qs.stringify({
+ x: 'y',
+ y: 'z'
+ }, ';', ':')
+ }, ';', ':');
+ assert.equal(f, 'a:b;q:x%3Ay%3By%3Az',
+ 'stringify ' + JSON.stringify({
+ a: 'b',
+ 'qs.stringify -> q': {
+ x: 'y',
+ y: 'z'
+ }
+ }) + ' -> ; : ');
+
+
+ assert.deepEqual({}, qs.parse(), 'parse undefined');
+};
+
+require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-registry.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-registry.js
new file mode 100644
index 0000000..c5820fb
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-registry.js
@@ -0,0 +1,80 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+exports['test:add'] = function(test) {
+ function Class() {}
+ let fixture = require('utils/registry').Registry(Class);
+ let isAddEmitted = false;
+ fixture.on('add', function(item) {
+ test.assert(
+ item instanceof Class,
+ 'if object added is not an instance should construct instance from it'
+ );
+ test.assert(
+ fixture.has(item),
+ 'callback is called after instance is added'
+ );
+ test.assert(
+ !isAddEmitted,
+ 'callback should be called for the same item only once'
+ );
+ isAddEmitted = true;
+ });
+
+ let object = fixture.add({});
+ fixture.add(object);
+};
+
+exports['test:remove'] = function(test) {
+ function Class() {}
+ let fixture = require('utils/registry').Registry(Class);
+ fixture.on('remove', function(item) {
+ test.assert(
+ item instanceof Class,
+ 'if object removed can be only instance of Class'
+ );
+ test.assert(
+ fixture.has(item),
+ 'callback is called before instance is removed'
+ );
+ test.assert(
+ !isRemoveEmitted,
+ 'callback should be called for the same item only once'
+ );
+ isRemoveEmitted = true;
+ });
+
+ fixture.remove({});
+ let object = fixture.add({});
+ fixture.remove(object);
+ fixture.remove(object);
+};
+
+exports['test:items'] = function(test) {
+ function Class() {}
+ let fixture = require('utils/registry').Registry(Class),
+ actual,
+ times = 0;
+
+ function testItem(item) {
+ times ++;
+ test.assertEqual(
+ actual,
+ item,
+ 'item should match actual item being added/removed'
+ );
+ }
+
+ actual = fixture.add({});
+
+ fixture.on('add', testItem);
+ fixture.on('remove', testItem);
+
+ fixture.remove(actual);
+ fixture.remove(fixture.add(actual = new Class()));
+ test.assertEqual(3, times, 'should notify listeners on each call');
+}
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-require.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-require.js
new file mode 100644
index 0000000..7508883
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-require.js
@@ -0,0 +1,29 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const traceback = require("traceback");
+
+exports.test_no_args = function(test) {
+ var passed = false;
+ try {
+ var oops = require(); // leave this on line 6!
+ } catch(e) {
+ let msg = e.toString();
+ test.assertEqual(msg.indexOf("Error: you must provide a module name when calling require() from "), 0);
+ test.assertNotEqual(msg.indexOf("test-require"), -1, msg);
+ // we'd also like to assert that the right filename and linenumber is in
+ // the stack trace, but this currently doesn't work (see bugs 679591 and
+ // 551604)
+ if (0) {
+ let tb = traceback.fromException(e);
+ let lastFrame = tb[tb.length-1];
+ test.assertNotEqual(lastFrame.filename.indexOf("test-require.js"), -1,
+ lastFrame.filename);
+ test.assertEqual(lastFrame.lineNo, 6);
+ test.assertEqual(lastFrame.funcName, "??");
+ }
+ passed = true;
+ }
+ test.assert(passed, 'require() with no args should raise helpful error');
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-sandbox.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-sandbox.js
new file mode 100644
index 0000000..fb7a1da
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-sandbox.js
@@ -0,0 +1,113 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const { sandbox, load, evaluate } = require('api-utils/sandbox');
+const fixturesURI = module.uri.split('test-sandbox.js')[0] + 'fixtures/';
+
+
+exports['test basics'] = function(assert) {
+ let fixture = sandbox('http://example.com');
+ assert.equal(evaluate(fixture, 'var a = 1;'), undefined,
+ 'returns expression value');
+ assert.equal(evaluate(fixture, 'b = 2;'), 2,
+ 'returns expression value');
+ assert.equal(fixture.b, 2, 'global is defined as property');
+ assert.equal(fixture.a, 1, 'global is defined as property');
+ assert.equal(evaluate(fixture, 'a + b;'), 3, 'returns correct sum');
+};
+
+exports['test non-privileged'] = function(assert) {
+ let fixture = sandbox('http://example.com');
+ assert.throws(function() {
+ evaluate(fixture, 'Compo' + 'nents.utils');
+ }, 'Access to components is restricted');
+ fixture.sandbox = sandbox;
+ assert.throws(function() {
+ evaluate(fixture, sandbox('http://foo.com'));
+ }, 'Can not call privileged code');
+};
+
+exports['test injection'] = function(assert) {
+ let fixture = sandbox();
+ fixture.hi = function(name) 'Hi ' + name
+ assert.equal(evaluate(fixture, 'hi("sandbox");'), 'Hi sandbox',
+ 'injected functions are callable');
+};
+
+exports['test exceptions'] = function(assert) {
+ let fixture = sandbox();
+ try {
+ evaluate(fixture, '!' + function() {
+ var message = 'boom';
+ throw Error(message);
+ } + '();');
+ }
+ catch (error) {
+ assert.equal(error.fileName, '', 'no fileName reported');
+ assert.equal(error.lineNumber, 3, 'reports correct line number');
+ }
+
+ try {
+ evaluate(fixture, '!' + function() {
+ var message = 'boom';
+ throw Error(message);
+ } + '();', 'foo.js');
+ }
+ catch (error) {
+ assert.equal(error.fileName, 'foo.js', 'correct fileName reported');
+ assert.equal(error.lineNumber, 3, 'reports correct line number');
+ }
+
+ try {
+ evaluate(fixture, '!' + function() {
+ var message = 'boom';
+ throw Error(message);
+ } + '();', 'foo.js', 2);
+ }
+ catch (error) {
+ assert.equal(error.fileName, 'foo.js', 'correct fileName reported');
+ assert.equal(error.lineNumber, 4, 'line number was opted');
+ }
+};
+
+exports['test opt version'] = function(assert) {
+ let fixture = sandbox();
+ assert.throws(function() {
+ evaluate(fixture, 'let a = 2;', 'test.js', 1, '1.5');
+ }, 'No let in js 1.5');
+};
+
+exports['test load'] = function(assert) {
+ let fixture = sandbox();
+ load(fixture, fixturesURI + 'sandbox-normal.js');
+ assert.equal(fixture.a, 1, 'global variable defined');
+ assert.equal(fixture.b, 2, 'global via `this` property was set');
+ assert.equal(fixture.f(), 4, 'function was defined');
+};
+
+exports['test load with data: URL'] = function(assert) {
+ let code = "var a = 1; this.b = 2; function f() 4";
+ let fixture = sandbox();
+ load(fixture, "data:," + encodeURIComponent(code));
+
+ assert.equal(fixture.a, 1, 'global variable defined');
+ assert.equal(fixture.b, 2, 'global via `this` property was set');
+ assert.equal(fixture.f(), 4, 'function was defined');
+};
+
+exports['test load script with complex char'] = function(assert) {
+ let fixture = sandbox();
+ load(fixture, fixturesURI + 'sandbox-complex-character.js');
+ assert.equal(fixture.chars, 'გამარჯობა', 'complex chars were loaded correctly');
+};
+
+exports['test load script with data: URL and complex char'] = function(assert) {
+ let code = "var chars = 'გამარჯობა';";
+ let fixture = sandbox();
+ load(fixture, "data:," + encodeURIComponent(code));
+
+ assert.equal(fixture.chars, 'გამარჯობა', 'complex chars were loaded correctly');
+};
+
+require('test').run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-self.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-self.js
new file mode 100644
index 0000000..2f0e093
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-self.js
@@ -0,0 +1,54 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {Cc, Ci, Cu, Cm, components} = require('chrome');
+Cu.import("resource://gre/modules/AddonManager.jsm", this);
+
+exports.testSelf = function(test) {
+ var self = require("self");
+
+ var source = self.data.load("test-content-symbiont.js");
+ test.assert(source.match(/test-content-symbiont/), "self.data.load() works");
+
+ // Likewise, we can't assert anything about the full URL, because that
+ // depends on self.id . We can only assert that it ends in the right
+ // thing.
+ var url = self.data.url("test-content-symbiont.js");
+ test.assertEqual(typeof(url), "string", "self.data.url('x') returns string");
+ test.assertEqual(/\/test-content-symbiont\.js$/.test(url), true);
+
+ // Make sure 'undefined' is not in url when no string is provided.
+ url = self.data.url();
+ test.assertEqual(typeof(url), "string", "self.data.url() returns string");
+ test.assertEqual(/\/undefined$/.test(url), false);
+
+ // When tests are run on just the api-utils package, self.name is
+ // api-utils. When they're run as 'cfx testall', self.name is testpkgs.
+ test.assert((self.name == "api-utils") || (self.name == "testpkgs"),
+ "self.name is api-utils or testpkgs");
+};
+
+exports.testSelfID = function(test) {
+ test.waitUntilDone();
+
+ var self = require("self");
+ // We can't assert anything about the ID inside the unit test right now,
+ // because the ID we get depends upon how the test was invoked. The idea
+ // is that it is supposed to come from the main top-level package's
+ // package.json file, from the "id" key.
+ test.assertEqual(typeof(self.id), "string", "self.id is a string");
+ test.assert(self.id.length > 0);
+
+ AddonManager.getAddonByID(self.id, function(addon) {
+ if (!addon) {
+ test.fail("did not find addon with self.id");
+ }
+ else {
+ test.pass("found addon with self.id");
+ }
+ test.done();
+ });
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-set-exports.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-set-exports.js
new file mode 100644
index 0000000..5221237
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-set-exports.js
@@ -0,0 +1,35 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+let four = require("./modules/exportsEquals");
+exports.testExportsEquals = function(test) {
+ test.assertEqual(four, 4);
+}
+
+/* TODO: Discuss idea of dropping support for this feature that was alternative
+ to `module.exports = ..` that failed.
+let five = require("./modules/setExports");
+exports.testSetExports = function(test) {
+ test.assertEqual(five, 5);
+}
+
+exports.testDupeSetExports = function(test) {
+ var passed = false;
+ try {
+ var dupe = require('./modules/dupeSetExports');
+ } catch(e) {
+ passed = /define\(\) was used, so module\.exports= and module\.setExports\(\) may not be used/.test(e.toString());
+ }
+ test.assertEqual(passed, true, 'define() or setExports(), not both');
+}
+*/
+
+exports.testModule = function(test) {
+ // module.id is not cast in stone yet. In the future, it may include the
+ // package name, or may possibly be a/ URL of some sort. For now, it's a
+ // URL that starts with resource: and ends with this module name, but the
+ // part in between varies depending upon how the test is run.
+ var found = /test-set-exports$/.test(module.id);
+ test.assertEqual(found, true, module.id+" ends with test-set-exports.js");
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-tab-browser.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-tab-browser.js
new file mode 100644
index 0000000..31c5656
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-tab-browser.js
@@ -0,0 +1,493 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var timer = require("timer");
+var {Cc,Ci} = require("chrome");
+
+function onBrowserLoad(callback, event) {
+ if (event.target && event.target.defaultView == this) {
+ this.removeEventListener("load", onBrowserLoad, true);
+ let browsers = this.document.getElementsByTagName("tabbrowser");
+ try {
+ require("timer").setTimeout(function (window) {
+ callback(window, browsers[0]);
+ }, 10, this);
+ } catch (e) { console.exception(e); }
+ }
+}
+// Utility function to open a new browser window.
+function openBrowserWindow(callback, url) {
+ let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
+ getService(Ci.nsIWindowWatcher);
+ let urlString = Cc["@mozilla.org/supports-string;1"].
+ createInstance(Ci.nsISupportsString);
+ urlString.data = url;
+ let window = ww.openWindow(null, "chrome://browser/content/browser.xul",
+ "_blank", "chrome,all,dialog=no", urlString);
+ if (callback)
+ window.addEventListener("load", onBrowserLoad.bind(window, callback), true);
+
+ return window;
+}
+
+// Helper for calling code at window close
+function closeBrowserWindow(window, callback) {
+ require("timer").setTimeout(function() {
+ window.addEventListener("unload", function onUnload() {
+ window.removeEventListener("unload", onUnload, false);
+ callback();
+ }, false);
+ window.close();
+ }, 0);
+}
+
+// Helper for opening two windows at once
+function openTwoWindows(callback) {
+ openBrowserWindow(function (window1) {
+ openBrowserWindow(function (window2) {
+ callback(window1, window2);
+ });
+ });
+}
+
+// Helper for closing two windows at once
+function closeTwoWindows(window1, window2, callback) {
+ closeBrowserWindow(window1, function() {
+ closeBrowserWindow(window2, callback);
+ });
+}
+
+exports.testAddTab = function(test) {
+ test.waitUntilDone();
+ openBrowserWindow(function(window, browser) {
+ const tabBrowser = require("tab-browser");
+
+ let cache = [];
+ let windowUtils = require("window-utils");
+ new windowUtils.WindowTracker({
+ onTrack: function(win) {
+ cache.push(win);
+ },
+ onUntrack: function(win) {
+ cache.splice(cache.indexOf(win), 1)
+ }
+ });
+ let startWindowCount = cache.length;
+
+ // Test 1: add a tab
+ let firstUrl = "data:text/html,one";
+ tabBrowser.addTab(firstUrl, {
+ onLoad: function(e) {
+ let win1 = cache[startWindowCount - 1];
+ test.assertEqual(win1.content.location, firstUrl, "URL of new tab in first window matches");
+
+ // Test 2: add a tab in a new window
+ let secondUrl = "data:text/html,two";
+ tabBrowser.addTab(secondUrl, {
+ inNewWindow: true,
+ onLoad: function(e) {
+ test.assertEqual(cache.length, startWindowCount + 1, "a new window was opened");
+ let win2 = cache[startWindowCount];
+ let gBrowser = win2.gBrowser;
+ gBrowser.addEventListener("DOMContentLoaded", function onLoad(e) {
+ gBrowser.removeEventListener("DOMContentLoaded", onLoad, false);
+ test.assertEqual(win2.content.location, secondUrl, "URL of new tab in the new window matches");
+
+ closeBrowserWindow(win2, function() {
+ closeBrowserWindow(win1, function() {
+ test.done();
+ });
+ });
+ }, false);
+ }
+ });
+ }
+ });
+ });
+};
+
+exports.testTrackerWithDelegate = function(test) {
+ test.waitUntilDone();
+ const tabBrowser = require("tab-browser");
+
+ var delegate = {
+ state: "initializing",
+ onTrack: function onTrack(browser) {
+ if (this.state == "initializing") {
+ this.state = "waiting for browser window to open";
+ }
+ else if (this.state == "waiting for browser window to open") {
+ this.state = "waiting for browser window to close";
+ require("timer").setTimeout(function() {
+ closeBrowserWindow(browser.ownerDocument.defaultView, function() {
+ test.assertEqual(delegate.state, "deinitializing");
+ tb.unload();
+ test.done();
+ });
+ }, 0);
+ }
+ else
+ test.fail("invalid state");
+ },
+ onUntrack: function onUntrack(browser) {
+ if (this.state == "waiting for browser window to close") {
+ test.pass("proper state in onUntrack");
+ this.state = "deinitializing";
+ }
+ else if (this.state != "deinitializing")
+ test.fail("invalid state");
+ }
+ };
+ var tb = new tabBrowser.Tracker(delegate);
+
+ delegate.state = "waiting for browser window to open";
+
+ openBrowserWindow();
+};
+
+exports.testWhenContentLoaded = function(test) {
+ test.waitUntilDone();
+ const tabBrowser = require("tab-browser");
+
+ var tracker = tabBrowser.whenContentLoaded(
+ function(window) {
+ var item = window.document.getElementById("foo");
+ test.assertEqual(item.textContent, "bar",
+ "whenContentLoaded() works.");
+ tracker.unload();
+ closeBrowserWindow(activeWindow(), function() {
+ test.done();
+ });
+ });
+
+ openBrowserWindow(function(browserWindow, browser) {
+ var html = '<div id="foo">bar</div>';
+ browser.addTab("data:text/html," + html);
+ });
+};
+
+exports.testTrackerWithoutDelegate = function(test) {
+ test.waitUntilDone();
+ const tabBrowser = require("tab-browser");
+
+ openBrowserWindow(function(browserWindow, browser) {
+ var tb = new tabBrowser.Tracker();
+
+ if (tb.length == 0)
+ test.fail("expect at least one tab browser to exist.");
+
+ for (var i = 0; i < tb.length; i++)
+ test.assertEqual(tb.get(i).nodeName, "tabbrowser",
+ "get() method and length prop should work");
+ for (var b in tb)
+ test.assertEqual(b.nodeName, "tabbrowser",
+ "iterator should work");
+
+ var matches = [b for (b in tb)
+ if (b == browser)];
+ test.assertEqual(matches.length, 1,
+ "New browser should be in tracker.");
+ tb.unload();
+
+ closeBrowserWindow(browserWindow, function() {
+ test.done();
+ });
+ });
+};
+
+exports.testTabTracker = function(test) {
+ test.waitUntilDone();
+ const tabBrowser = require("tab-browser");
+
+ openBrowserWindow(function(browserWindow, browser) {
+ var delegate = {
+ tracked: 0,
+ onTrack: function(tab) {
+ this.tracked++;
+ },
+ onUntrack: function(tab) {
+ this.tracked--;
+ }
+ };
+
+ let tabTracker = tabBrowser.TabTracker(delegate);
+
+ let tracked = delegate.tracked;
+ let url1 = "data:text/html,1";
+ let url2 = "data:text/html,2";
+ let url3 = "data:text/html,3";
+ let tabCount = 0;
+
+ function tabLoadListener(e) {
+ let loadedURL = e.target.defaultView.location;
+ if (loadedURL == url1)
+ tabCount++;
+ else if (loadedURL == url2)
+ tabCount++;
+ else if (loadedURL == url3)
+ tabCount++;
+
+ if (tabCount == 3) {
+ test.assertEqual(delegate.tracked, tracked + 3, "delegate tracked tabs matched count");
+ tabTracker.unload();
+ closeBrowserWindow(browserWindow, function() {
+ require("timer").setTimeout(function() test.done(), 0);
+ });
+ }
+ }
+
+ tabBrowser.addTab(url1, {
+ onLoad: tabLoadListener
+ });
+ tabBrowser.addTab(url2, {
+ onLoad: tabLoadListener
+ });
+ tabBrowser.addTab(url3, {
+ onLoad: tabLoadListener
+ });
+ });
+};
+
+exports.testActiveTab = function(test) {
+ test.waitUntilDone();
+ openBrowserWindow(function(browserWindow, browser) {
+ const tabBrowser = require("tab-browser");
+ const TabModule = require("tab-browser").TabModule;
+ let tm = new TabModule(browserWindow);
+ test.assertEqual(tm.length, 1);
+ let url1 = "data:text/html,foo";
+ let url2 = "data:text/html,bar";
+
+ function tabURL(tab) tab.ownerDocument.defaultView.content.location.toString()
+
+ tabBrowser.addTab(url1, {
+ onLoad: function(e) {
+ // make sure we're running in the right window.
+ test.assertEqual(tabBrowser.activeTab.ownerDocument.defaultView, browserWindow, "active window matches");
+ browserWindow.focus();
+
+ test.assertEqual(tabURL(tabBrowser.activeTab), url1, "url1 matches");
+ let tabIndex = browser.getBrowserIndexForDocument(e.target);
+ let tabAtIndex = browser.tabContainer.getItemAtIndex(tabIndex);
+ test.assertEqual(tabAtIndex, tabBrowser.activeTab, "activeTab element matches");
+
+ tabBrowser.addTab(url2, {
+ inBackground: true,
+ onLoad: function() {
+ test.assertEqual(tabURL(tabBrowser.activeTab), url1, "url1 still matches");
+ let tabAtIndex = browser.tabContainer.getItemAtIndex(tabIndex);
+ test.assertEqual(tabAtIndex, tabBrowser.activeTab, "activeTab element matches");
+ closeBrowserWindow(browserWindow, function() {
+ test.done()
+ });
+ }
+ });
+ }
+ });
+ });
+};
+
+// TabModule tests
+exports.testEventsAndLengthStayInModule = function(test) {
+ test.waitUntilDone();
+ let TabModule = require("tab-browser").TabModule;
+
+ openTwoWindows(function(window1, window2) {
+ let tm1 = new TabModule(window1);
+ let tm2 = new TabModule(window2);
+
+ let counter1 = 0, counter2 = 0;
+ let counterTabs = 0;
+
+ function onOpenListener() {
+ ++counterTabs;
+ if (counterTabs < 5)
+ return;
+ test.assertEqual(counter1, 2, "Correct number of events fired from window 1");
+ test.assertEqual(counter2, 3, "Correct number of events fired from window 2");
+ test.assertEqual(counterTabs, 5, "Correct number of events fired from all windows");
+ test.assertEqual(tm1.length, 3, "Correct number of tabs in window 1");
+ test.assertEqual(tm2.length, 4, "Correct number of tabs in window 2");
+ closeTwoWindows(window1, window2, function() test.done());
+ }
+
+ tm1.onOpen = function() ++counter1 && onOpenListener();
+ tm2.onOpen = function() ++counter2 && onOpenListener();
+
+ let url = "data:text/html,default";
+ tm1.open(url);
+ tm1.open(url);
+
+ tm2.open(url);
+ tm2.open(url);
+ tm2.open(url);
+ });
+}
+
+exports.testTabModuleActiveTab_getterAndSetter = function(test) {
+ test.waitUntilDone();
+ let TabModule = require("tab-browser").TabModule;
+
+ openTwoWindows(function(window1, window2) {
+ let tm1 = new TabModule(window1);
+ let tm2 = new TabModule(window2);
+
+ let tab1 = null;
+ tm1.open({
+ url: "data:text/html,<title>window1,tab1</title>",
+ onOpen: function(tab) tab1 = tab,
+ });
+ tm1.open("data:text/html,<title>window1,tab2</title>");
+
+ tm1.onActivate = function onActivate() {
+ tm1.onActivate.remove(onActivate);
+ require("timer").setTimeout(function() {
+ test.assertEqual(tm1.activeTab.title, "window1,tab1", "activeTab setter works");
+ closeTwoWindows(window1, window2, function() test.done());
+ }, 1000);
+ }
+
+ tm2.open("data:text/html,<title>window2,tab1</title>");
+ tm2.open({
+ url: "data:text/html,<title>window2,tab2</title>",
+ onOpen: function(tab4) {
+ test.assertEqual(tm1.activeTab.title, "window1,tab2", "Correct active tab on window 1");
+ test.assertEqual(tm2.activeTab.title, "window2,tab2", "Correct active tab on window 2");
+
+ tm1.activeTab = tab1;
+ tm1.activeTab = tab4; // Setting activeTab from another window should have no effect
+ }
+ });
+ });
+}
+
+// test tabs iterator
+exports.testTabModuleTabsIterator = function(test) {
+ test.waitUntilDone();
+ let TabModule = require("tab-browser").TabModule;
+
+ openBrowserWindow(function(window) {
+ let tm1 = new TabModule(window);
+ let url = "data:text/html,default";
+ tm1.open(url);
+ tm1.open(url);
+ tm1.open({
+ url: url,
+ onOpen: function(tab) {
+ let count = 0;
+ for each (let t in tm1) count++;
+ test.assertEqual(count, 4, "iterated tab count matches");
+ test.assertEqual(count, tm1.length, "length tab count matches");
+ closeBrowserWindow(window, function() test.done());
+ }
+ });
+ });
+};
+
+// inNewWindow parameter is ignored on single-window modules
+exports.testTabModuleCantOpenInNewWindow = function(test) {
+ test.waitUntilDone();
+ let TabModule = require("tab-browser").TabModule;
+
+ openBrowserWindow(function(window) {
+ let tm = new TabModule(window);
+ let url = "data:text/html,default";
+ tm.open({
+ url: url,
+ inNewWindow: true,
+ onOpen: function() {
+ test.assertEqual(tm.length, 2, "Tab was open on same window");
+ closeBrowserWindow(window, function() test.done());
+ }
+ });
+ });
+};
+
+// Test that having two modules attached to the same
+// window won't duplicate events fired on each module
+exports.testModuleListenersDontInteract = function(test) {
+ test.waitUntilDone();
+ let TabModule = require("tab-browser").TabModule;
+
+ openBrowserWindow(function(window) {
+ let tm1 = new TabModule(window);
+ let tm2 = new TabModule(window);
+
+ let url = "data:text/html,foo";
+ let eventCount = 0, eventModule1 = 0, eventModule2 = 0;
+
+
+ let listener1 = function() {
+ // this should be called twice: when tab is open and when
+ // the url location is changed
+ eventCount++;
+ eventModule1++;
+ }
+ tm1.onReady = listener1;
+
+ tm2.open({
+ url: "about:blank",
+ onOpen: function(tab) {
+ // add listener via property assignment
+ let listener2 = function() {
+ eventCount++;
+ eventModule2++;
+ };
+ tab.onReady = listener2;
+
+ // add listener via collection add
+ let listener3 = function() {
+ eventCount++;
+ eventModule2++;
+ };
+ tab.onReady.add(listener3);
+
+ tab.location = url;
+
+ test.waitUntilEqual(function () eventCount, 4,
+ "Correct global number of events")
+ .then(function () {
+ test.assertEqual(eventModule1, 2,
+ "Correct number of events on module 1");
+ test.assertEqual(eventModule2, 2,
+ "Correct number of events on module 2");
+
+ tm1.onReady.remove(listener1);
+ tab.onReady.remove(listener2);
+ tab.onReady.remove(listener3);
+ closeBrowserWindow(window, function() test.done());
+ });
+ }
+ });
+ });
+};
+
+/******************* helpers *********************/
+
+// Helper for getting the active window
+function activeWindow() {
+ return Cc["@mozilla.org/appshell/window-mediator;1"].
+ getService(Ci.nsIWindowMediator).
+ getMostRecentWindow("navigator:browser");
+};
+
+// If the module doesn't support the app we're being run in, require() will
+// throw. In that case, remove all tests above from exports, and add one dummy
+// test that passes.
+try {
+ require("tab-browser");
+}
+catch (err) {
+ // This bug should be mentioned in the error message.
+ let bug = "https://bugzilla.mozilla.org/show_bug.cgi?id=560716";
+ if (err.message.indexOf(bug) < 0)
+ throw err;
+ for (let [prop, val] in Iterator(exports)) {
+ if (/^test/.test(prop) && typeof(val) === "function")
+ delete exports[prop];
+ }
+ exports.testAppNotSupported = function (test) {
+ test.pass("the tab-browser module does not support this application.");
+ };
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-tab-observer.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-tab-observer.js
new file mode 100644
index 0000000..3a506fa
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-tab-observer.js
@@ -0,0 +1,39 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { openTab, closeTab } = require("api-utils/tabs/utils");
+const { Loader } = require("./helpers");
+const { setTimeout } = require("timer");
+
+exports["test unload tab observer"] = function(assert, done) {
+ let loader = Loader(module);
+
+ let window = loader.require("api-utils/window-utils").activeBrowserWindow;
+ let observer = loader.require("api-utils/tabs/observer").observer;
+ let opened = 0;
+ let closed = 0;
+
+ observer.on("open", function onOpen(window) { opened++; });
+ observer.on("close", function onClose(window) { closed++; });
+
+ // Open and close tab to trigger observers.
+ closeTab(openTab(window, "data:text/html,tab-1"));
+
+ // Unload the module so that all listeners set by observer are removed.
+ loader.unload();
+
+ // Open and close tab once again.
+ closeTab(openTab(window, "data:text/html,tab-2"));
+
+ // Enqueuing asserts to make sure that assertion is not performed early.
+ setTimeout(function () {
+ assert.equal(1, opened, "observer open was called before unload only");
+ assert.equal(1, closed, "observer close was called before unload only");
+ done();
+ }, 0);
+};
+
+require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-tab.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-tab.js
new file mode 100644
index 0000000..2324fa7
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-tab.js
@@ -0,0 +1,110 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const tabAPI = require("tabs/tab");
+const tabs = require("tabs"); // From addon-kit
+const windowUtils = require("window-utils");
+
+// The primary test tab
+var primaryTab;
+
+// We have an auxiliary tab to test background tabs.
+var auxTab;
+
+// The window for the outer iframe in the primary test page
+var iframeWin;
+
+exports.testGetTabForWindow = function(test) {
+ test.waitUntilDone();
+
+ test.assertEqual(tabAPI.getTabForWindow(windowUtils.activeWindow), null,
+ "getTabForWindow return null on topwindow");
+ test.assertEqual(tabAPI.getTabForWindow(windowUtils.activeBrowserWindow), null,
+ "getTabForWindow return null on topwindow");
+
+ let subSubDocument = encodeURIComponent(
+ 'Sub iframe<br/>'+
+ '<iframe id="sub-sub-iframe" src="data:text/html,SubSubIframe" />');
+ let subDocument = encodeURIComponent(
+ 'Iframe<br/>'+
+ '<iframe id="sub-iframe" src="data:text/html,'+subSubDocument+'" />');
+ let url = 'data:text/html,' + encodeURIComponent(
+ 'Content<br/><iframe id="iframe" src="data:text/html,'+subDocument+'" />');
+
+ // Open up a new tab in the background.
+ //
+ // This lets us test whether GetTabForWindow works even when the tab in
+ // question is not active.
+ tabs.open({
+ inBackground: true,
+ url: "about:mozilla",
+ onReady: function(tab) { auxTab = tab; step2(url, test);},
+ onActivate: function(tab) { step3(test); }
+ });
+}
+
+function step2(url, test) {
+
+ tabs.open({
+ url: url,
+ onReady: function(tab) {
+ primaryTab = tab;
+ let window = windowUtils.activeBrowserWindow.content;
+
+ let matchedTab = tabAPI.getTabForWindow(window);
+ test.assertEqual(matchedTab, tab,
+ "We are able to find the tab with his content window object");
+
+ let timer = require("timer");
+ function waitForFrames() {
+ let iframe = window.document.getElementById("iframe");
+ if (!iframe) {
+ timer.setTimeout(waitForFrames, 100);
+ return;
+ }
+ iframeWin = iframe.contentWindow;
+ let subIframe = iframeWin.document.getElementById("sub-iframe");
+ if (!subIframe) {
+ timer.setTimeout(waitForFrames, 100);
+ return;
+ }
+ let subIframeWin = subIframe.contentWindow;
+ let subSubIframe = subIframeWin.document.getElementById("sub-sub-iframe");
+ if (!subSubIframe) {
+ timer.setTimeout(waitForFrames, 100);
+ return;
+ }
+ let subSubIframeWin = subSubIframe.contentWindow;
+
+ matchedTab = tabAPI.getTabForWindow(iframeWin);
+ test.assertEqual(matchedTab, tab,
+ "We are able to find the tab with an iframe window object");
+
+ matchedTab = tabAPI.getTabForWindow(subIframeWin);
+ test.assertEqual(matchedTab, tab,
+ "We are able to find the tab with a sub-iframe window object");
+
+ matchedTab = tabAPI.getTabForWindow(subSubIframeWin);
+ test.assertEqual(matchedTab, tab,
+ "We are able to find the tab with a sub-sub-iframe window object");
+
+ // Put our primary tab in the background and test again.
+ // The onActivate listener will take us to step3.
+ auxTab.activate();
+ }
+ waitForFrames();
+ }
+ });
+}
+
+function step3(test) {
+
+ let matchedTab = tabAPI.getTabForWindow(iframeWin);
+ test.assertEqual(matchedTab, primaryTab,
+ "We get the correct tab even when it's in the background");
+
+ primaryTab.close(function () {
+ auxTab.close(function () { test.done();});
+ });
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-text-streams.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-text-streams.js
new file mode 100644
index 0000000..f5aec98
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-text-streams.js
@@ -0,0 +1,156 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim:set ts=2 sw=2 sts=2 et filetype=javascript
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const file = require("file");
+const { pathFor } = require("api-utils/system");
+const { Loader } = require("./helpers");
+
+const STREAM_CLOSED_ERROR = "The stream is closed and cannot be used.";
+
+// This should match the constant of the same name in text-streams.js.
+const BUFFER_BYTE_LEN = 0x8000;
+
+exports.testWriteRead = function (test) {
+ let fname = dataFileFilename();
+
+ // Write a small string less than the stream's buffer size...
+ let str = "exports.testWriteRead data!";
+ let stream = file.open(fname, "w");
+ test.assert(!stream.closed, "stream.closed after open should be false");
+ stream.write(str);
+ stream.close();
+ test.assert(stream.closed, "stream.closed after close should be true");
+ test.assertRaises(function () stream.close(),
+ STREAM_CLOSED_ERROR,
+ "stream.close after already closed should raise error");
+ test.assertRaises(function () stream.write("This shouldn't be written!"),
+ STREAM_CLOSED_ERROR,
+ "stream.write after close should raise error");
+
+ // ... and read it.
+ stream = file.open(fname);
+ test.assert(!stream.closed, "stream.closed after open should be false");
+ test.assertEqual(stream.read(), str,
+ "stream.read should return string written");
+ test.assertEqual(stream.read(), "",
+ "stream.read at EOS should return empty string");
+ stream.close();
+ test.assert(stream.closed, "stream.closed after close should be true");
+ test.assertRaises(function () stream.close(),
+ STREAM_CLOSED_ERROR,
+ "stream.close after already closed should raise error");
+ test.assertRaises(function () stream.read(),
+ STREAM_CLOSED_ERROR,
+ "stream.read after close should raise error");
+
+ // Write a big string many times the size of the stream's buffer and read it.
+ // Since it comes after the previous test, this also ensures that the file is
+ // truncated when it's opened for writing.
+ str = "";
+ let bufLen = BUFFER_BYTE_LEN;
+ let fileSize = bufLen * 10;
+ for (let i = 0; i < fileSize; i++)
+ str += i % 10;
+ stream = file.open(fname, "w");
+ stream.write(str);
+ stream.close();
+ stream = file.open(fname);
+ test.assertEqual(stream.read(), str,
+ "stream.read should return string written");
+ stream.close();
+
+ // The same, but write and read in chunks.
+ stream = file.open(fname, "w");
+ let i = 0;
+ while (i < str.length) {
+ // Use a chunk length that spans buffers.
+ let chunk = str.substr(i, bufLen + 1);
+ stream.write(chunk);
+ i += bufLen + 1;
+ }
+ stream.close();
+ stream = file.open(fname);
+ let readStr = "";
+ bufLen = BUFFER_BYTE_LEN;
+ let readLen = bufLen + 1;
+ do {
+ var frag = stream.read(readLen);
+ readStr += frag;
+ } while (frag);
+ stream.close();
+ test.assertEqual(readStr, str,
+ "stream.write and read in chunks should work as expected");
+
+ // Read the same file, passing in strange numbers of bytes to read.
+ stream = file.open(fname);
+ test.assertEqual(stream.read(fileSize * 100), str,
+ "stream.read with big byte length should return string " +
+ "written");
+ stream.close();
+
+ stream = file.open(fname);
+ test.assertEqual(stream.read(0), "",
+ "string.read with zero byte length should return empty " +
+ "string");
+ stream.close();
+
+ stream = file.open(fname);
+ test.assertEqual(stream.read(-1), "",
+ "string.read with negative byte length should return " +
+ "empty string");
+ stream.close();
+
+ file.remove(fname);
+};
+
+exports.testWriteAsync = function (test) {
+ test.waitUntilDone();
+
+ let fname = dataFileFilename();
+ let str = "exports.testWriteAsync data!";
+ let stream = file.open(fname, "w");
+ test.assert(!stream.closed, "stream.closed after open should be false");
+
+ // Write.
+ stream.writeAsync(str, function (err) {
+ test.assertEqual(this, stream, "|this| should be the stream object");
+ test.assertEqual(err, undefined,
+ "stream.writeAsync should not cause error");
+ test.assert(stream.closed, "stream.closed after write should be true");
+ test.assertRaises(function () stream.close(),
+ STREAM_CLOSED_ERROR,
+ "stream.close after already closed should raise error");
+ test.assertRaises(function () stream.writeAsync("This shouldn't work!"),
+ STREAM_CLOSED_ERROR,
+ "stream.writeAsync after close should raise error");
+
+ // Read.
+ stream = file.open(fname, "r");
+ test.assert(!stream.closed, "stream.closed after open should be false");
+ let readStr = stream.read();
+ test.assertEqual(readStr, str,
+ "string.read should yield string written");
+ stream.close();
+ file.remove(fname);
+ test.done();
+ });
+};
+
+exports.testUnload = function (test) {
+ let loader = Loader(module);
+ let file = loader.require("file");
+
+ let filename = dataFileFilename("temp");
+ let stream = file.open(filename, "w");
+
+ loader.unload();
+ test.assert(stream.closed, "stream should be closed after module unload");
+};
+
+// Returns the name of a file that should be used to test writing and reading.
+function dataFileFilename() {
+ return file.join(pathFor("ProfD"), "test-text-streams-data");
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-timer.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-timer.js
new file mode 100644
index 0000000..bf6917c
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-timer.js
@@ -0,0 +1,131 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var timer = require("timer");
+const { Loader } = require("./helpers");
+
+exports.testSetTimeout = function(test) {
+ timer.setTimeout(function() {
+ test.pass("testSetTimeout passed");
+ test.done();
+ }, 1);
+ test.waitUntilDone();
+};
+
+exports.testParamedSetTimeout = function(test) {
+ let params = [1, 'foo', { bar: 'test' }, null, undefined];
+ timer.setTimeout.apply(null, [function() {
+ test.assertEqual(arguments.length, params.length);
+ for (let i = 0, ii = params.length; i < ii; i++)
+ test.assertEqual(params[i], arguments[i]);
+ test.done();
+ }, 1].concat(params));
+ test.waitUntilDone();
+};
+
+exports.testClearTimeout = function(test) {
+ var myFunc = function myFunc() {
+ test.fail("myFunc() should not be called in testClearTimeout");
+ };
+ var id = timer.setTimeout(myFunc, 1);
+ timer.setTimeout(function() {
+ test.pass("testClearTimeout passed");
+ test.done();
+ }, 2);
+ timer.clearTimeout(id);
+ test.waitUntilDone();
+};
+
+exports.testParamedClearTimeout = function(test) {
+ let params = [1, 'foo', { bar: 'test' }, null, undefined];
+ var myFunc = function myFunc() {
+ test.fail("myFunc() should not be called in testClearTimeout");
+ };
+ var id = timer.setTimeout(myFunc, 1);
+ timer.setTimeout.apply(null, [function() {
+ test.assertEqual(arguments.length, params.length);
+ for (let i = 0, ii = params.length; i < ii; i++)
+ test.assertEqual(params[i], arguments[i]);
+ test.done();
+ }, 1].concat(params));
+ timer.clearTimeout(id);
+ test.waitUntilDone();
+};
+
+exports.testSetInterval = function (test) {
+ var count = 0;
+ var id = timer.setInterval(function () {
+ count++;
+ if (count >= 5) {
+ timer.clearInterval(id);
+ test.pass("testSetInterval passed");
+ test.done();
+ }
+ }, 1);
+ test.waitUntilDone();
+};
+
+exports.testParamedSetInerval = function(test) {
+ let params = [1, 'foo', { bar: 'test' }, null, undefined];
+ let count = 0;
+ let id = timer.setInterval.apply(null, [function() {
+ count ++;
+ if (count < 5) {
+ test.assertEqual(arguments.length, params.length);
+ for (let i = 0, ii = params.length; i < ii; i++)
+ test.assertEqual(params[i], arguments[i]);
+ } else {
+ timer.clearInterval(id);
+ test.done();
+ }
+ }, 1].concat(params));
+ test.waitUntilDone();
+};
+
+exports.testClearInterval = function (test) {
+ timer.clearInterval(timer.setInterval(function () {
+ test.fail("setInterval callback should not be called");
+ }, 1));
+ var id = timer.setInterval(function () {
+ timer.clearInterval(id);
+ test.pass("testClearInterval passed");
+ test.done();
+ }, 2);
+ test.waitUntilDone();
+};
+
+exports.testParamedClearInterval = function(test) {
+ timer.clearInterval(timer.setInterval(function () {
+ test.fail("setInterval callback should not be called");
+ }, 1, timer, {}, null));
+
+ let id = timer.setInterval(function() {
+ timer.clearInterval(id);
+ test.assertEqual(3, arguments.length);
+ test.done();
+ }, 2, undefined, 'test', {});
+ test.waitUntilDone();
+};
+
+
+exports.testUnload = function(test) {
+ var loader = Loader(module);
+ var sbtimer = loader.require("timer");
+
+ var myFunc = function myFunc() {
+ test.fail("myFunc() should not be called in testUnload");
+ };
+
+ sbtimer.setTimeout(myFunc, 1);
+ sbtimer.setTimeout(myFunc, 1, 'foo', 4, {}, undefined);
+ sbtimer.setInterval(myFunc, 1);
+ sbtimer.setInterval(myFunc, 1, {}, null, 'bar', undefined, 87);
+ loader.unload();
+ timer.setTimeout(function() {
+ test.pass("timer testUnload passed");
+ test.done();
+ }, 2);
+ test.waitUntilDone();
+};
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-traceback.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-traceback.js
new file mode 100644
index 0000000..e4d1737
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-traceback.js
@@ -0,0 +1,118 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var traceback = require("traceback");
+var {Cc,Ci,Cr,Cu} = require("chrome");
+
+function throwNsIException() {
+ var ios = Cc['@mozilla.org/network/io-service;1']
+ .getService(Ci.nsIIOService);
+ ios.newURI("i'm a malformed URI", null, null);
+}
+
+function throwError() {
+ throw new Error("foob");
+}
+
+exports.testFormatDoesNotFetchRemoteFiles = function(test) {
+ var observers = require("observer-service");
+ ["http", "https"].forEach(
+ function(scheme) {
+ var httpRequests = 0;
+ function onHttp() {
+ httpRequests++;
+ }
+
+ observers.add("http-on-modify-request", onHttp);
+
+ try {
+ var tb = [{filename: scheme + "://www.mozilla.org/",
+ lineNo: 1,
+ funcName: "blah"}];
+ traceback.format(tb);
+ } catch (e) {
+ test.exception(e);
+ }
+
+ observers.remove("http-on-modify-request", onHttp);
+
+ test.assertEqual(httpRequests, 0,
+ "traceback.format() does not make " +
+ scheme + " request");
+ });
+};
+
+exports.testFromExceptionWithString = function(test) {
+ try {
+ throw "foob";
+ test.fail("an exception should've been thrown");
+ } catch (e if e == "foob") {
+ var tb = traceback.fromException(e);
+ test.assertEqual(tb.length, 0);
+ }
+};
+
+exports.testFormatWithString = function(test) {
+ // This can happen if e.g. a thrown exception was
+ // a string instead of an Error instance.
+ test.assertEqual(traceback.format("blah"),
+ "Traceback (most recent call last):");
+};
+
+exports.testFromExceptionWithError = function(test) {
+ try {
+ throwError();
+ test.fail("an exception should've been thrown");
+ } catch (e if e instanceof Error) {
+ var tb = traceback.fromException(e);
+ var xulApp = require("xul-app");
+ test.assertEqual(tb.slice(-1)[0].funcName, "throwError");
+ }
+};
+
+exports.testFromExceptionWithNsIException = function(test) {
+ try {
+ throwNsIException();
+ test.fail("an exception should've been thrown");
+ } catch (e if e.result == Cr.NS_ERROR_MALFORMED_URI) {
+ var tb = traceback.fromException(e);
+ test.assertEqual(tb.slice(-1)[0].funcName,
+ "throwNsIException");
+ }
+};
+
+exports.testFormat = function(test) {
+ function getTraceback() {
+ return traceback.format();
+ }
+
+ var formatted = getTraceback();
+ test.assertEqual(typeof(formatted), "string");
+ var lines = formatted.split("\n");
+ test.assertEqual(lines.slice(-2)[0].indexOf("getTraceback") > 0,
+ true,
+ "formatted traceback should include function name");
+ test.assertEqual(lines.slice(-1)[0].trim(),
+ "return traceback.format();",
+ "formatted traceback should include source code");
+};
+
+exports.testExceptionsWithEmptyStacksAreLogged = function(test) {
+ // Ensures that our fix to bug 550368 works.
+ var sandbox = Cu.Sandbox("http://www.foo.com");
+ var excRaised = false;
+ try {
+ Cu.evalInSandbox("returns 1 + 2;", sandbox, "1.8",
+ "blah.js", 25);
+ } catch (e) {
+ excRaised = true;
+ var stack = traceback.fromException(e);
+ test.assertEqual(stack.length, 1, "stack should have one frame");
+ test.assert(stack[0].filename, "blah.js", "frame should have filename");
+ test.assert(stack[0].lineNo, 25, "frame should have line no");
+ test.assertEqual(stack[0].funcName, null, "frame should have null function name");
+ }
+ if (!excRaised)
+ test.fail("Exception should have been raised.");
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-traits-core.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-traits-core.js
new file mode 100644
index 0000000..c2bf4df
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-traits-core.js
@@ -0,0 +1,838 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const ERR_CONFLICT = 'Remaining conflicting property: ',
+ ERR_REQUIRED = 'Missing required property: ';
+
+function assertSametrait(test, trait1, trait2) {
+ let names1 = Object.getOwnPropertyNames(trait1),
+ names2 = Object.getOwnPropertyNames(trait2);
+
+ test.assertEqual(
+ names1.length,
+ names2.length,
+ 'equal traits must have same amount of properties'
+ );
+
+ for (let i = 0; i < names1.length; i++) {
+ let name = names1[i];
+ test.assertNotEqual(
+ -1,
+ names2.indexOf(name),
+ 'equal traits must contain same named properties: ' + name
+ );
+ assertSameDescriptor(test, name, trait1[name], trait2[name]);
+ }
+}
+
+function assertSameDescriptor(test, name, desc1, desc2) {
+ if (desc1.conflict || desc2.conflict) {
+ test.assertEqual(
+ desc1.conflict,
+ desc2.conflict,
+ 'if one of same descriptors has `conflict` another must have it: '
+ + name
+ );
+ } else if (desc1.required || desc2.required) {
+ test.assertEqual(
+ desc1.required,
+ desc2.required,
+ 'if one of same descriptors is has `required` another must have it: '
+ + name
+ );
+ } else {
+ test.assertEqual(
+ desc1.get,
+ desc2.get,
+ 'get must be the same on both descriptors: ' + name
+ );
+ test.assertEqual(
+ desc1.set,
+ desc2.set,
+ 'set must be the same on both descriptors: ' + name
+ );
+ test.assertEqual(
+ desc1.value,
+ desc2.value,
+ 'value must be the same on both descriptors: ' + name
+ );
+ test.assertEqual(
+ desc1.enumerable,
+ desc2.enumerable,
+ 'enumerable must be the same on both descriptors: ' + name
+ );
+ test.assertEqual(
+ desc1.required,
+ desc2.required,
+ 'value must be the same on both descriptors: ' + name
+ );
+ }
+}
+
+function Data(value, enumerable, confligurable, writable) {
+ return {
+ value: value,
+ enumerable: false !== enumerable,
+ confligurable: false !== confligurable,
+ writable: false !== writable
+ };
+}
+
+function Method(method, enumerable, confligurable, writable) {
+ return {
+ value: method,
+ enumerable: false !== enumerable,
+ confligurable: false !== confligurable,
+ writable: false !== writable
+ };
+}
+
+function Accessor(get, set, enumerable, confligurable) {
+ return {
+ get: get,
+ set: set,
+ enumerable: false !== enumerable,
+ confligurable: false !== confligurable,
+ };
+}
+
+function Required(name) {
+ function required() { throw new Error(ERR_REQUIRED + name) }
+ return {
+ get: required,
+ set: required,
+ required: true
+ };
+}
+
+function Conflict(name) {
+ function conflict() { throw new Error(ERR_CONFLICT + name) }
+ return {
+ get: conflict,
+ set: conflict,
+ conflict: true
+ };
+}
+
+function testMethod() {};
+
+const { trait, compose, resolve, required, override, create } =
+ require('traits/core');
+
+
+exports['test:empty trait'] = function(test) {
+ assertSametrait(
+ test,
+ trait({}),
+ {}
+ );
+};
+
+exports['test:simple trait'] = function(test) {
+ assertSametrait(
+ test,
+ trait({
+ a: 0,
+ b: testMethod
+ }),
+ {
+ a: Data(0, true, true, true),
+ b: Method(testMethod, true, true, true)
+ }
+ );
+};
+
+exports['test:simple trait with required prop'] = function(test) {
+ assertSametrait(
+ test,
+ trait({
+ a: required,
+ b: 1
+ }),
+ {
+ a: Required('a'),
+ b: Data(1)
+ }
+ );
+};
+
+exports['test:ordering of trait properties is irrelevant'] = function(test) {
+ assertSametrait(test,
+ trait({ a: 0, b: 1, c: required }),
+ trait({ b: 1, c: required, a: 0 })
+ );
+};
+
+exports['test:trait with accessor property'] = function(test) {
+ let record = { get a() {}, set a(v) {} };
+ let get = Object.getOwnPropertyDescriptor(record,'a').get;
+ let set = Object.getOwnPropertyDescriptor(record,'a').set;
+ assertSametrait(test,
+ trait(record),
+ { a: Accessor(get, set ) }
+ );
+};
+
+exports['test:simple composition'] = function(test) {
+ assertSametrait(test,
+ compose(
+ trait({ a: 0, b: 1 }),
+ trait({ c: 2, d: testMethod })
+ ),
+ {
+ a: Data(0),
+ b: Data(1),
+ c: Data(2),
+ d: Method(testMethod)
+ }
+ );
+};
+
+exports['test:composition with conflict'] = function(test) {
+ assertSametrait(test,
+ compose(
+ trait({ a: 0, b: 1 }),
+ trait({ a: 2, c: testMethod })
+ ),
+ {
+ a: Conflict('a'),
+ b: Data(1),
+ c: Method(testMethod)
+ }
+ );
+};
+
+exports['test:composition of identical props does not cause conflict'] =
+function(test) {
+ assertSametrait(test,
+ compose(
+ trait({ a: 0, b: 1 }),
+ trait({ a: 0, c: testMethod })
+ ),
+ {
+ a: Data(0),
+ b: Data(1),
+ c: Method(testMethod) }
+ )
+};
+
+exports['test:composition with identical required props'] =
+function(test) {
+ assertSametrait(test,
+ compose(
+ trait({ a: required, b: 1 }),
+ trait({ a: required, c: testMethod })
+ ),
+ {
+ a: Required(),
+ b: Data(1),
+ c: Method(testMethod)
+ }
+ );
+};
+
+exports['test:composition satisfying a required prop'] = function (test) {
+ assertSametrait(test,
+ compose(
+ trait({ a: required, b: 1 }),
+ trait({ a: testMethod })
+ ),
+ {
+ a: Method(testMethod),
+ b: Data(1)
+ }
+ );
+};
+
+exports['test:compose is neutral wrt conflicts'] = function (test) {
+ assertSametrait(test,
+ compose(
+ compose(
+ trait({ a: 1 }),
+ trait({ a: 2 })
+ ),
+ trait({ b: 0 })
+ ),
+ {
+ a: Conflict('a'),
+ b: Data(0)
+ }
+ );
+};
+
+exports['test:conflicting prop overrides required prop'] = function (test) {
+ assertSametrait(test,
+ compose(
+ compose(
+ trait({ a: 1 }),
+ trait({ a: 2 })
+ ),
+ trait({ a: required })
+ ),
+ {
+ a: Conflict('a')
+ }
+ );
+};
+
+exports['test:compose is commutative'] = function (test) {
+ assertSametrait(test,
+ compose(
+ trait({ a: 0, b: 1 }),
+ trait({ c: 2, d: testMethod })
+ ),
+ compose(
+ trait({ c: 2, d: testMethod }),
+ trait({ a: 0, b: 1 })
+ )
+ );
+};
+
+exports['test:compose is commutative, also for required/conflicting props'] =
+function (test) {
+ assertSametrait(test,
+ compose(
+ trait({ a: 0, b: 1, c: 3, e: required }),
+ trait({ c: 2, d: testMethod })
+ ),
+ compose(
+ trait({ c: 2, d: testMethod }),
+ trait({ a: 0, b: 1, c: 3, e: required })
+ )
+ );
+};
+exports['test:compose is associative'] = function (test) {
+ assertSametrait(test,
+ compose(
+ trait({ a: 0, b: 1, c: 3, d: required }),
+ compose(
+ trait({ c: 3, d: required }),
+ trait({ c: 2, d: testMethod, e: 'foo' })
+ )
+ ),
+ compose(
+ compose(
+ trait({ a: 0, b: 1, c: 3, d: required }),
+ trait({ c: 3, d: required })
+ ),
+ trait({ c: 2, d: testMethod, e: 'foo' })
+ )
+ );
+};
+
+exports['test:diamond import of same prop does not generate conflict'] =
+function (test) {
+ assertSametrait(test,
+ compose(
+ compose(
+ trait({ b: 2 }),
+ trait({ a: 1 })
+ ),
+ compose(
+ trait({ c: 3 }),
+ trait({ a: 1 })
+ ),
+ trait({ d: 4 })
+ ),
+ {
+ a: Data(1),
+ b: Data(2),
+ c: Data(3),
+ d: Data(4)
+ }
+ );
+};
+
+exports['test:resolve with empty resolutions has no effect'] =
+function (test) {
+ assertSametrait(test, resolve({}, trait({
+ a: 1,
+ b: required,
+ c: testMethod
+ })), {
+ a: Data(1),
+ b: Required(),
+ c: Method(testMethod)
+ });
+};
+
+exports['test:resolve: renaming'] = function (test) {
+ assertSametrait(test,
+ resolve(
+ { a: 'A', c: 'C' },
+ trait({ a: 1, b: required, c: testMethod })
+ ),
+ {
+ A: Data(1),
+ b: Required(),
+ C: Method(testMethod),
+ a: Required(),
+ c: Required()
+ }
+ );
+};
+
+exports['test:resolve: renaming to conflicting name causes conflict, order 1']
+= function (test) {
+ assertSametrait(test,
+ resolve(
+ { a: 'b'},
+ trait({ a: 1, b: 2 })
+ ),
+ {
+ b: Conflict('b'),
+ a: Required()
+ }
+ );
+};
+
+exports['test:resolve: renaming to conflicting name causes conflict, order 2']
+= function (test) {
+ assertSametrait(test,
+ resolve(
+ { a: 'b' },
+ trait({ b: 2, a: 1 })
+ ),
+ {
+ b: Conflict('b'),
+ a: Required()
+ }
+ );
+};
+
+exports['test:resolve: simple exclusion'] = function (test) {
+ assertSametrait(test,
+ resolve(
+ { a: undefined },
+ trait({ a: 1, b: 2 })
+ ),
+ {
+ a: Required(),
+ b: Data(2)
+ }
+ );
+};
+
+exports['test:resolve: exclusion to "empty" trait'] = function (test) {
+ assertSametrait(test,
+ resolve(
+ { a: undefined, b: undefined },
+ trait({ a: 1, b: 2 })
+ ),
+ {
+ a: Required(),
+ b: Required()
+ }
+ );
+};
+
+exports['test:resolve: exclusion and renaming of disjoint props'] =
+function (test) {
+ assertSametrait(test,
+ resolve(
+ { a: undefined, b: 'c' },
+ trait({ a: 1, b: 2 })
+ ),
+ {
+ a: Required(),
+ c: Data(2),
+ b: Required()
+ }
+ );
+};
+
+exports['test:resolve: exclusion and renaming of overlapping props'] =
+function (test) {
+ assertSametrait(test,
+ resolve(
+ { a: undefined, b: 'a' },
+ trait({ a: 1, b: 2 })
+ ),
+ {
+ a: Data(2),
+ b: Required()
+ }
+ );
+};
+
+exports['test:resolve: renaming to a common alias causes conflict'] =
+function (test) {
+ assertSametrait(test,
+ resolve(
+ { a: 'c', b: 'c' },
+ trait({ a: 1, b: 2 })
+ ),
+ {
+ c: Conflict('c'),
+ a: Required(),
+ b: Required()
+ }
+ );
+};
+
+exports['test:resolve: renaming overrides required target'] =
+function (test) {
+ assertSametrait(test,
+ resolve(
+ { b: 'a' },
+ trait({ a: required, b: 2 })
+ ),
+ {
+ a: Data(2),
+ b: Required()
+ }
+ );
+};
+
+exports['test:resolve: renaming required properties has no effect'] =
+function (test) {
+ assertSametrait(test,
+ resolve(
+ { b: 'a' },
+ trait({ a: 2, b: required })
+ ),
+ {
+ a: Data(2),
+ b: Required()
+ }
+ );
+};
+
+exports['test:resolve: renaming of non-existent props has no effect'] =
+function (test) {
+ assertSametrait(test,
+ resolve(
+ { a: 'c', d: 'c' },
+ trait({ a: 1, b: 2 })
+ ),
+ {
+ c: Data(1),
+ b: Data(2),
+ a: Required()
+ }
+ );
+};
+
+exports['test:resolve: exclusion of non-existent props has no effect'] =
+function (test) {
+ assertSametrait(test,
+ resolve(
+ { b: undefined },
+ trait({ a: 1 })
+ ),
+ {
+ a: Data(1)
+ }
+ );
+};
+
+exports['test:resolve is neutral w.r.t. required properties'] =
+function (test) {
+ assertSametrait(test,
+ resolve(
+ { a: 'c', b: undefined },
+ trait({ a: required, b: required, c: 'foo', d: 1 })
+ ),
+ {
+ a: Required(),
+ b: Required(),
+ c: Data('foo'),
+ d: Data(1)
+ }
+ );
+};
+
+exports['test:resolve supports swapping of property names, ordering 1'] =
+function (test) {
+ assertSametrait(test,
+ resolve(
+ { a: 'b', b: 'a' },
+ trait({ a: 1, b: 2 })
+ ),
+ {
+ a: Data(2),
+ b: Data(1)
+ }
+ );
+};
+
+exports['test:resolve supports swapping of property names, ordering 2'] =
+function (test) {
+ assertSametrait(test,
+ resolve(
+ { b: 'a', a: 'b' },
+ trait({ a: 1, b: 2 })
+ ),
+ {
+ a: Data(2),
+ b: Data(1)
+ }
+ );
+};
+
+exports['test:resolve supports swapping of property names, ordering 3'] =
+function (test) {
+ assertSametrait(test,
+ resolve(
+ { b: 'a', a: 'b' },
+ trait({ b: 2, a: 1 })
+ ),
+ {
+ a: Data(2),
+ b: Data(1)
+ }
+ );
+};
+
+exports['test:resolve supports swapping of property names, ordering 4'] =
+function (test) {
+ assertSametrait(test,
+ resolve(
+ { a: 'b', b: 'a' },
+ trait({ b: 2, a: 1 })
+ ),
+ {
+ a: Data(2),
+ b: Data(1)
+ }
+ );
+};
+
+exports['test:override of mutually exclusive traits'] = function (test) {
+ assertSametrait(test,
+ override(
+ trait({ a: 1, b: 2 }),
+ trait({ c: 3, d: testMethod })
+ ),
+ {
+ a: Data(1),
+ b: Data(2),
+ c: Data(3),
+ d: Method(testMethod)
+ }
+ );
+};
+
+exports['test:override of mutually exclusive traits is compose'] =
+function (test) {
+ assertSametrait(test,
+ override(
+ trait({ a: 1, b: 2 }),
+ trait({ c: 3, d: testMethod })
+ ),
+ compose(
+ trait({ d: testMethod, c: 3 }),
+ trait({ b: 2, a: 1 })
+ )
+ );
+};
+
+exports['test:override of overlapping traits'] = function (test) {
+ assertSametrait(test,
+ override(
+ trait({ a: 1, b: 2 }),
+ trait({ a: 3, c: testMethod })
+ ),
+ {
+ a: Data(1),
+ b: Data(2),
+ c: Method(testMethod)
+ }
+ );
+};
+
+exports['test:three-way override of overlapping traits'] = function (test) {
+ assertSametrait(test,
+ override(
+ trait({ a: 1, b: 2 }),
+ trait({ b: 4, c: 3 }),
+ trait({ a: 3, c: testMethod, d: 5 })
+ ),
+ {
+ a: Data(1),
+ b: Data(2),
+ c: Data(3),
+ d: Data(5)
+ }
+ );
+};
+
+exports['test:override replaces required properties'] = function (test) {
+ assertSametrait(test,
+ override(
+ trait({ a: required, b: 2 }),
+ trait({ a: 1, c: testMethod })
+ ),
+ {
+ a: Data(1),
+ b: Data(2),
+ c: Method(testMethod)
+ }
+ );
+};
+
+exports['test:override is not commutative'] = function (test) {
+ assertSametrait(test,
+ override(
+ trait({ a: 1, b: 2 }),
+ trait({ a: 3, c: 4 })
+ ),
+ {
+ a: Data(1),
+ b: Data(2),
+ c: Data(4)
+ }
+ );
+
+ assertSametrait(test,
+ override(
+ trait({ a: 3, c: 4 }),
+ trait({ a: 1, b: 2 })
+ ),
+ {
+ a: Data(3),
+ b: Data(2),
+ c: Data(4)
+ }
+ );
+};
+
+exports['test:override is associative'] = function (test) {
+ assertSametrait(test,
+ override(
+ override(
+ trait({ a: 1, b: 2 }),
+ trait({ a: 3, c: 4, d: 5 })
+ ),
+ trait({ a: 6, c: 7, e: 8 })
+ ),
+ override(
+ trait({ a: 1, b: 2 }),
+ override(
+ trait({ a: 3, c: 4, d: 5 }),
+ trait({ a: 6, c: 7, e: 8 })
+ )
+ )
+ );
+};
+
+exports['test:create simple'] = function(test) {
+ let o1 = create(
+ Object.prototype,
+ trait({ a: 1, b: function() { return this.a; } })
+ );
+
+ test.assertEqual(
+ Object.prototype,
+ Object.getPrototypeOf(o1),
+ 'o1 prototype'
+ );
+ test.assertEqual(1, o1.a, 'o1.a');
+ test.assertEqual(1, o1.b(), 'o1.b()');
+ test.assertEqual(
+ 2,
+ Object.getOwnPropertyNames(o1).length,
+ 'Object.keys(o1).length === 2'
+ );
+};
+
+exports['test:create with Array.prototype'] = function(test) {
+ let o2 = create(Array.prototype, trait({}));
+ test.assertEqual(
+ Array.prototype,
+ Object.getPrototypeOf(o2),
+ "o2 prototype"
+ );
+};
+
+exports['test:exception for incomplete required properties'] =
+function(test) {
+ try {
+ create(Object.prototype, trait({ foo: required }));
+ test.fail('expected create to complain about missing required props');
+ } catch(e) {
+ test.assertEqual(
+ 'Error: Missing required property: foo',
+ e.toString(),
+ 'required prop error'
+ );
+ }
+};
+
+exports['test:exception for unresolved conflicts'] = function(test) {
+ try {
+ create({}, compose(trait({ a: 0 }), trait({ a: 1 })));
+ test.fail('expected create to complain about unresolved conflicts');
+ } catch(e) {
+ test.assertEqual(
+ 'Error: Remaining conflicting property: a',
+ e.toString(),
+ 'conflicting prop error'
+ );
+ }
+};
+
+exports['test:verify that required properties are present but undefined'] =
+function(test) {
+ try {
+ let o4 = Object.create(Object.prototype, trait({ foo: required }));
+ test.assertEqual(true, 'foo' in o4, 'required property present');
+ try {
+ let foo = o4.foo;
+ test.fail('access to required property must throw');
+ } catch(e) {
+ test.assertEqual(
+ 'Error: Missing required property: foo',
+ e.toString(),
+ 'required prop error'
+ )
+ }
+ } catch(e) {
+ test.fail('did not expect create to complain about required props');
+ }
+};
+
+exports['test:verify that conflicting properties are present'] =
+function(test) {
+ try {
+ let o5 = Object.create(
+ Object.prototype,
+ compose(trait({ a: 0 }), trait({ a: 1 }))
+ );
+ test.assertEqual(true, 'a' in o5, 'conflicting property present');
+ try {
+ let a = o5.a; // accessors or data prop
+ test.fail('expected conflicting prop to cause exception');
+ } catch (e) {
+ test.assertEqual(
+ 'Error: Remaining conflicting property: a',
+ e.toString(),
+ 'conflicting prop access error'
+ );
+ }
+ } catch(e) {
+ test.fail('did not expect create to complain about conflicting props');
+ }
+};
+
+exports['test diamond with conflicts'] = function(test) {
+ function makeT1(x) trait({ m: function() { return x; } })
+ function makeT2(x) compose(trait({ t2: 'foo' }), makeT1(x))
+ function makeT3(x) compose(trait({ t3: 'bar' }), makeT1(x))
+
+ let T4 = compose(makeT2(5), makeT3(5));
+ try {
+ let o = create(Object.prototype, T4);
+ test.fail('expected diamond prop to cause exception');
+ } catch(e) {
+ test.assertEqual(
+ 'Error: Remaining conflicting property: m',
+ e.toString(),
+ 'diamond prop conflict'
+ );
+ }
+};
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-traits.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-traits.js
new file mode 100644
index 0000000..8b88f94
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-traits.js
@@ -0,0 +1,398 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Trait } = require('traits');
+
+exports['test:simple compose'] = function(test) {
+ let List = Trait.compose({
+ _list: null,
+ constructor: function List() {
+ this._list = [];
+ },
+ list: function list() this._list.slice(0),
+ add: function add(item) this._list.push(item),
+ remove: function remove(item) {
+ let list = this._list;
+ let index = list.indexOf(item);
+ if (0 <= index) list.slice(index, 1);
+ }
+ });
+
+ test.assertNotEqual(undefined, List, 'should not be undefined');
+ test.assertEqual('function', typeof List, 'type should be function');
+ test.assertEqual(
+ Trait.compose,
+ List.compose,
+ 'should inherit static compose'
+ );
+ test.assertEqual(
+ Trait.override,
+ List.override,
+ 'should inherit static override'
+ );
+ test.assertEqual(
+ Trait.required,
+ List.required,
+ 'should inherit static required'
+ );
+ test.assertEqual(
+ Trait.resolve,
+ List.resolve,
+ 'should inherit static resolve'
+ );
+
+ test.assert(
+ !('_list' in List.prototype),
+ 'should not expose private API'
+ );
+}
+exports['test: compose trait instance and create instance'] = function(test) {
+ let List = Trait.compose({
+ constructor: function List(options) {
+ this._list = [];
+ this._public.publicMember = options.publicMember;
+ },
+ _privateMember: true,
+ get privateMember() this._privateMember,
+ get list() this._list.slice(0),
+ add: function add(item) this._list.push(item),
+ remove: function remove(item) {
+ let list = this._list
+ let index = list.indexOf(item)
+ if (0 <= index) list.slice(index, 1)
+ }
+ });
+ let list = List({ publicMember: true });
+
+ test.assertEqual('object', typeof list, 'should return an object')
+ test.assertEqual(
+ true,
+ list instanceof List,
+ 'should be instance of a List'
+ );
+
+ test.assertEqual(
+ undefined,
+ list._privateMember,
+ 'instance should not expose private API'
+ );
+
+ test.assertEqual(
+ true,
+ list.privateMember,
+ 'privates are accessible by public API'
+ );
+
+ list._privateMember = false;
+
+ test.assertEqual(
+ true,
+ list.privateMember,
+ 'property changes on instance must not affect privates'
+ );
+
+ test.assert(
+ !('_list' in list),
+ 'instance should not expose private members'
+ );
+
+ test.assertEqual(
+ true,
+ list.publicMember,
+ 'public members are exposed'
+ )
+ test.assertEqual(
+ 'function',
+ typeof list.add,
+ 'should be function'
+ )
+ test.assertEqual(
+ 'function',
+ typeof list.remove,
+ 'should be function'
+ );
+
+ list.add(1);
+ test.assertEqual(
+ 1,
+ list.list[0],
+ 'exposed public API should be able of modifying privates'
+ )
+};
+
+
+exports['test:instances must not be hackable'] = function(test) {
+ let SECRET = 'There is no secret!',
+ secret = null;
+
+ let Class = Trait.compose({
+ _secret: null,
+ protect: function(data) this._secret = data
+ });
+
+ let i1 = Class();
+ i1.protect(SECRET);
+
+ test.assertEqual(
+ undefined,
+ (function() this._secret).call(i1),
+ 'call / apply can\'t access private state'
+ );
+
+ let proto = Object.getPrototypeOf(i1);
+ try {
+ proto.reveal = function() this._secret;
+ secret = i1.reveal();
+ } catch(e) {}
+ test.assertNotEqual(
+ SECRET,
+ secret,
+ 'public __proto__ changes should not affect privates'
+ );
+ secret = null;
+
+ let Class2 = Trait.compose({
+ _secret: null,
+ protect: function(data) this._secret = data
+ });
+ let i2 = Class2();
+ i2.protect(SECRET);
+ try {
+ Object.prototype.reveal = function() this._secret;
+ secret = i2.reveal();
+ } catch(e) {}
+ test.assertNotEqual(
+ SECRET,
+ secret,
+ 'Object.prototype changes must not affect instances'
+ );
+}
+
+exports['test:instanceof'] = function(test) {
+ const List = Trait.compose({
+ // private API:
+ _list: null,
+ // public API
+ constructor: function List() {
+ this._list = []
+ },
+ get length() this._list.length,
+ add: function add(item) this._list.push(item),
+ remove: function remove(item) {
+ let list = this._list;
+ let index = list.indexOf(item);
+ if (0 <= index) list.slice(index, 1);
+ }
+ });
+
+ test.assert(List() instanceof List, 'Must be instance of List');
+ test.assert(new List() instanceof List, 'Must be instance of List');
+};
+
+exports['test:privates are unaccessible'] = function(test) {
+ const List = Trait.compose({
+ // private API:
+ _list: null,
+ // public API
+ constructor: function List() {
+ this._list = [];
+ },
+ get length() this._list.length,
+ add: function add(item) this._list.push(item),
+ remove: function remove(item) {
+ let list = this._list;
+ let index = list.indexOf(item);
+ if (0 <= index) list.slice(index, 1);
+ }
+ });
+
+ let list = List();
+ test.assert(!('_list' in list), 'no privates on instance');
+ test.assert(
+ !('_list' in List.prototype),
+ 'no privates on prototype'
+ );
+};
+
+exports['test:public API can access private API'] = function(test) {
+ const List = Trait.compose({
+ // private API:
+ _list: null,
+ // public API
+ constructor: function List() {
+ this._list = [];
+ },
+ get length() this._list.length,
+ add: function add(item) this._list.push(item),
+ remove: function remove(item) {
+ let list = this._list;
+ let index = list.indexOf(item);
+ if (0 <= index) list.slice(index, 1);
+ }
+ });
+ let list = List();
+
+ list.add('test');
+
+ test.assertEqual(
+ 1,
+ list.length,
+ 'should be able to add element and access it from public getter'
+ );
+};
+
+exports['test:required'] = function(test) {
+ const Enumerable = Trait.compose({
+ list: Trait.required,
+ forEach: function forEach(consumer) {
+ return this.list.forEach(consumer);
+ }
+ });
+
+ try {
+ let i = Enumerable();
+ test.fail('should throw when creating instance with required properties');
+ } catch(e) {
+ test.assertEqual(
+ 'Error: Missing required property: list',
+ e.toString(),
+ 'required prop error'
+ );
+ }
+};
+
+exports['test:compose with required'] = function(test) {
+ const List = Trait.compose({
+ // private API:
+ _list: null,
+ // public API
+ constructor: function List() {
+ this._list = [];
+ },
+ get length() this._list.length,
+ add: function add(item) this._list.push(item),
+ remove: function remove(item) {
+ let list = this._list;
+ let index = list.indexOf(item);
+ if (0 <= index) list.slice(index, 1);
+ }
+ });
+
+ const Enumerable = Trait.compose({
+ list: Trait.required,
+ forEach: function forEach(consumer) {
+ return this.list.forEach(consumer);
+ }
+ });
+
+ const EnumerableList = Enumerable.compose({
+ get list() this._list.slice(0)
+ }, List);
+
+ let array = [1,2, 'ab']
+ let l = EnumerableList(array);
+ array.forEach(function(element) l.add(element));
+ let number = 0;
+ l.forEach(function(element, index) {
+ number ++;
+ test.assertEqual(array[index], element, 'should mach array element')
+ });
+ test.assertEqual(
+ array.length,
+ number,
+ 'should perform as many asserts as elements in array'
+ );
+};
+
+exports['test:resolve'] = function(test) {
+ const List = Trait.compose({
+ // private API:
+ _list: null,
+ // public API
+ constructor: function List() {
+ this._list = [];
+ },
+ get length() this._list.length,
+ add: function add(item) this._list.push(item),
+ remove: function remove(item) {
+ let list = this._list;
+ let index = list.indexOf(item);
+ if (0 <= index) list.slice(index, 1);
+ }
+ });
+
+ const Range = List.resolve({
+ constructor: null,
+ add: '_add',
+ }).compose({
+ min: null,
+ max: null,
+ get list() this._list.slice(0),
+ constructor: function Range(min, max) {
+ this.min = min;
+ this.max = max;
+ this._list = [];
+ },
+ add: function(item) {
+ if (item <= this.max && item >= this.min)
+ this._add(item)
+ }
+ });
+
+ let r = Range(0, 10);
+
+ test.assertEqual(
+ 0,
+ r.min,
+ 'constructor must have set min'
+ );
+ test.assertEqual(
+ 10,
+ r.max,
+ 'constructor must have set max'
+ );
+
+ test.assertEqual(
+ 0,
+ r.length,
+ 'should not contain any elements'
+ );
+
+ r.add(5);
+
+ test.assertEqual(
+ 1,
+ r.length,
+ 'should add `5` to list'
+ );
+
+ r.add(12);
+
+ test.assertEqual(
+ 1,
+ r.length,
+ 'should not add `12` to list'
+ );
+};
+
+exports['test:custom iterator'] = function(test) {
+ let Sub = Trait.compose({
+ foo: "foo",
+ bar: "bar",
+ baz: "baz",
+ __iterator__: function() {
+ yield 1;
+ yield 2;
+ yield 3;
+ }
+ });
+
+ let (i = 0, sub = Sub()) {
+ for (let item in sub)
+ test.assertEqual(++i, item, "iterated item has the right value");
+ };
+};
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-type.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-type.js
new file mode 100644
index 0000000..d5b5775
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-type.js
@@ -0,0 +1,92 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict"
+
+var utils = require("type");
+
+exports["test function"] = function (assert) {
+ assert.ok(utils.isFunction(function(){}), "value is function");
+ assert.ok(utils.isFunction(Object), "Object is function");
+ assert.ok(utils.isFunction(new Function("")), "Genertaed value is function");
+ assert.ok(!utils.isFunction({}), "object is not a function");
+ assert.ok(!utils.isFunction(4), "number is not a function");
+};
+
+exports["test atoms"] = function (assert) {
+ assert.ok(utils.isPrimitive(2), "number is primitive");
+ assert.ok(utils.isPrimitive(NaN), "`NaN` is primitve");
+ assert.ok(utils.isPrimitive(undefined), "`undefined` is primitive");
+ assert.ok(utils.isPrimitive(null), "`null` is primitive");
+ assert.ok(utils.isPrimitive(Infinity), "`Infinity` is primitive");
+ assert.ok(utils.isPrimitive("foo"), "strings are primitive");
+ assert.ok(utils.isPrimitive(true) && utils.isPrimitive(false),
+ "booleans are primitive");
+};
+
+exports["test object"] = function (assert) {
+ assert.ok(utils.isObject({}), "`{}` is object");
+ assert.ok(!utils.isObject(null), "`null` is not an object");
+ assert.ok(!utils.isObject(Object), "functions is not an object");
+};
+
+exports["test flat objects"] = function (assert) {
+ assert.ok(utils.isFlat({}), "`{}` is a flat object");
+ assert.ok(!utils.isFlat([]), "`[]` is not a flat object");
+ assert.ok(!utils.isFlat(new function() {}), "derived objects are not flat");
+ assert.ok(utils.isFlat(Object.prototype), "Object.prototype is flat");
+};
+
+exports["test json atoms"] = function (assert) {
+ assert.ok(utils.isJSON(null), "`null` is JSON");
+ assert.ok(utils.isJSON(undefined), "`undefined` is JSON");
+ assert.ok(utils.isJSON(NaN), "`NaN` is JSON");
+ assert.ok(utils.isJSON(Infinity), "`Infinity` is JSON");
+ assert.ok(utils.isJSON(true) && utils.isJSON(false), "booleans are JSON");
+ assert.ok(utils.isJSON(4), utils.isJSON(0), "numbers are JSON");
+ assert.ok(utils.isJSON("foo bar"), "strings are JSON");
+};
+
+exports["test instanceOf"] = function (assert) {
+ assert.ok(utils.instanceOf(assert, Object),
+ "assert is object from other sandbox");
+ assert.ok(utils.instanceOf(new Date(), Date), "instance of date");
+ assert.ok(!utils.instanceOf(null, Object), "null is not an instance");
+};
+
+exports["test json"] = function (assert) {
+ assert.ok(!utils.isJSON(function(){}), "functions are not json");
+ assert.ok(utils.isJSON({}), "`{}` is JSON");
+ assert.ok(utils.isJSON({
+ a: "foo",
+ b: 3,
+ c: undefined,
+ d: null,
+ e: {
+ f: {
+ g: "bar",
+ p: [{}, "oueou", 56]
+ },
+ q: { nan: NaN, infinity: Infinity },
+ "non standard name": "still works"
+ }
+ }), "JSON can contain nested objects");
+
+ var foo = {};
+ var bar = { foo: foo };
+ foo.bar = bar;
+ assert.ok(!utils.isJSON(foo), "recursive objects are not json");
+
+
+ assert.ok(!utils.isJSON({ get foo() { return 5 } }),
+ "json can not have getter");
+
+ assert.ok(!utils.isJSON({ foo: "bar", baz: function () {} }),
+ "json can not contain functions");
+
+ assert.ok(!utils.isJSON(Object.create({})),
+ "json must be direct descendant of `Object.prototype`");
+};
+
+require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-unit-test.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-unit-test.js
new file mode 100644
index 0000000..8ee99a4
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-unit-test.js
@@ -0,0 +1,251 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const timer = require("timer");
+const { Loader } = require("./helpers");
+
+var setupCalled = false, teardownCalled = false;
+
+exports.setup = function() {
+ setupCalled = true;
+};
+
+exports.teardown = function() {
+ teardownCalled = true;
+ setupCalled = false;
+};
+
+// Important note - unit tests are run in alphabetical order. The following
+// unit tests for setup/teardown are order dependent, sometimes the result of
+// one test is checked in the next test (testing for teardown does this). When
+// tests are cohesively a single unit, they are named <test_name> - partN where
+// N is their order in the sequence. Secondly, because these tests should be
+// run before all others, they start with an A.
+exports.testASetupTeardownSyncTestPart1 = function(test) {
+ test.assertEqual(true, setupCalled, 'setup function was called before this');
+ test.assertEqual(false, teardownCalled, 'teardown function was not called before this');
+};
+
+exports.testASetupTeardownSyncTestPart2 = function(test) {
+ test.assertEqual(true, setupCalled, 'setup was re-called before this');
+ test.assertEqual(true, teardownCalled, 'teardown was called after first function');
+};
+
+exports.testATeardownAsyncTestPart1 = function(test) {
+ teardownCalled = false;
+
+ timer.setTimeout(function() {
+ test.assertEqual(false, teardownCalled, "teardown not called until done");
+ test.done();
+ }, 200);
+ test.waitUntilDone();
+};
+
+exports.testATeardownAsyncTestPart2 = function(test) {
+ test.assertEqual(true, teardownCalled, "teardown called after done");
+};
+
+exports.testWaitUntilInstant = function(test) {
+ test.waitUntilDone();
+
+ test.waitUntil(function () true, "waitUntil with instant true pass")
+ .then(function () test.done());
+}
+
+exports.testWaitUntil = function(test) {
+ test.waitUntilDone();
+ let succeed = false;
+
+ test.waitUntil(function () succeed, "waitUntil pass")
+ .then(function () test.done());
+
+ timer.setTimeout(function () {
+ succeed = true;
+ }, 200);
+}
+
+exports.testWaitUntilEqual = function(test) {
+ test.waitUntilDone();
+ let succeed = false;
+
+ test.waitUntilEqual("foo", function () succeed ? "foo" : "bar",
+ "waitUntilEqual pass")
+ .then(function () test.done());
+
+ timer.setTimeout(function () {
+ succeed = true;
+ }, 200);
+}
+
+exports.testWaitUntilNotEqual = function(test) {
+ test.waitUntilDone();
+ let succeed = false;
+
+ test.waitUntilNotEqual("foo", function () succeed ? "bar" : "foo",
+ "waitUntilNotEqual pass")
+ .then(function () test.done());
+
+ timer.setTimeout(function () {
+ succeed = true;
+ }, 200);
+}
+
+exports.testWaitUntilMatches = function(test) {
+ test.waitUntilDone();
+ let succeed = false;
+
+ test.waitUntilMatches(function () succeed ? "foo" : "bar",
+ /foo/, "waitUntilEqual pass")
+ .then(function () test.done());
+
+ timer.setTimeout(function () {
+ succeed = true;
+ }, 200);
+}
+
+exports.testWaitUntilErrorInCallback = function(test) {
+ test.waitUntilDone();
+
+ test.expectFail(function() {
+ test.waitUntil(function () {throw "oops"}, "waitUntil pass")
+ .then(function () test.done());
+ });
+}
+
+exports.testWaitUntilTimeoutInCallback = function(test) {
+ test.waitUntilDone(1000);
+
+ let runner = new (require("unit-test").TestRunner)({
+ console: {
+ calls: 0,
+ error: function(msg) {
+ this.calls++;
+ if (this.calls == 1)
+ test.assertEqual(arguments[0], "TEST FAILED: wait4ever (timed out)");
+ else if (this.calls == 2) {
+ test.assertEqual(arguments[0], "test assertion never became true:\n");
+ test.assertEqual(arguments[1], "assertion failed, value is false\n");
+ // We could additionally check that arguments[1] contains the correct
+ // stack, but it would be difficult to do so given that it contains
+ // resource: URLs with a randomly generated string embedded in them
+ // (the ID of the test addon created to run the tests). And in any
+ // case, checking the arguments seems sufficient.
+
+ test.done();
+ }
+ else {
+ test.fail("We got unexpected console.error() calls from waitUntil" +
+ " assertion callback: '" + arguments[1] + "'");
+ }
+ },
+ trace: function () {}
+ }
+ });
+
+ runner.start({
+ test: {
+ name: "wait4ever",
+ testFunction: function(test) {
+ test.waitUntilDone(100);
+ test.waitUntil(function() false);
+ }
+ },
+ onDone: function() {}
+ });
+};
+
+exports.testExpectFail = function(test) {
+ test.expectFail(function() {
+ test.fail('expectFail masking .fail');
+ });
+
+ test.expectFail(function() {
+ test.assert(false, 'expectFail masking .assert');
+ });
+
+ test.assert(true, 'assert should pass with no expectFail');
+/*
+ test.expectFail(function() {
+ test.expectFail(function() {
+ test.fail('this should blow up');
+ });
+ });
+*/
+};
+
+exports.testAssertFunction = function(test) {
+ test.assertFunction(function() {}, 'assertFunction with function');
+ test.expectFail(function() {
+ test.assertFunction(null, 'assertFunction with non-function');
+ });
+};
+
+exports.testAssertUndefined = function(test) {
+ test.assertUndefined(undefined, 'assertUndefined with undefined');
+ test.expectFail(function() {
+ test.assertUndefined(null, 'assertUndefined with null');
+ });
+ test.expectFail(function() {
+ test.assertUndefined(false, 'assertUndefined with false');
+ });
+ test.expectFail(function() {
+ test.assertUndefined(0, 'assertUndefined with 0');
+ });
+};
+
+exports.testAssertNotUndefined = function(test) {
+ test.expectFail(function() {
+ test.assertNotUndefined(undefined, 'assertNotUndefined with undefined');
+ });
+ test.assertNotUndefined(null, 'assertNotUndefined with null');
+ test.assertNotUndefined(false, 'assertNotUndefined with false');
+ test.assertNotUndefined(0, 'assertNotUndefined with 0');
+};
+
+exports.testAssertNull = function(test) {
+ test.assertNull(null, 'assertNull with null');
+ test.expectFail(function() {
+ test.assertNull(undefined, 'assertNull with undefined');
+ });
+ test.expectFail(function() {
+ test.assertNull(false, 'assertNull with false');
+ });
+ test.expectFail(function() {
+ test.assertNull(0, 'assertNull with 0');
+ });
+};
+
+exports.testAssertNotNull = function(test) {
+ test.assertNotNull(undefined, 'assertNotNull with undefined');
+ test.assertNotNull(false, 'assertNotNull with false');
+ test.assertNotNull(0, 'assertNotNull with 0');
+
+ test.expectFail(function() {
+ test.assertNotNull(null, 'testAssertNotNull with null');
+ });
+};
+
+exports.testAssertObject = function(test) {
+ test.assertObject({}, 'assertObject with {}' );
+ test.assertObject(new Object(), 'assertObject with new Object');
+ test.expectFail(function() {
+ test.assertObject('fail', 'assertObject with string');
+ });
+};
+
+exports.testAssertString = function(test) {
+ test.assertString('', 'assertString with ""');
+ test.assertString(new String(), 'assertString with new String');
+};
+
+exports.testAssertArray = function(test) {
+ test.assertArray([], 'assertArray with []');
+ test.assertArray(new Array(), 'assertArray with new Array');
+};
+
+exports.testNumber = function(test) {
+ test.assertNumber(1, 'assertNumber with 1');
+ test.assertNumber(new Number('2'), 'assertNumber with new Number("2")' );
+};
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-unload.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-unload.js
new file mode 100644
index 0000000..e05b4e0
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-unload.js
@@ -0,0 +1,161 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var unload = require("unload");
+var { Loader } = require("./helpers");
+
+exports.testUnloading = function(test) {
+ var loader = Loader(module);
+ var ul = loader.require("unload");
+ var unloadCalled = 0;
+ var errorsReported = 0;
+ function unload() {
+ unloadCalled++;
+ throw new Error("error");
+ }
+ ul.when(unload);
+
+ // This should be ignored, as we already registered it
+ ul.when(unload);
+
+ function unload2() { unloadCalled++; }
+ ul.when(unload2);
+ loader.unload(undefined, function onError() { errorsReported++; });
+ test.assertEqual(unloadCalled, 2,
+ "Unloader functions are called on unload.");
+ test.assertEqual(errorsReported, 1,
+ "One unload handler threw exception");
+};
+
+exports.testEnsure = function(test) {
+ test.assertRaises(function() { unload.ensure({}); },
+ "object has no 'unload' property",
+ "passing obj with no unload prop should fail");
+ test.assertRaises(function() { unload.ensure({}, "destroy"); },
+ "object has no 'destroy' property",
+ "passing obj with no custom unload prop should fail");
+
+ var called = 0;
+ var obj = {unload: function() { called++; }};
+
+ unload.ensure(obj);
+ obj.unload();
+ test.assertEqual(called, 1,
+ "unload() should be called");
+ obj.unload();
+ test.assertEqual(called, 1,
+ "unload() should be called only once");
+};
+
+/**
+ * Check that destructors are called only once with Traits.
+ * - check that public API is calling the destructor and unregister it,
+ * - check that composed traits with multiple ensure calls, leads to only
+ * one destructor call.
+ */
+exports.testEnsureWithTraits = function(test) {
+
+ let { Trait } = require("traits");
+ let loader = Loader(module);
+ let ul = loader.require("unload");
+
+ let called = 0;
+ let composedCalled = 0;
+ let composedTrait = Trait.compose({
+ constructor: function () {
+ // We have to give "public interface" of this trait, as we want to
+ // call public `unload` method and ensure that we call it only once,
+ // either when we call this public function manually or on add-on unload
+ ul.ensure(this._public);
+ },
+ unload: function unload() {
+ composedCalled++;
+ }
+ });
+ let obj = Trait.compose(
+ composedTrait.resolve({
+ constructor: "_constructor",
+ unload : "_unload"
+ }), {
+ constructor: function constructor() {
+ // Same thing applies here, we need to pass public interface
+ ul.ensure(this._public);
+ this._constructor();
+ },
+ unload: function unload() {
+ called++;
+ this._unload();
+ }
+ })();
+
+ obj.unload();
+ test.assertEqual(called, 1,
+ "unload() should be called");
+
+ test.assertEqual(composedCalled, 1,
+ "composed object unload() should be called");
+
+ obj.unload();
+ test.assertEqual(called, 1,
+ "unload() should be called only once");
+ test.assertEqual(composedCalled, 1,
+ "composed object unload() should be called only once");
+
+ loader.unload();
+ test.assertEqual(called, 1,
+ "unload() should be called only once, after addon unload");
+ test.assertEqual(composedCalled, 1,
+ "composed object unload() should be called only once, " +
+ "after addon unload");
+};
+
+exports.testEnsureWithTraitsPrivate = function(test) {
+
+ let { Trait } = require("traits");
+ let loader = Loader(module);
+ let ul = loader.require("unload");
+
+ let called = 0;
+ let privateObj = null;
+ let obj = Trait.compose({
+ constructor: function constructor() {
+ // This time wa don't have to give public interface,
+ // as we want to call a private method:
+ ul.ensure(this, "_unload");
+ privateObj = this;
+ },
+ _unload: function unload() {
+ called++;
+ this._unload();
+ }
+ })();
+
+ loader.unload();
+ test.assertEqual(called, 1,
+ "unload() should be called");
+
+ privateObj._unload();
+ test.assertEqual(called, 1,
+ "_unload() should be called only once, after addon unload");
+};
+
+exports.testReason = function (test) {
+ var reason = "Reason doesn't actually have to be anything in particular.";
+ var loader = Loader(module);
+ var ul = loader.require("unload");
+ ul.when(function (rsn) {
+ test.assertEqual(rsn, reason,
+ "when() reason should be reason given to loader");
+ });
+ var obj = {
+ unload: function (rsn) {
+ test.assertEqual(rsn, reason,
+ "ensure() reason should be reason given to loader");
+ }
+ };
+ ul.ensure(obj);
+ loader.unload(reason);
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-url.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-url.js
new file mode 100644
index 0000000..f217400
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-url.js
@@ -0,0 +1,204 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var url = require("url");
+
+exports.testResolve = function(test) {
+ test.assertEqual(url.URL("bar", "http://www.foo.com/").toString(),
+ "http://www.foo.com/bar");
+
+ test.assertEqual(url.URL("bar", "http://www.foo.com"),
+ "http://www.foo.com/bar");
+
+ test.assertEqual(url.URL("http://bar.com/", "http://foo.com/"),
+ "http://bar.com/",
+ "relative should override base");
+
+ test.assertRaises(function() { url.URL("blah"); },
+ "malformed URI: blah",
+ "url.resolve() should throw malformed URI on base");
+
+ test.assertRaises(function() { url.URL("chrome://global"); },
+ "invalid URI: chrome://global",
+ "url.resolve() should throw invalid URI on base");
+
+ test.assertRaises(function() { url.URL("chrome://foo/bar"); },
+ "invalid URI: chrome://foo/bar",
+ "url.resolve() should throw on bad chrome URI");
+
+ test.assertEqual(url.URL("", "http://www.foo.com"),
+ "http://www.foo.com/",
+ "url.resolve() should add slash to end of domain");
+};
+
+exports.testParseHttp = function(test) {
+ var info = url.URL("http://foo.com/bar");
+ test.assertEqual(info.scheme, "http");
+ test.assertEqual(info.host, "foo.com");
+ test.assertEqual(info.port, null);
+ test.assertEqual(info.userPass, null);
+ test.assertEqual(info.path, "/bar");
+};
+
+exports.testParseHttpWithPort = function(test) {
+ var info = url.URL("http://foo.com:5/bar");
+ test.assertEqual(info.port, 5);
+};
+
+exports.testParseChrome = function(test) {
+ var info = url.URL("chrome://global/content/blah");
+ test.assertEqual(info.scheme, "chrome");
+ test.assertEqual(info.host, "global");
+ test.assertEqual(info.port, null);
+ test.assertEqual(info.userPass, null);
+ test.assertEqual(info.path, "/content/blah");
+};
+
+exports.testParseAbout = function(test) {
+ var info = url.URL("about:boop");
+ test.assertEqual(info.scheme, "about");
+ test.assertEqual(info.host, null);
+ test.assertEqual(info.port, null);
+ test.assertEqual(info.userPass, null);
+ test.assertEqual(info.path, "boop");
+};
+
+exports.testParseFTP = function(test) {
+ var info = url.URL("ftp://1.2.3.4/foo");
+ test.assertEqual(info.scheme, "ftp");
+ test.assertEqual(info.host, "1.2.3.4");
+ test.assertEqual(info.port, null);
+ test.assertEqual(info.userPass, null);
+ test.assertEqual(info.path, "/foo");
+};
+
+exports.testParseFTPWithUserPass = function(test) {
+ var info = url.URL("ftp://user:pass@1.2.3.4/foo");
+ test.assertEqual(info.userPass, "user:pass");
+};
+
+// rootURI is jar:file://...!/ if we're packed, and file://.../ if we're
+// unpacked. url.toFilename() is not required to work for the contents of
+// packed XPIs
+var unpacked = (require("@packaging").rootURI.indexOf("file:") == 0);
+
+exports.testToFilename = function(test) {
+ test.assertRaises(
+ function() { url.toFilename("resource://nonexistent"); },
+ "resource does not exist: resource://nonexistent/",
+ "url.toFilename() on nonexistent resources should throw"
+ );
+
+ if (unpacked)
+ test.assertMatches(url.toFilename(module.uri),
+ /.*test-url\.js$/,
+ "url.toFilename() on resource: URIs should work");
+ else
+ test.assertRaises(
+ function() { url.toFilename(module.uri); },
+ "cannot map to filename: "+module.uri,
+ "url.toFilename() can fail for packed XPIs");
+
+ test.assertRaises(
+ function() { url.toFilename("http://foo.com/"); },
+ "cannot map to filename: http://foo.com/",
+ "url.toFilename() on http: URIs should raise error"
+ );
+
+ try {
+ test.assertMatches(
+ url.toFilename("chrome://global/content/console.xul"),
+ /.*console\.xul$/,
+ "url.toFilename() w/ console.xul works when it maps to filesystem"
+ );
+ } catch (e) {
+ if (/chrome url isn\'t on filesystem/.test(e.message))
+ test.pass("accessing console.xul in jar raises exception");
+ else
+ test.fail("accessing console.xul raises " + e);
+ }
+
+ // TODO: Are there any chrome URLs that we're certain exist on the
+ // filesystem?
+ // test.assertMatches(url.toFilename("chrome://myapp/content/main.js"),
+ // /.*main\.js$/);
+};
+
+exports.testFromFilename = function(test) {
+ var profileDirName = require("system").pathFor("ProfD");
+ var fileUrl = url.fromFilename(profileDirName);
+ test.assertEqual(url.URL(fileUrl).scheme, 'file',
+ 'url.toFilename() should return a file: url');
+ test.assertEqual(url.fromFilename(url.toFilename(fileUrl)),
+ fileUrl);
+};
+
+exports.testURL = function(test) {
+ let URL = url.URL;
+ test.assert(URL("h:foo") instanceof URL, "instance is of correct type");
+ test.assertRaises(function() URL(),
+ "malformed URI: undefined",
+ "url.URL should throw on undefined");
+ test.assertRaises(function() URL(""),
+ "malformed URI: ",
+ "url.URL should throw on empty string");
+ test.assertRaises(function() URL("foo"),
+ "malformed URI: foo",
+ "url.URL should throw on invalid URI");
+ test.assert(URL("h:foo").scheme, "has scheme");
+ test.assertEqual(URL("h:foo").toString(),
+ "h:foo",
+ "toString should roundtrip");
+ // test relative + base
+ test.assertEqual(URL("mypath", "http://foo").toString(),
+ "http://foo/mypath",
+ "relative URL resolved to base");
+ // test relative + no base
+ test.assertRaises(function() URL("path").toString(),
+ "malformed URI: path",
+ "no base for relative URI should throw");
+
+ let a = URL("h:foo");
+ let b = URL(a);
+ test.assertEqual(b.toString(),
+ "h:foo",
+ "a URL can be initialized from another URL");
+ test.assertNotStrictEqual(a, b,
+ "a URL initialized from another URL is not the same object");
+ test.assert(a == "h:foo",
+ "toString is implicit when a URL is compared to a string via ==");
+ test.assertStrictEqual(a + "", "h:foo",
+ "toString is implicit when a URL is concatenated to a string");
+};
+
+exports.testStringInterface = function(test) {
+ let URL = url.URL;
+ var EM = "about:addons";
+ var a = URL(EM);
+
+ // make sure the standard URL properties are enumerable and not the String interface bits
+ test.assertEqual(Object.keys(a), "scheme,userPass,host,port,path", "enumerable key list check for URL.");
+ test.assertEqual(
+ JSON.stringify(a),
+ "{\"scheme\":\"about\",\"userPass\":null,\"host\":null,\"port\":null,\"path\":\"addons\"}",
+ "JSON.stringify should return a object with correct props and vals.");
+
+ // make sure that the String interface exists and works as expected
+ test.assertEqual(a.indexOf(":"), EM.indexOf(":"), "indexOf on URL works");
+ test.assertEqual(a.valueOf(), EM.valueOf(), "valueOf on URL works.");
+ test.assertEqual(a.toSource(), EM.toSource(), "toSource on URL works.");
+ test.assertEqual(a.lastIndexOf("a"), EM.lastIndexOf("a"), "lastIndexOf on URL works.");
+ test.assertEqual(a.match("t:").toString(), EM.match("t:").toString(), "match on URL works.");
+ test.assertEqual(a.toUpperCase(), EM.toUpperCase(), "toUpperCase on URL works.");
+ test.assertEqual(a.toLowerCase(), EM.toLowerCase(), "toLowerCase on URL works.");
+ test.assertEqual(a.split(":").toString(), EM.split(":").toString(), "split on URL works.");
+ test.assertEqual(a.charAt(2), EM.charAt(2), "charAt on URL works.");
+ test.assertEqual(a.charCodeAt(2), EM.charCodeAt(2), "charCodeAt on URL works.");
+ test.assertEqual(a.concat(EM), EM.concat(a), "concat on URL works.");
+ test.assertEqual(a.substr(2,3), EM.substr(2,3), "substr on URL works.");
+ test.assertEqual(a.substring(2,3), EM.substring(2,3), "substring on URL works.");
+ test.assertEqual(a.trim(), EM.trim(), "trim on URL works.");
+ test.assertEqual(a.trimRight(), EM.trimRight(), "trimRight on URL works.");
+ test.assertEqual(a.trimLeft(), EM.trimLeft(), "trimLeft on URL works.");
+}
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-uuid.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-uuid.js
new file mode 100644
index 0000000..5670023
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-uuid.js
@@ -0,0 +1,27 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { uuid } = require('api-utils/uuid');
+
+exports['test generate uuid'] = function(assert) {
+ let signature = /{[0-9a-f\-]+}/
+ let first = String(uuid());
+ let second = String(uuid());
+
+ assert.ok(signature.test(first), 'first guid has a correct signature');
+ assert.ok(signature.test(second), 'second guid has a correct signature');
+ assert.notEqual(first, second, 'guid generates new guid on each call');
+};
+
+exports['test parse uuid'] = function(assert) {
+ let firefoxUUID = '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}';
+ let actual = uuid(firefoxUUID);
+
+ assert.equal(actual.number, firefoxUUID, 'uuid parsed given string');
+ assert.equal(String(actual), firefoxUUID, 'serializes to the same value');
+};
+
+require('test').run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-window-loader.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-window-loader.js
new file mode 100644
index 0000000..0a5ab84
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-window-loader.js
@@ -0,0 +1,120 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const { WindowLoader } = require('windows/loader'),
+ { Trait } = require('traits');
+
+const Loader = Trait.compose(
+ WindowLoader,
+ {
+ constructor: function Loader(options) {
+ this._onLoad = options.onLoad;
+ this._onUnload = options.onUnload;
+ if ('window' in options)
+ this._window = options.window;
+ this._load();
+ this.window = this._window;
+ },
+ window: null,
+ _onLoad: null,
+ _onUnload: null,
+ _tabOptions: []
+ }
+);
+
+exports['test compositions with missing required properties'] = function(test) {
+ test.assertRaises(
+ function() WindowLoader.compose({})(),
+ 'Missing required property: _onLoad',
+ 'should throw missing required property exception'
+ );
+ test.assertRaises(
+ function() WindowLoader.compose({ _onLoad: null, _tabOptions: null })(),
+ 'Missing required property: _onUnload',
+ 'should throw missing required property `_onUnload`'
+ );
+ test.assertRaises(
+ function() WindowLoader.compose({ _onUnload: null, _tabOptions: null })(),
+ 'Missing required property: _onLoad',
+ 'should throw missing required property `_onLoad`'
+ );
+ test.assertRaises(
+ function() WindowLoader.compose({ _onUnload: null, _onLoad: null })(),
+ 'Missing required property: _tabOptions',
+ 'should throw missing required property `_tabOptions`'
+ );
+};
+
+exports['test `load` events'] = function(test) {
+ test.waitUntilDone();
+ let onLoadCalled = false;
+ Loader({
+ onLoad: function(window) {
+ onLoadCalled = true;
+ test.assertEqual(
+ window, this._window, 'windows should match'
+ );
+ test.assertEqual(
+ window.document.readyState, 'complete', 'window must be fully loaded'
+ );
+ window.close();
+ },
+ onUnload: function(window) {
+ test.assertEqual(
+ window, this._window, 'windows should match'
+ );
+ test.assertEqual(
+ window.document.readyState, 'complete', 'window must be fully loaded'
+ );
+ test.assert(onLoadCalled, 'load callback is supposed to be called');
+ test.done();
+ }
+ });
+};
+
+exports['test removeing listeners'] = function(test) {
+ test.waitUntilDone();
+ Loader({
+ onLoad: function(window) {
+ test.assertEqual(
+ window, this._window, 'windows should match'
+ );
+ window.close();
+ },
+ onUnload: function(window) {
+ test.done();
+ }
+ });
+};
+
+exports['test create loader from opened window'] = function(test) {
+ test.waitUntilDone();
+ let onUnloadCalled = false;
+ Loader({
+ onLoad: function(window) {
+ test.assertEqual(
+ window, this._window, 'windows should match'
+ );
+ test.assertEqual(
+ window.document.readyState, 'complete', 'window must be fully loaded'
+ );
+ Loader({
+ window: window,
+ onLoad: function(win) {
+ test.assertEqual(win, window, 'windows should match');
+ window.close();
+ },
+ onUnload: function(window) {
+ test.assert(onUnloadCalled, 'first handler should be called already');
+ test.done();
+ }
+ });
+ },
+ onUnload: function(window) {
+ onUnloadCalled = true;
+ }
+ });
+};
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-window-observer.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-window-observer.js
new file mode 100644
index 0000000..687df04
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-window-observer.js
@@ -0,0 +1,48 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Loader } = require("./helpers");
+
+exports["test unload window observer"] = function(assert, done) {
+ // Hacky way to be able to create unloadable modules via makeSandboxedLoader.
+ let loader = Loader(module);
+
+ let utils = loader.require("api-utils/window-utils");
+ let { isBrowser, activeBrowserWindow: activeWindow } = utils;
+ let observer = loader.require("api-utils/windows/observer").observer;
+ let opened = 0;
+ let closed = 0;
+
+ observer.on("open", function onOpen(window) {
+ // Ignoring non-browser windows
+ if (isBrowser(window))
+ opened++;
+ });
+ observer.on("close", function onClose(window) {
+ // Ignore non-browser windows & already opened `activeWindow` (unload will
+ // emit close on it even though it is not actually closed).
+ if (isBrowser(window) && window !== activeWindow)
+ closed++;
+ });
+
+ // Open window and close it to trigger observers.
+ activeWindow.open().close();
+
+ // Unload the module so that all listeners set by observer are removed.
+ loader.unload();
+
+ // Open and close window once again.
+ activeWindow.open().close();
+
+ // Enqueuing asserts to make sure that assertion is not performed early.
+ require("timer").setTimeout(function () {
+ assert.equal(1, opened, "observer open was called before unload only");
+ assert.equal(1, closed, "observer close was called before unload only");
+ done();
+ }, 0);
+};
+
+require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-window-utils.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-window-utils.js
new file mode 100644
index 0000000..9985458
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-window-utils.js
@@ -0,0 +1,321 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+var windowUtils = require("api-utils/window-utils");
+var timer = require("api-utils/timer");
+var { Cc, Ci } = require("chrome");
+var { Loader } = require("./helpers");
+
+function toArray(iterator) {
+ let array = [];
+ for each (let item in iterator())
+ array.push(item);
+ return array;
+}
+
+function makeEmptyWindow() {
+ var xulNs = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
+ var blankXul = ('<?xml version="1.0"?>' +
+ '<?xml-stylesheet href="chrome://global/skin/" ' +
+ ' type="text/css"?>' +
+ '<window xmlns="' + xulNs + '" windowtype="test:window">' +
+ '</window>');
+ var url = "data:application/vnd.mozilla.xul+xml," + escape(blankXul);
+ var features = ["chrome", "width=10", "height=10"];
+
+ var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"]
+ .getService(Ci.nsIWindowWatcher);
+ return ww.openWindow(null, url, null, features.join(","), null);
+}
+
+exports['test close on unload'] = function(assert) {
+ var timesClosed = 0;
+ var fakeWindow = {
+ _listeners: [],
+ addEventListener: function(name, func, bool) {
+ this._listeners.push(func);
+ },
+ removeEventListener: function(name, func, bool) {
+ var index = this._listeners.indexOf(func);
+ if (index == -1)
+ throw new Error("event listener not found");
+ this._listeners.splice(index, 1);
+ },
+ close: function() {
+ timesClosed++;
+ this._listeners.forEach(
+ function(func) {
+ func({target: fakeWindow.document});
+ });
+ },
+ document: {
+ get defaultView() { return fakeWindow; }
+ }
+ };
+
+ let loader = Loader(module);
+ loader.require("window-utils").closeOnUnload(fakeWindow);
+ assert.equal(fakeWindow._listeners.length, 1,
+ "unload listener added on closeOnUnload()");
+ assert.equal(timesClosed, 0,
+ "window not closed when registered.");
+ loader.require("unload").send();
+ assert.equal(timesClosed, 1,
+ "window closed on module unload.");
+ assert.equal(fakeWindow._listeners.length, 0,
+ "unload event listener removed on module unload");
+
+ timesClosed = 0;
+ loader.require("window-utils").closeOnUnload(fakeWindow);
+ assert.equal(timesClosed, 0,
+ "window not closed when registered.");
+ fakeWindow.close();
+ assert.equal(timesClosed, 1,
+ "window closed when close() called.");
+ assert.equal(fakeWindow._listeners.length, 0,
+ "unload event listener removed on window close");
+ loader.require("unload").send();
+ assert.equal(timesClosed, 1,
+ "window not closed again on module unload.");
+ loader.unload();
+};
+
+exports['test window watcher'] = function(assert, done) {
+ var myWindow;
+ var finished = false;
+
+ var delegate = {
+ onTrack: function(window) {
+ if (window == myWindow) {
+ assert.pass("onTrack() called with our test window");
+ timer.setTimeout(function() { myWindow.close(); }, 1);
+ }
+ },
+ onUntrack: function(window) {
+ if (window == myWindow) {
+ assert.pass("onUntrack() called with our test window");
+ timer.setTimeout(function() {
+ if (!finished) {
+ finished = true;
+ myWindow = null;
+ wt.unload();
+ done();
+ } else
+ assert.fail("finishTest() called multiple times.");
+ }, 1);
+ }
+ }
+ };
+
+ // test bug 638007 (new is optional), using new
+ var wt = new windowUtils.WindowTracker(delegate);
+ myWindow = makeEmptyWindow();
+};
+
+exports['test window watcher untracker'] = function(assert, done) {
+ var myWindow;
+ var tracks = 0;
+ var unloadCalled = false;
+
+ var delegate = {
+ onTrack: function(window) {
+ tracks = tracks + 1;
+ if (window == myWindow) {
+ assert.pass("onTrack() called with our test window");
+ timer.setTimeout(function() {
+ myWindow.close();
+ }, 1);
+ }
+ },
+ onUntrack: function(window) {
+ tracks = tracks - 1;
+ if (window == myWindow && !unloadCalled) {
+ unloadCalled = true;
+ timer.setTimeout(function() {
+ wt.unload();
+ }, 1);
+ }
+ if (0 > tracks) {
+ assert.fail("WindowTracker onUntrack was called more times than onTrack..");
+ }
+ else if (0 == tracks) {
+ timer.setTimeout(function() {
+ myWindow = null;
+ done();
+ }, 1);
+ }
+ }
+ };
+
+ // test bug 638007 (new is optional), not using new
+ var wt = windowUtils.WindowTracker(delegate);
+ myWindow = makeEmptyWindow();
+};
+
+// test that _unregWindow calls _unregLoadingWindow
+exports['test window watcher unregs 4 loading wins'] = function(assert, done) {
+ var myWindow;
+ var finished = false;
+ let browserWindow = Cc["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Ci.nsIWindowMediator)
+ .getMostRecentWindow("navigator:browser");
+ var counter = 0;
+
+ var delegate = {
+ onTrack: function(window) {
+ var type = window.document.documentElement.getAttribute("windowtype");
+ if (type == "test:window")
+ assert.fail("onTrack shouldn't have been executed.");
+ }
+ };
+ var wt = new windowUtils.WindowTracker(delegate);
+
+ // make a new window
+ myWindow = makeEmptyWindow();
+
+ // make sure that the window hasn't loaded yet
+ assert.notEqual(
+ myWindow.document.readyState,
+ "complete",
+ "window hasn't loaded yet.");
+
+ // unload WindowTracker
+ wt.unload();
+
+ // make sure that the window still hasn't loaded, which means that the onTrack
+ // would have been removed successfully assuming that it doesn't execute.
+ assert.notEqual(
+ myWindow.document.readyState,
+ "complete",
+ "window still hasn't loaded yet.");
+
+ // wait for the window to load and then close it. onTrack wouldn't be called
+ // until the window loads, so we must let it load before closing it to be
+ // certain that onTrack was removed.
+ myWindow.addEventListener("load", function() {
+ // allow all of the load handles to execute before closing
+ myWindow.setTimeout(function() {
+ myWindow.addEventListener("unload", function() {
+ // once the window unloads test is done
+ done();
+ }, false);
+ myWindow.close();
+ }, 0);
+ }, false);
+}
+
+exports['test window watcher without untracker'] = function(assert, done) {
+ var myWindow;
+ var finished = false;
+
+ var delegate = {
+ onTrack: function(window) {
+ if (window == myWindow) {
+ assert.pass("onTrack() called with our test window");
+ timer.setTimeout(function() {
+ myWindow.close();
+
+ if (!finished) {
+ finished = true;
+ myWindow = null;
+ wt.unload();
+ done();
+ } else {
+ assert.fail("onTrack() called multiple times.");
+ }
+ }, 1);
+ }
+ }
+ };
+
+ var wt = new windowUtils.WindowTracker(delegate);
+ myWindow = makeEmptyWindow();
+};
+
+exports['test active window'] = function(assert, done) {
+ let testRunnerWindow = Cc["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Ci.nsIWindowMediator)
+ .getMostRecentWindow("test:runner");
+ let browserWindow = Cc["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Ci.nsIWindowMediator)
+ .getMostRecentWindow("navigator:browser");
+
+ assert.equal(windowUtils.activeBrowserWindow, browserWindow,
+ "Browser window is the active browser window.");
+
+
+ let testSteps = [
+ function() {
+ windowUtils.activeWindow = browserWindow;
+ continueAfterFocus(browserWindow);
+ },
+ function() {
+ assert.equal(windowUtils.activeWindow, browserWindow,
+ "Correct active window [1]");
+ continueAfterFocus(windowUtils.activeWindow = testRunnerWindow);
+ },
+ function() {
+ assert.equal(windowUtils.activeWindow, testRunnerWindow,
+ "Correct active window [2]");
+ assert.equal(windowUtils.activeBrowserWindow, browserWindow,
+ "Correct active browser window [3]");
+ continueAfterFocus(windowUtils.activeWindow = browserWindow);
+ },
+ function() {
+ assert.equal(windowUtils.activeWindow, browserWindow,
+ "Correct active window [4]");
+ continueAfterFocus(windowUtils.activeWindow = testRunnerWindow);
+ },
+ function() {
+ assert.equal(windowUtils.activeWindow, testRunnerWindow,
+ "Correct active window [5]");
+ assert.equal(windowUtils.activeBrowserWindow, browserWindow,
+ "Correct active browser window [6]");
+ testRunnerWindow = null;
+ browserWindow = null;
+ done();
+ }
+ ];
+
+ let nextTest = function() {
+ let func = testSteps.shift();
+ if (func) {
+ func();
+ }
+ }
+
+ function continueAfterFocus(targetWindow) {
+
+ // Based on SimpleTest.waitForFocus
+ var fm = Cc["@mozilla.org/focus-manager;1"].
+ getService(Ci.nsIFocusManager);
+
+ var childTargetWindow = {};
+ fm.getFocusedElementForWindow(targetWindow, true, childTargetWindow);
+ childTargetWindow = childTargetWindow.value;
+
+ var focusedChildWindow = {};
+ if (fm.activeWindow) {
+ fm.getFocusedElementForWindow(fm.activeWindow, true, focusedChildWindow);
+ focusedChildWindow = focusedChildWindow.value;
+ }
+
+ var focused = (focusedChildWindow == childTargetWindow);
+ if (focused) {
+ nextTest();
+ } else {
+ childTargetWindow.addEventListener("focus", function focusListener() {
+ childTargetWindow.removeEventListener("focus", focusListener, true);
+ nextTest();
+ }, true);
+ }
+
+ }
+
+ nextTest();
+};
+
+require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-window-utils2.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-window-utils2.js
new file mode 100644
index 0000000..62f34f9
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-window-utils2.js
@@ -0,0 +1,67 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+const { Ci } = require('chrome');
+const { open, backgroundify,
+ getXULWindow, getBaseWindow } = require('api-utils/window/utils');
+const windowUtils = require('api-utils/window-utils');
+
+function windows(iterator) {
+ let array = [];
+ for each (let item in windowUtils.windowIterator())
+ array.push(item);
+ return array;
+}
+
+exports['test get nsIBaseWindow from nsIDomWindow'] = function(assert) {
+ let active = windowUtils.activeBrowserWindow;
+
+ assert.ok(!(active instanceof Ci.nsIBaseWindow),
+ 'active window is not nsIBaseWindow');
+
+ assert.ok(getBaseWindow(active) instanceof Ci.nsIBaseWindow,
+ 'base returns nsIBaseWindow');
+};
+
+exports['test get nsIXULWindow from nsIDomWindow'] = function(assert) {
+ let active = windowUtils.activeBrowserWindow;
+ assert.ok(!(active instanceof Ci.nsIXULWindow),
+ 'active window is not nsIXULWindow');
+ assert.ok(getXULWindow(active) instanceof Ci.nsIXULWindow,
+ 'base returns nsIXULWindow');
+};
+
+exports['test top window creation'] = function(assert) {
+ let window = open('data:text/html,Hello top window');
+ assert.ok(~windows().indexOf(window), 'window was opened');
+ window.close();
+};
+
+exports['test new top window with options'] = function(assert) {
+ let window = open('data:text/html,Hi custom top window', {
+ name: 'test',
+ features: { height: 100, width: 200, toolbar: true }
+ });
+ assert.ok(~windows().indexOf(window), 'window was opened');
+ assert.equal(window.name, 'test', 'name was set');
+ assert.equal(window.innerHeight, 100, 'height is set');
+ assert.equal(window.innerWidth, 200, 'height is set');
+ assert.equal(window.toolbar.visible, true, 'toolbar was set');
+ window.close();
+};
+
+exports['test backgroundify'] = function(assert) {
+ let window = open('data:text/html,backgroundy');
+ assert.ok(~windows().indexOf(window),
+ 'window is in the list of windows');
+ let backgroundy = backgroundify(window);
+ assert.equal(backgroundy, window, 'backgroundify returs give window back');
+ assert.ok(!~windows().indexOf(window),
+ 'backgroundifyied window is in the list of windows');
+ window.close();
+};
+
+require('test').run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-xhr.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-xhr.js
new file mode 100644
index 0000000..ad47e54
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-xhr.js
@@ -0,0 +1,75 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var xhr = require("xhr");
+var timer = require("timer");
+var { Loader } = require("./helpers");
+var xulApp = require("xul-app");
+
+/* Test is intentionally disabled until platform bug 707256 is fixed.
+exports.testAbortedXhr = function(test) {
+ var req = new xhr.XMLHttpRequest();
+ test.assertEqual(xhr.getRequestCount(), 1);
+ req.abort();
+ test.assertEqual(xhr.getRequestCount(), 0);
+};
+*/
+
+exports.testLocalXhr = function(test) {
+ var req = new xhr.XMLHttpRequest();
+ req.overrideMimeType("text/plain");
+ req.open("GET", module.uri);
+ req.onreadystatechange = function() {
+ if (req.readyState == 4 && req.status == 0) {
+ test.assertMatches(req.responseText,
+ /onreadystatechange/,
+ "XMLHttpRequest should get local files");
+ timer.setTimeout(
+ function() { test.assertEqual(xhr.getRequestCount(), 0);
+ test.done(); },
+ 0
+ );
+ }
+ };
+ req.send(null);
+ test.assertEqual(xhr.getRequestCount(), 1);
+ test.waitUntilDone(4000);
+};
+
+exports.testUnload = function(test) {
+ var loader = Loader(module);
+ var sbxhr = loader.require("xhr");
+ var req = new sbxhr.XMLHttpRequest();
+ req.overrideMimeType("text/plain");
+ req.open("GET", module.uri);
+ req.send(null);
+ test.assertEqual(sbxhr.getRequestCount(), 1);
+ loader.unload();
+ test.assertEqual(sbxhr.getRequestCount(), 0);
+};
+
+exports.testResponseHeaders = function(test) {
+ var req = new xhr.XMLHttpRequest();
+ req.overrideMimeType("text/plain");
+ req.open("GET", module.uri);
+ req.onreadystatechange = function() {
+ if (req.readyState == 4 && req.status == 0) {
+ var headers = req.getAllResponseHeaders();
+ if (xulApp.versionInRange(xulApp.platformVersion, "13.0a1", "*")) {
+ // Now that bug 608939 is FIXED, headers works correctly on files:
+ test.assertEqual(headers, "Content-Type: text/plain\n",
+ "XHR's headers are valid");
+ }
+ else {
+ test.assert(headers === null || headers === "",
+ "XHR's headers are empty");
+ }
+ test.done();
+ }
+ };
+ req.send(null);
+ test.assertEqual(xhr.getRequestCount(), 1);
+ test.waitUntilDone(4000);
+}
+
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-xpcom.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-xpcom.js
new file mode 100644
index 0000000..eda3565
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-xpcom.js
@@ -0,0 +1,217 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const xpcom = require("api-utils/xpcom");
+const { Cc, Ci, Cm, Cr } = require("chrome");
+const { isCIDRegistered } = Cm.QueryInterface(Ci.nsIComponentRegistrar);
+const { Loader } = require("./helpers");
+
+exports['test Unknown implements nsISupports'] = function(assert) {
+ let actual = xpcom.Unknown.new();
+ assert.equal(actual.QueryInterface(Ci.nsISupports),
+ actual,
+ 'component implements nsISupports');
+};
+
+exports['test implement xpcom interfaces'] = function(assert) {
+ let component = xpcom.Unknown.extend({
+ interfaces: [ 'nsIWeakReference' ],
+ QueryReferent: function() {}
+ })
+
+ assert.equal(component.QueryInterface(Ci.nsISupports),
+ component,
+ 'component implements nsISupports');
+ assert.equal(component.QueryInterface(Ci.nsIWeakReference),
+ component,
+ 'component implements specified interface');
+
+ assert.throws(function() {
+ component.QueryInterface(Ci.nsIObserver);
+ }, "component does not implements interface");
+
+ let actual = component.extend({
+ interfaces: [ 'nsIObserver', 'nsIRequestObserver' ],
+ observe: function() {},
+ onStartRequest: function() {},
+ onStopRequest: function() {}
+ });
+
+ assert.equal(actual.QueryInterface(Ci.nsISupports),
+ actual,
+ 'derived component implements nsISupports');
+ assert.equal(actual.QueryInterface(Ci.nsIWeakReference),
+ actual,
+ 'derived component implements supers interface');
+ assert.equal(actual.QueryInterface(Ci.nsIObserver),
+ actual.QueryInterface(Ci.nsIRequestObserver),
+ 'derived component implements specified interfaces');
+};
+
+exports['test implement factory without contract'] = function(assert) {
+ let actual = xpcom.Factory.new({
+ component: xpcom.Unknown.extend({
+ get wrappedJSObject() this,
+ })
+ });
+
+ assert.ok(isCIDRegistered(actual.id), 'factory is regiseterd');
+ xpcom.unregister(actual);
+ assert.ok(!isCIDRegistered(actual.id), 'factory is unregistered');
+};
+
+exports['test implement xpcom factory'] = function(assert) {
+ let Component = xpcom.Unknown.extend({
+ interfaces: [ 'nsIObserver' ],
+ get wrappedJSObject() this,
+ observe: function() {}
+ });
+
+ let factory = xpcom.Factory.new({
+ register: false,
+ contract: '@jetpack/test/factory;1',
+ component: Component
+ });
+
+ assert.ok(!isCIDRegistered(factory.id), 'factory is not registered');
+ xpcom.register(factory);
+ assert.ok(isCIDRegistered(factory.id), 'factory is registered');
+
+ let actual = Cc[factory.contract].createInstance(Ci.nsIObserver);
+
+ assert.ok(Component.isPrototypeOf(actual.wrappedJSObject),
+ "createInstance returnes wrapped factory instances");
+
+ assert.notEqual(Cc[factory.contract].createInstance(Ci.nsIObserver),
+ Cc[factory.contract].createInstance(Ci.nsIObserver),
+ "createInstance returns new instance each time");
+};
+
+exports['test implement xpcom service'] = function(assert) {
+ let actual = xpcom.Service.new({
+ contract: '@jetpack/test/service;1',
+ register: false,
+ component: xpcom.Unknown.extend({
+ get wrappedJSObject() this,
+ interfaces: [ 'nsIObserver'],
+ observe: function() {},
+ name: 'my-service'
+ })
+ });
+
+ assert.ok(!isCIDRegistered(actual.id), 'component is not registered');
+ xpcom.register(actual);
+ assert.ok(isCIDRegistered(actual.id), 'service is regiseterd');
+ assert.ok(Cc[actual.contract].getService(Ci.nsIObserver).observe,
+ 'service can be accessed via get service');
+ assert.equal(Cc[actual.contract].getService(Ci.nsIObserver).wrappedJSObject,
+ actual.component,
+ 'wrappedJSObject is an actual component');
+ xpcom.unregister(actual);
+ assert.ok(!isCIDRegistered(actual.id), 'service is unregistered');
+};
+
+
+function testRegister(assert, text) {
+
+ const service = xpcom.Service.new({
+ description: 'test about:boop page',
+ contract: '@mozilla.org/network/protocol/about;1?what=boop',
+ register: false,
+ component: xpcom.Unknown.extend({
+ get wrappedJSObject() this,
+ interfaces: [ 'nsIAboutModule' ],
+ newChannel : function(aURI) {
+ var ios = Cc["@mozilla.org/network/io-service;1"].
+ getService(Ci.nsIIOService);
+
+ var channel = ios.newChannel(
+ "data:text/plain," + text,
+ null,
+ null
+ );
+
+ channel.originalURI = aURI;
+ return channel;
+ },
+ getURIFlags: function(aURI) {
+ return Ci.nsIAboutModule.ALLOW_SCRIPT;
+ }
+ })
+ });
+
+ xpcom.register(service);
+
+ assert.equal(isCIDRegistered(service.id), true);
+
+ var aboutFactory = xpcom.factoryByContract(service.contract);
+ var about = aboutFactory.createInstance(Ci.nsIAboutModule);
+
+ var ios = Cc["@mozilla.org/network/io-service;1"].
+ getService(Ci.nsIIOService);
+ assert.equal(
+ about.getURIFlags(ios.newURI("http://foo.com", null, null)),
+ Ci.nsIAboutModule.ALLOW_SCRIPT
+ );
+
+ var aboutURI = ios.newURI("about:boop", null, null);
+ var channel = ios.newChannelFromURI(aboutURI);
+ var iStream = channel.open();
+ var siStream = Cc['@mozilla.org/scriptableinputstream;1']
+ .createInstance(Ci.nsIScriptableInputStream);
+ siStream.init(iStream);
+ var data = new String();
+ data += siStream.read(-1);
+ siStream.close();
+ iStream.close();
+ assert.equal(data, text);
+
+ xpcom.unregister(service);
+ assert.equal(isCIDRegistered(service.id), false);
+}
+
+exports["test register"] = function(assert) {
+ testRegister(assert, "hai2u");
+};
+
+exports["test re-register"] = function(assert) {
+ testRegister(assert, "hai2u again");
+};
+
+exports["test unload"] = function(assert) {
+ let loader = Loader(module);
+ let sbxpcom = loader.require("xpcom");
+
+ let auto = sbxpcom.Factory.new({
+ contract: "@mozilla.org/test/auto-unload;1",
+ description: "test auto",
+ component: sbxpcom.Unknown.extend({ name: 'auto' })
+ });
+
+ let manual = sbxpcom.Factory.new({
+ contract: "@mozilla.org/test/manual-unload;1",
+ description: "test manual",
+ register: false,
+ unregister: false,
+ component: sbxpcom.Unknown.extend({ name: 'manual' })
+ });
+
+ assert.equal(isCIDRegistered(auto.id), true, 'component registered');
+ assert.equal(isCIDRegistered(manual.id), false, 'component not registered');
+
+ sbxpcom.register(manual)
+ assert.equal(isCIDRegistered(manual.id), true,
+ 'component was automatically registered on first instance');
+ loader.unload();
+
+ assert.equal(isCIDRegistered(auto.id), false,
+ 'component was atumatically unregistered on unload');
+ assert.equal(isCIDRegistered(manual.id), true,
+ 'component was not automatically unregistered on unload');
+ sbxpcom.unregister(manual);
+ assert.equal(isCIDRegistered(manual.id), false,
+ 'component was manually unregistered on unload');
+};
+
+require("test").run(exports)
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/test-xul-app.js b/tools/addon-sdk-1.7/packages/api-utils/tests/test-xul-app.js
new file mode 100644
index 0000000..58aa29e
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/test-xul-app.js
@@ -0,0 +1,45 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var xulApp = require("xul-app");
+
+exports.testXulApp = function(test) {
+ test.assertEqual(typeof(xulApp.ID), "string",
+ "ID is a string");
+ test.assertEqual(typeof(xulApp.name), "string",
+ "name is a string");
+ test.assertEqual(typeof(xulApp.version), "string",
+ "version is a string");
+ test.assertEqual(typeof(xulApp.platformVersion), "string",
+ "platformVersion is a string");
+
+ test.assertRaises(function() { xulApp.is("blargy"); },
+ "Unkown Mozilla Application: blargy",
+ "is() throws error on bad app name");
+ test.assertRaises(function() { xulApp.isOneOf(["blargy"]); },
+ "Unkown Mozilla Application: blargy",
+ "isOneOf() throws error on bad app name");
+
+ function testSupport(name) {
+ var item = xulApp.is(name);
+ test.assert(item === true || item === false,
+ "is('" + name + "') is true or false.");
+ }
+
+ var apps = ["Firefox", "Mozilla", "Sunbird", "SeaMonkey",
+ "Fennec", "Thunderbird"];
+
+ apps.forEach(function(name) { testSupport(name); });
+
+ test.assert(xulApp.isOneOf(apps) == true ||
+ xulApp.isOneOf(apps) == false,
+ "isOneOf() returns true or false.");
+
+ test.assertEqual(xulApp.versionInRange(xulApp.platformVersion, "1.9", "*"),
+ true, "platformVersion in range [1.9, *)");
+ test.assertEqual(xulApp.versionInRange("3.6.4", "3.6.4", "3.6.*"),
+ true, "3.6.4 in [3.6.4, 3.6.*)");
+ test.assertEqual(xulApp.versionInRange("1.9.3", "1.9.2", "1.9.3"),
+ false, "1.9.3 not in [1.9.2, 1.9.3)");
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/traits/assert.js b/tools/addon-sdk-1.7/packages/api-utils/tests/traits/assert.js
new file mode 100644
index 0000000..7c385e4
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/traits/assert.js
@@ -0,0 +1,98 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+var BaseAssert = require("test/assert").Assert;
+
+/**
+ * Whether or not given property descriptors are equivalent. They are
+ * equivalent either if both are marked as "conflict" or "required" property
+ * or if all the properties of descriptors are equal.
+ * @param {Object} actual
+ * @param {Object} expected
+ */
+function equivalentDescriptors(actual, expected) {
+ return (actual.conflict && expected.conflict) ||
+ (actual.required && expected.required) ||
+ equalDescriptors(actual, expected);
+}
+
+function equalDescriptors(actual, expected) {
+ return actual.get === expected.get &&
+ actual.set === expected.set &&
+ actual.value === expected.value &&
+ !!actual.enumerable === !!expected.enumerable &&
+ !!actual.configurable === !!expected.configurable &&
+ !!actual.writable === !!expected.writable;
+}
+
+/**
+ * Whether or not given `target` array contains all the element
+ * from a given `source` array.
+ */
+function containsSet(source, target) {
+ return source.some(function(element) {
+ return 0 > target.indexOf(element);
+ });
+}
+
+/**
+ * Whether or not given two arrays contain all elements from another.
+ */
+function equivalentSets(source, target) {
+ return containsSet(source, target) && containsSet(target, source);
+}
+
+/**
+ * Finds name of the property from `source` property descriptor map, that
+ * is not equivalent of the name named property in the `target` property
+ * descriptor map. If not found `null` is returned instead.
+ */
+function findNonEquivalentPropertyName(source, target) {
+ var value = null;
+ Object.getOwnPropertyNames(source).some(function(key) {
+ var areEquivalent = false;
+ if (!equivalentDescriptors(source[key], target[key])) {
+ value = key;
+ areEquivalent = true;
+ }
+ return areEquivalent;
+ });
+ return value;
+}
+
+var AssertDescriptor = {
+ equalTraits: {
+ value: function equivalentTraits(actual, expected, message) {
+ var difference;
+ var actualKeys = Object.getOwnPropertyNames(actual);
+ var expectedKeys = Object.getOwnPropertyNames(expected);
+
+ if (equivalentSets(actualKeys, expectedKeys)) {
+ this.fail({
+ operator: "equalTraits",
+ message: "Traits define different properties",
+ actual: actualKeys.sort().join(","),
+ expected: expectedKeys.sort().join(","),
+ });
+ }
+ else if ((difference = findNonEquivalentPropertyName(actual, expected))) {
+ this.fail({
+ operator: "equalTraits",
+ message: "Traits define non-equivalent property `" + difference + "`",
+ actual: actual[difference],
+ expected: expected[difference]
+ });
+ }
+ else {
+ this.pass(message || "Traits are equivalent.");
+ }
+ }
+ }
+};
+
+exports.Assert = function Assert() {
+ return Object.create(BaseAssert.apply(null, arguments), AssertDescriptor);
+};
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/traits/descriptor-tests.js b/tools/addon-sdk-1.7/packages/api-utils/tests/traits/descriptor-tests.js
new file mode 100644
index 0000000..b775ff4
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/traits/descriptor-tests.js
@@ -0,0 +1,335 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+var Trait = require("light-traits").Trait;
+var utils = require("./utils");
+var Data = utils.Data;
+var Method = utils.Method;
+var Accessor = utils.Accessor;
+var Required = utils.Required;
+var Conflict = utils.Conflict;
+
+function method() {}
+
+exports.Assert = require("./assert").Assert
+exports["test simple composition"] = function(assert) {
+ var actual = Trait.compose(
+ Trait({ a: 0, b: 1 }),
+ { c: { value: 2 }, d: { value: method, enumerable: true } }
+ );
+
+ var expected = {
+ a: Data(0),
+ b: Data(1),
+ c: Data(2, false, false, false),
+ d: Method(method, true, false, false)
+ };
+
+ assert.equalTraits(actual, expected);
+};
+
+exports["test composition with conflict"] = function(assert) {
+ var actual = Trait.compose(
+ Trait({ a: 0, b: 1 }),
+ {
+ a: {
+ value: 2,
+ writable: true,
+ configurable: true,
+ enumerable: true
+ },
+ c: {
+ value: method,
+ configurable: true
+ }
+ }
+ );
+
+ var expected = {
+ a: Conflict("a"),
+ b: Data(1),
+ c: Method(method, false, true, false)
+ };
+
+ assert.equalTraits(actual, expected);
+};
+
+exports["test identical props does not cause conflict"] = function(assert) {
+ var actual = Trait.compose(
+ {
+ a: {
+ value: 0,
+ writable: true,
+ configurable: true,
+ enumerable: true
+ },
+ b: {
+ value: 1
+ }
+ },
+ Trait({
+ a: 0,
+ c: method
+ })
+ );
+
+ var expected = {
+ a: Data(0),
+ b: Data(1, false, false, false),
+ c: Method(method)
+ }
+
+ assert.equalTraits(actual, expected);
+};
+
+exports["test composition with identical required props"] = function(assert) {
+ var actual = Trait.compose(
+ Trait({ a: Trait.required, b: 1 }),
+ { a: { required: true }, c: { value: method } }
+ );
+
+ var expected = {
+ a: Required(),
+ b: Data(1),
+ c: Method(method, false, false, false)
+ };
+
+ assert.equalTraits(actual, expected);
+};
+
+exports["test composition satisfying a required prop"] = function(assert) {
+ var actual = Trait.compose(
+ Trait({ a: Trait.required, b: 1 }),
+ { a: { value: method, enumerable: true } }
+ );
+
+ var expected = {
+ a: Method(method, true, false, false),
+ b: Data(1)
+ };
+
+ assert.equalTraits(actual, expected);
+};
+
+exports["test compose is neutral wrt conflicts"] = function(assert) {
+ var actual = Trait.compose(
+ Trait({ a: { value: 1 } }, Trait({ a: 2 })),
+ { b: { value: 0, writable: true, configurable: true, enumerable: false } }
+ );
+
+ var expected = { a: Conflict("a"), b: Data(0, false) };
+
+ assert.equalTraits(actual, expected);
+};
+
+exports["test conflicting prop overrides Trait.required"] = function(assert) {
+ var actual = Trait.compose(
+ Trait.compose(
+ Trait({ a: 1 }),
+ { a: { value: 2 } }
+ ),
+ { a: { value: Trait.required } }
+ );
+
+ var expected = { a: Conflict("a") };
+
+ assert.equalTraits(actual, expected);
+};
+
+exports["test compose is commutative"] = function(assert) {
+ var actual = Trait.compose(
+ Trait({ a: 0, b: 1 }),
+ { c: { value: 2 }, d: { value: method } }
+ );
+
+ var expected = Trait.compose(
+ { c: { value: 2 }, d: { value: method } },
+ Trait({ a: 0, b: 1 })
+ );
+
+ assert.equalTraits(actual, expected);
+}
+
+exports["test compose is commutative, also for required/conflicting props"] = function(assert) {
+ var actual = Trait.compose(
+ {
+ a: { value: 0 },
+ b: { value: 1 },
+ c: { value: 3 },
+ e: { value: Trait.required }
+ },
+ {
+ c: { value: 2 },
+ d: { get: method }
+ }
+ );
+
+ var expected = Trait.compose(
+ Trait({ c: 3 }),
+ {
+ c: { value: 2 },
+ d: { get: method },
+ a: { value: 0 },
+ b: { value: 1 },
+ e: { value: Trait.required },
+ }
+ );
+
+ assert.equalTraits(actual, expected);
+};
+
+exports["test compose is associative"] = function(assert) {
+ var actual = Trait.compose(
+ {
+ a: { value: 0 },
+ b: { value: 1 },
+ c: { value: 3 },
+ d: { value: Trait.required }
+ },
+ Trait.compose(
+ { c: { value: 3 }, d: { value: Trait.required } },
+ { c: { value: 2 }, d: { value: method }, e: { value: "foo" } }
+ )
+ );
+
+ var expected = Trait.compose(
+ Trait.compose(
+ {
+ a: { value: 0 },
+ b: { value: 1 },
+ c: { value: 3 },
+ d: { value: Trait.required }
+ },
+ {
+ c: { value: 3 },
+ d: { value: Trait.required }
+ }
+ ),
+ {
+ c: { value: 2 },
+ d: { value: method },
+ e: { value: "foo" }
+ }
+ );
+
+ assert.equalTraits(actual, expected);
+};
+
+exports["test diamond import of same prop do not conflict"] = function(assert) {
+ var actual = Trait.compose(
+ Trait.compose(
+ { b: { value: 2 } },
+ { a: { value: 1, enumerable: true, configurable: true, writable: true } }
+ ),
+ Trait.compose(
+ { c: { value: 3 } },
+ Trait({ a: 1 })
+ ),
+ Trait({ d: 4 })
+ );
+
+ var expected = {
+ a: Data(1),
+ b: Data(2, false, false, false),
+ c: Data(3, false, false, false),
+ d: Data(4)
+ };
+
+ assert.equalTraits(actual, expected);
+};
+
+exports["test create simple"] = function(assert) {
+ var o1 = Trait.compose(
+ Trait({ a: 1 }),
+ {
+ b: {
+ value: function() {
+ return this.a;
+ }
+ }
+ }
+ ).create(Object.prototype);
+
+ assert.equal(Object.getPrototypeOf(o1), Object.prototype, "o1 prototype");
+ assert.equal(1, o1.a, "o1.a");
+ assert.equal(1, o1.b(), "o1.b()");
+ assert.equal(Object.keys(o1).length, 1, "Object.keys(o1).length === 2");
+};
+
+exports["test create with Array.prototype"] = function(assert) {
+ var o2 = Trait.compose({}, {}).create(Array.prototype);
+ assert.equal(Object.getPrototypeOf(o2), Array.prototype, "o2 prototype");
+};
+
+exports["test exception for incomplete required properties"] = function(assert) {
+ assert.throws(function() {
+ Trait({ foo: Trait.required }).create(Object.prototype)
+ }, /Missing required property: `foo`/, "required prop error");
+}
+
+exports["test exception for unresolved conflicts"] = function(assert) {
+ assert.throws(function() {
+ Trait(Trait({ a: 0 }), Trait({ a: 1 })).create({})
+ }, /Remaining conflicting property: `a`/, "conflicting prop error");
+}
+
+exports["test conflicting properties are present"] = function(assert) {
+ var o5 = Object.create(Object.prototype, Trait.compose(
+ { a: { value: 0 } },
+ { a: { value: 1 } }
+ ));
+
+ assert.ok("a" in o5, "conflicting property present");
+ assert.throws(function() {
+ o5.a
+ }, /Remaining conflicting property: `a`/, "conflicting prop access error");
+};
+
+exports["test diamond with conflicts"] = function(assert) {
+ function makeT1(x) {
+ return {
+ m: {
+ value: function() {
+ return x
+ }
+ }
+ };
+ };
+
+ function makeT2(x) {
+ return Trait.compose(
+ Trait({ t2: "foo" }),
+ makeT1(x)
+ );
+ };
+
+ function makeT3(x) {
+ return Trait.compose(
+ {
+ t3: { value: "bar" }
+ },
+ makeT1(x)
+ );
+ };
+
+ var T4 = Trait.compose(makeT2(5), makeT3(5));
+
+ assert.throws(function() {
+ T4.create(Object.prototype);
+ }, /Remaining conflicting property: `m`/, "diamond prop conflict");
+};
+
+exports["test providing requirements through proto"] = function(assert) {
+ var t = Trait.compose(
+ {},
+ { required: { required: true } }
+ ).create({ required: "test" });
+
+ assert.equal(t.required, "test", "property from proto is inherited");
+};
+
+if (module == require.main)
+ require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/traits/inheritance-tests.js b/tools/addon-sdk-1.7/packages/api-utils/tests/traits/inheritance-tests.js
new file mode 100644
index 0000000..3b311f9
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/traits/inheritance-tests.js
@@ -0,0 +1,104 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+var Trait = require("light-traits").Trait;
+
+exports["test custom constructor and inherited toString"] = function(assert) {
+ function Type() {
+ return Object.create(Type.prototype);
+ }
+ Type.prototype = Trait({
+ method: function method() {
+ return 2;
+ }
+ }).create(Object.freeze(Type.prototype));
+
+ var fixture = Type();
+
+ assert.equal(fixture.constructor, Type, "must override constructor");
+ assert.equal(fixture.toString(), "[object Type]", "must inherit toString");
+};
+
+exports["test custom toString and inherited constructor"] = function(assert) {
+ function Type() {
+ return Object.create(Type.prototype);
+ }
+ Type.prototype = Trait({
+ toString: function toString() {
+ return "<toString>";
+ }
+ }).create();
+
+ var fixture = Type();
+
+ assert.equal(fixture.constructor, Trait, "must inherit constructor Trait");
+ assert.equal(fixture.toString(), "<toString>", "Must override toString");
+};
+
+exports["test custom toString and constructor"] = function(assert) {
+ function Type() {
+ return TypeTrait.create(Type.prototype);
+ }
+ Object.freeze(Type.prototype);
+ var TypeTrait = Trait({
+ toString: function toString() {
+ return "<toString>";
+ }
+ });
+
+ var fixture = Type();
+
+ assert.equal(fixture.constructor, Type, "constructor is provided to create");
+ assert.equal(fixture.toString(), "<toString>", "toString was overridden");
+};
+
+exports["test resolve constructor"] = function (assert) {
+ function Type() {}
+ var T1 = Trait({ constructor: Type }).resolve({ constructor: '_foo' });
+ var f1 = T1.create();
+
+ assert.equal(f1._foo, Type, "constructor was resolved");
+ assert.equal(f1.constructor, Trait, "constructor of prototype is inherited");
+ assert.equal(f1.toString(), "[object Trait]", "toString is inherited");
+};
+
+exports["test compose read-only"] = function (assert) {
+ function Type() {}
+ Type.prototype = Trait.compose(Trait({}), {
+ constructor: { value: Type },
+ a: { value: "b", enumerable: true }
+ }).resolve({ a: "b" }).create({ a: "a" });
+
+ var f1 = new Type();
+
+ assert.equal(Object.getPrototypeOf(f1), Type.prototype, "inherits correctly");
+ assert.equal(f1.constructor, Type, "constructor was overridden");
+ assert.equal(f1.toString(), "[object Type]", "toString was inherited");
+ assert.equal(f1.a, "a", "property a was resolved");
+ assert.equal(f1.b, "b", "property a was renamed to b");
+ assert.ok(!Object.getOwnPropertyDescriptor(Type.prototype, "a"),
+ "a is not on the prototype of the instance");
+
+ var proto = Object.getPrototypeOf(Type.prototype);
+ var dc = Object.getOwnPropertyDescriptor(Type.prototype, "constructor");
+ var db = Object.getOwnPropertyDescriptor(Type.prototype, "b");
+ var da = Object.getOwnPropertyDescriptor(proto, "a");
+
+ assert.ok(!dc.writable, "constructor is not writable");
+ assert.ok(!dc.enumerable, "constructor is not enumerable");
+ assert.ok(dc.configurable, "constructor inherits configurability");
+
+ assert.ok(!db.writable, "a -> b is not writable");
+ assert.ok(db.enumerable, "a -> b is enumerable");
+ assert.ok(!db.configurable, "a -> b is not configurable");
+
+ assert.ok(da.writable, "a is writable");
+ assert.ok(da.enumerable, "a is enumerable");
+ assert.ok(da.configurable, "a is configurable");
+};
+
+if (require.main == module)
+ require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/traits/object-tests.js b/tools/addon-sdk-1.7/packages/api-utils/tests/traits/object-tests.js
new file mode 100644
index 0000000..6a94ff3
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/traits/object-tests.js
@@ -0,0 +1,321 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+var Trait = require("light-traits").Trait;
+var utils = require("./utils");
+var Data = utils.Data;
+var Method = utils.Method;
+var Accessor = utils.Accessor;
+var Required = utils.Required;
+var Conflict = utils.Conflict;
+
+function method() {}
+
+exports.Assert = require("./assert").Assert;
+
+exports["test empty trait"] = function (assert) {
+ assert.equalTraits(Trait({}), {});
+};
+
+exports["test simple trait"] = function (assert) {
+ var expected = {
+ a: Data(0, true, true, true),
+ b: Method(method, true, true, true)
+ };
+
+ assert.equalTraits(Trait({ a: 0, b: method }), expected);
+};
+
+exports["test simple trait with Trait.required property"] = function (assert) {
+ var actual = Trait({ a: Trait.required, b: 1 });
+ var expected = { a: Required("a"), b: Data(1) };
+
+ assert.equalTraits(actual, expected);
+};
+
+exports["test ordering of trait properties is irrelevant"] = function (assert) {
+ var actual = Trait({ a: 0, b: 1, c: Trait.required });
+ var expected = Trait({ b: 1, c: Trait.required, a: 0 });
+
+ assert.equalTraits(actual, expected);
+};
+
+exports["test trait with accessor property"] = function (assert) {
+ var record = { get a() {}, set a(v) {} };
+ var get = Object.getOwnPropertyDescriptor(record, "a").get;
+ var set = Object.getOwnPropertyDescriptor(record, "a").set;
+
+ assert.equalTraits(Trait(record), { a: Accessor(get, set) });
+};
+
+exports["test simple composition"] = function (assert) {
+ var actual = Trait.compose(Trait({ a: 0, b: 1 }), Trait({ c: 2, d: method }));
+ var expected = { a: Data(0), b: Data(1), c: Data(2), d: Method(method) };
+
+ assert.equalTraits(actual, expected);
+};
+
+exports["test composition with conflict"] = function (assert) {
+ var actual = Trait.compose(Trait({ a: 0, b: 1 }), Trait({ a: 2, c: method }));
+ var expected = { a: Conflict("a"), b: Data(1), c: Method(method) };
+
+ assert.equalTraits(actual, expected);
+};
+
+exports["test composition of identical props does not cause conflict"] = function (assert) {
+ var actual = Trait.compose(Trait({ a: 0, b: 1 }), Trait({ a: 0, c: method }));
+
+ assert.equalTraits(actual, { a: Data(0), b: Data(1), c: Method(method) });
+};
+
+exports["test composition with identical Trait.required props"] = function (assert) {
+ var actual = Trait.compose(Trait({ a: Trait.required, b: 1 }),
+ Trait({ a: Trait.required, c: method }));
+
+ assert.equalTraits(actual, { a: Required(), b: Data(1), c: Method(method) });
+};
+
+exports["test composition satisfying a Trait.required prop"] = function (assert) {
+ var actual = Trait.compose(Trait({ a: Trait.required, b: 1 }),
+ Trait({ a: method }));
+
+ assert.equalTraits(actual, { a: Method(method), b: Data(1) });
+};
+
+exports["test compose is neutral wrt conflicts"] = function (assert) {
+ var actual = Trait.compose(Trait.compose(Trait({ a: 1 }), Trait({ a: 2 })),
+ Trait({ b: 0 }));
+
+ assert.equalTraits(actual, { a: Conflict("a"), b: Data(0) });
+};
+
+exports["test conflicting prop overrides Trait.required prop"] = function (assert) {
+ var actual = Trait.compose(Trait.compose(Trait({ a: 1 }),
+ Trait({ a: 2 })),
+ Trait({ a: Trait.required }));
+
+ assert.equalTraits(actual, { a: Conflict("a") });
+};
+
+exports["test compose is commutative"] = function (assert) {
+ var actual = Trait.compose(Trait({ a: 0, b: 1 }), Trait({ c: 2, d: method }));
+ var expected = Trait.compose(Trait({ c: 2, d: method }),
+ Trait({ a: 0, b: 1 }));
+
+ assert.equalTraits(actual, expected);
+};
+
+exports["test compose is commutative, also for Trait.required/conflicting props"] = function (assert) {
+ var actual = Trait.compose(Trait({ a: 0, b: 1, c: 3, e: Trait.required }),
+ Trait({ c: 2, d: method }));
+
+ var expected = Trait.compose(Trait({ c: 2, d: method }),
+ Trait({ a: 0, b: 1, c: 3, e: Trait.required }));
+
+ assert.equalTraits(actual, expected);
+};
+
+exports["test compose is associative"] = function (assert) {
+ var actual = Trait.compose(Trait({ a: 0, b: 1, c: 3, d: Trait.required }),
+ Trait.compose(Trait({ c: 3, d: Trait.required }),
+ Trait({ c: 2, d: method,
+ e: "foo" })));
+
+ var expected = Trait.compose(
+ Trait.compose(Trait({ a: 0, b: 1, c: 3, d: Trait.required }),
+ Trait({ c: 3, d: Trait.required })),
+ Trait({ c: 2, d: method, e: "foo" }));
+
+ assert.equalTraits(actual, expected);
+};
+
+exports["test diamond import of same prop does not generate conflict"] = function (assert) {
+ var actual = Trait.compose(Trait.compose(Trait({ b: 2 }), Trait({ a: 1 })),
+ Trait.compose(Trait({ c: 3 }), Trait({ a: 1 })),
+ Trait({ d: 4 }));
+ var expected = { a: Data(1), b: Data(2), c: Data(3), d: Data(4) };
+
+ assert.equalTraits(actual, expected);
+};
+
+exports["test resolve with empty resolutions has no effect"] = function (assert) {
+ assert.equalTraits(Trait({ a: 1, b: Trait.required, c: method }).resolve({}),
+ { a: Data(1), b: Required(), c: Method(method) });
+};
+
+exports["test resolve: renaming"] = function (assert) {
+ var actual = Trait({ a: 1, b: Trait.required, c: method });
+
+ assert.equalTraits(actual.resolve({ a: "A", c: "C" }),
+ { A: Data(1), b: Required(), C: Method(method),
+ a: Required(), c: Required() });
+};
+
+exports["test resolve: renaming to conflicting name causes conflict, order 1"] = function (assert) {
+ assert.equalTraits(Trait({ a: 1, b: 2 }).resolve({ a: "b" }),
+ { b: Conflict("b"), a: Required() });
+};
+
+exports["test resolve: renaming to conflicting name causes conflict, order 2"] = function (assert) {
+ assert.equalTraits(Trait({ b: 2, a: 1 }).resolve({ a: "b" }),
+ { b: Conflict("b"), a: Required() });
+};
+
+exports["test resolve: simple exclusion"] = function (assert) {
+ assert.equalTraits(Trait({ a: 1, b: 2 }).resolve({ a: undefined }),
+ { a: Required(), b: Data(2) });
+};
+
+exports["test resolve: exclusion to empty trait"] = function (assert) {
+ assert.equalTraits(Trait({ a: 1, b: 2 }).resolve({ a: null, b: undefined }),
+ { a: Required(), b: Required() });
+};
+
+exports["test resolve: exclusion and renaming of disjoint props"] = function (assert) {
+ assert.equalTraits(Trait({ a: 1, b: 2 }).resolve({ a: undefined, b: "c" }),
+ { a: Required(), c: Data(2), b: Required() });
+};
+
+exports["test resolve: exclusion and renaming of overlapping props"] = function (assert) {
+ assert.equalTraits(Trait({ a: 1, b: 2 }).resolve({ a: undefined, b: "a" }),
+ { a: Data(2), b: Required() });
+};
+
+exports["test resolve: renaming to a common alias causes conflict"] = function (assert) {
+ assert.equalTraits(Trait({ a: 1, b: 2 }).resolve({ a: "c", b: "c" }),
+ { c: Conflict("c"), a: Required(), b: Required() });
+};
+
+exports["test resolve: renaming overrides Trait.required target"] = function (assert) {
+ assert.equalTraits(Trait({ a: Trait.required, b: 2 }).resolve({ b: "a" }),
+ { a: Data(2), b: Required() });
+};
+
+exports["test resolve: renaming Trait.required properties has no effect"] = function (assert) {
+ assert.equalTraits(Trait({ a: 2, b: Trait.required }).resolve({ b: "a" }),
+ { a: Data(2), b: Required() });
+};
+
+exports["test resolve: renaming of non-existent props has no effect"] = function (assert) {
+ assert.equalTraits(Trait({ a: 1, b: 2 }).resolve({ a: "c", d: "c" }),
+ { c: Data(1), b: Data(2), a: Required() });
+};
+
+exports["test resolve: exclusion of non-existent props has no effect"] = function (assert) {
+ assert.equalTraits(Trait({ a: 1 }).resolve({ b: undefined }), { a: Data(1) });
+};
+
+exports["test resolve is neutral w.r.t. Trait.required properties"] = function (assert) {
+ var actual = Trait({ a: Trait.required, b: Trait.required, c: "foo", d: 1 });
+ var expected = { a: Required(), b: Required(), c: Data("foo"), d: Data(1) };
+ assert.equalTraits(actual.resolve({ a: "c", b: undefined }), expected);
+};
+
+exports["test resolve supports swapping of property names, ordering 1"] = function (assert) {
+ assert.equalTraits(Trait({ a: 1, b: 2 }).resolve({ a: "b", b: "a" }),
+ { a: Data(2), b: Data(1) });
+};
+
+exports["test resolve supports swapping of property names, ordering 2"] = function (assert) {
+ assert.equalTraits(Trait({ a: 1, b: 2 }).resolve({ b: "a", a: "b" }),
+ { a: Data(2), b: Data(1) });
+};
+
+exports["test resolve supports swapping of property names, ordering 3"] = function (assert) {
+ assert.equalTraits(Trait({ b: 2, a: 1 }).resolve({ b: "a", a: "b" }),
+ { a: Data(2), b: Data(1) });
+};
+
+exports["test resolve supports swapping of property names, ordering 4"] = function (assert) {
+ assert.equalTraits(Trait({ b: 2, a: 1 }).resolve({ a: "b", b: "a" }),
+ { a: Data(2), b: Data(1) });
+};
+
+exports["test create simple"] = function (assert) {
+ var o1 = Trait({
+ a: 1,
+ b: function () {
+ return this.a;
+ }
+ }).create(Object.prototype);
+
+ assert.equal(Object.getPrototypeOf(o1), Object.prototype, "o1 prototype");
+ assert.equal(1, o1.a, "o1.a");
+ assert.equal(1, o1.b(), "o1.b()");
+ assert.equal(Object.keys(o1).length, 2, "Object.keys(o1).length === 2");
+};
+
+exports["test create with Array.prototype"] = function (assert) {
+ var o2 = Trait({}).create(Array.prototype);
+ assert.equal(Object.getPrototypeOf(o2), Array.prototype, "o2 prototype");
+};
+
+exports["test exception for incomplete required properties"] = function (assert) {
+ assert.throws(function () {
+ Trait({ foo: Trait.required }).create(Object.prototype);
+ }, /Missing required property: `foo`/, "required prop error");
+};
+
+exports["test exception for unresolved conflicts"] = function (assert) {
+ assert.throws(function () {
+ Trait.compose(Trait({ a: 0 }), Trait({ a: 1 })).create({});
+ }, /Remaining conflicting property: `a`/, "conflicting prop error");
+};
+
+exports["test verify that required properties are present but undefined"] = function (assert) {
+ var o4 = Object.create(Object.prototype, Trait({ foo: Trait.required }));
+
+ assert.ok("foo" in o4, "required property present");
+ assert.throws(function () {
+ o4.foo;
+ }, /Missing required property: `foo`/, "required prop error");
+};
+
+exports["test verify that conflicting properties are present"] = function (assert) {
+ var o5 = Object.create(Object.prototype, Trait.compose(Trait({ a: 0 }),
+ Trait({ a: 1 })));
+
+ assert.ok("a" in o5, "conflicting property present");
+ assert.throws(function () {
+ o5.a;
+ }, /Remaining conflicting property: `a`/, "conflicting prop access error");
+};
+
+exports["test diamond with conflicts"] = function (assert) {
+ function makeT1(x) {
+ return Trait({
+ m: function () {
+ return x
+ }
+ })
+ };
+
+ function makeT2(x) {
+ return Trait.compose(Trait({
+ t2: "foo"
+ }), makeT1(x));
+ };
+
+ function makeT3(x) {
+ return Trait.compose(Trait({
+ t3: "bar"
+ }), makeT1(x));
+ };
+
+ var T4 = Trait.compose(makeT2(5), makeT3(5));
+
+ assert.throws(function () {
+ T4.create(Object.prototype);
+ }, /Remaining conflicting property: `m`/, "diamond prop conflict");
+};
+
+exports["test providing requirements through proto"] = function (assert) {
+ var t = Trait({ required: Trait.required }).create({ required: "test" });
+ assert.equal(t.required, "test", "property from proto is inherited");
+};
+
+if (module == require.main)
+ require("test").run(exports);
diff --git a/tools/addon-sdk-1.7/packages/api-utils/tests/traits/utils.js b/tools/addon-sdk-1.7/packages/api-utils/tests/traits/utils.js
new file mode 100644
index 0000000..8426af7
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/api-utils/tests/traits/utils.js
@@ -0,0 +1,56 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+var ERR_CONFLICT = "Remaining conflicting property: ";
+var ERR_REQUIRED = "Missing required property: ";
+
+exports.Data = function Data(value, enumerable, configurable, writable) {
+ return ({
+ value: value,
+ enumerable: enumerable !== false,
+ configurable: configurable !== false,
+ writable: writable !== false
+ });
+};
+
+exports.Method = function Method(method, enumerable, configurable, writable) {
+ return ({
+ value: method,
+ enumerable: enumerable !== false,
+ configurable: configurable !== false,
+ writable: writable !== false
+ });
+};
+
+exports.Accessor = function Accessor(get, set, enumerable, configurable) {
+ return ({
+ get: get,
+ set: set,
+ enumerable: enumerable !== false,
+ configurable: configurable !== false
+ });
+};
+
+exports.Required = function Required(name) {
+ function required() { throw new Error(ERR_REQUIRED + name) }
+
+ return ({
+ get: required,
+ set: required,
+ required: true
+ });
+};
+
+exports.Conflict = function Conflict(name) {
+ function conflict() { throw new Error(ERR_CONFLICT + name) }
+
+ return ({
+ get: conflict,
+ set: conflict,
+ conflict: true
+ });
+};
+
diff --git a/tools/addon-sdk-1.7/packages/test-harness/README.md b/tools/addon-sdk-1.7/packages/test-harness/README.md
new file mode 100644
index 0000000..b22824b
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/test-harness/README.md
@@ -0,0 +1,12 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<span class="aside">
+For more information on testing in the Add-on SDK, see the
+[Unit Testing](dev-guide/tutorials/unit-testing.html)
+tutorial.
+</span>
+
+This package contains a program that finds and runs tests. It is
+automatically used whenever the `cfx test` command is executed.
diff --git a/tools/addon-sdk-1.7/packages/test-harness/docs/harness.md b/tools/addon-sdk-1.7/packages/test-harness/docs/harness.md
new file mode 100644
index 0000000..45218ec
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/test-harness/docs/harness.md
@@ -0,0 +1,6 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+This module contains the bulk of the test harness setup and execution
+implementation.
diff --git a/tools/addon-sdk-1.7/packages/test-harness/docs/run-tests.md b/tools/addon-sdk-1.7/packages/test-harness/docs/run-tests.md
new file mode 100644
index 0000000..155b809
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/test-harness/docs/run-tests.md
@@ -0,0 +1,13 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<span class="aside">
+For more information on testing in the Add-on SDK, see the
+[Unit Testing](dev-guide/tutorials/unit-testing.html)
+tutorial.
+</span>
+
+This module contains the package's main program, which does a
+bit of high-level setup and then delegates test finding and running to
+the `harness` module.
diff --git a/tools/addon-sdk-1.7/packages/test-harness/lib/harness.js b/tools/addon-sdk-1.7/packages/test-harness/lib/harness.js
new file mode 100644
index 0000000..e1b1105
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/test-harness/lib/harness.js
@@ -0,0 +1,324 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { Cc,Ci } = require("chrome");
+const { Loader } = require("@loader")
+const memory = require('api-utils/memory');
+
+var cService = Cc['@mozilla.org/consoleservice;1'].getService()
+ .QueryInterface(Ci.nsIConsoleService);
+
+// Cuddlefish loader for the sandbox in which we load and
+// execute tests.
+var sandbox;
+
+// Function to call when we're done running tests.
+var onDone;
+
+// Function to print text to a console, w/o CR at the end.
+var print;
+
+// How many more times to run all tests.
+var iterationsLeft;
+
+// Only tests in files whose names match this regexp filter will be run.
+var filter;
+
+// Whether to report memory profiling information.
+var profileMemory;
+
+// Whether we should stop as soon as a test reports a failure.
+var stopOnError;
+
+// Combined information from all test runs.
+var results = {
+ passed: 0,
+ failed: 0,
+ testRuns: []
+};
+
+// JSON serialization of last memory usage stats; we keep it stringified
+// so we don't actually change the memory usage stats (in terms of objects)
+// of the JSRuntime we're profiling.
+var lastMemoryUsage;
+
+function analyzeRawProfilingData(data) {
+ var graph = data.graph;
+ var shapes = {};
+
+ // Convert keys in the graph from strings to ints.
+ // TODO: Can we get rid of this ridiculousness?
+ var newGraph = {};
+ for (id in graph) {
+ newGraph[parseInt(id)] = graph[id];
+ }
+ graph = newGraph;
+
+ var modules = 0;
+ var moduleIds = [];
+ var moduleObjs = {UNKNOWN: 0};
+ for (let name in data.namedObjects) {
+ moduleObjs[name] = 0;
+ moduleIds[data.namedObjects[name]] = name;
+ modules++;
+ }
+
+ var count = 0;
+ for (id in graph) {
+ var parent = graph[id].parent;
+ while (parent) {
+ if (parent in moduleIds) {
+ var name = moduleIds[parent];
+ moduleObjs[name]++;
+ break;
+ }
+ if (!(parent in graph)) {
+ moduleObjs.UNKNOWN++;
+ break;
+ }
+ parent = graph[parent].parent;
+ }
+ count++;
+ }
+
+ print("\nobject count is " + count + " in " + modules + " modules" +
+ " (" + data.totalObjectCount + " across entire JS runtime)\n");
+ if (lastMemoryUsage) {
+ var last = JSON.parse(lastMemoryUsage);
+ var diff = {
+ moduleObjs: dictDiff(last.moduleObjs, moduleObjs),
+ totalObjectClasses: dictDiff(last.totalObjectClasses,
+ data.totalObjectClasses)
+ };
+
+ for (let name in diff.moduleObjs)
+ print(" " + diff.moduleObjs[name] + " in " + name + "\n");
+ for (let name in diff.totalObjectClasses)
+ print(" " + diff.totalObjectClasses[name] + " instances of " +
+ name + "\n");
+ }
+ lastMemoryUsage = JSON.stringify(
+ {moduleObjs: moduleObjs,
+ totalObjectClasses: data.totalObjectClasses}
+ );
+}
+
+function dictDiff(last, curr) {
+ var diff = {};
+
+ for (let name in last) {
+ var result = (curr[name] || 0) - last[name];
+ if (result)
+ diff[name] = (result > 0 ? "+" : "") + result;
+ }
+ for (let name in curr) {
+ var result = curr[name] - (last[name] || 0);
+ if (result)
+ diff[name] = (result > 0 ? "+" : "") + result;
+ }
+ return diff;
+}
+
+function reportMemoryUsage() {
+ memory.gc();
+
+ var mgr = Cc["@mozilla.org/memory-reporter-manager;1"]
+ .getService(Ci.nsIMemoryReporterManager);
+ var reporters = mgr.enumerateReporters();
+ if (reporters.hasMoreElements())
+ print("\n");
+ while (reporters.hasMoreElements()) {
+ var reporter = reporters.getNext();
+ reporter.QueryInterface(Ci.nsIMemoryReporter);
+ print(reporter.description + ": " + reporter.memoryUsed + "\n");
+ }
+
+ var weakrefs = [info.weakref.get()
+ for each (info in memory.getObjects())];
+ weakrefs = [weakref for each (weakref in weakrefs) if (weakref)];
+ print("Tracked memory objects in testing sandbox: " +
+ weakrefs.length + "\n");
+}
+
+var gWeakrefInfo;
+
+function showResults() {
+ memory.gc();
+
+ if (gWeakrefInfo) {
+ gWeakrefInfo.forEach(
+ function(info) {
+ var ref = info.weakref.get();
+ if (ref !== null) {
+ var data = ref.__url__ ? ref.__url__ : ref;
+ var warning = data == "[object Object]"
+ ? "[object " + data.constructor.name + "(" +
+ [p for (p in data)].join(", ") + ")]"
+ : data;
+ console.warn("LEAK", warning, info.bin);
+ }
+ }
+ );
+ }
+
+ print("\n");
+ var total = results.passed + results.failed;
+ print(results.passed + " of " + total + " tests passed.\n");
+ onDone(results);
+}
+
+function cleanup() {
+ try {
+ for (let name in sandbox.modules)
+ memory.track(sandbox.modules[name],
+ "module global scope: " + name);
+ memory.track(sandbox, "Cuddlefish Loader");
+
+ if (profileMemory) {
+ gWeakrefInfo = [{ weakref: info.weakref, bin: info.bin }
+ for each (info in memory.getObjects())];
+ }
+
+ sandbox.unload();
+
+ if (sandbox.globals.console.errorsLogged && !results.failed) {
+ results.failed++;
+ console.error("warnings and/or errors were logged.");
+ }
+
+ if (consoleListener.errorsLogged && !results.failed) {
+ console.warn(consoleListener.errorsLogged + " " +
+ "warnings or errors were logged to the " +
+ "platform's nsIConsoleService, which could " +
+ "be of no consequence; however, they could also " +
+ "be indicative of aberrant behavior.");
+ }
+
+ consoleListener.errorsLogged = 0;
+ sandbox = null;
+
+ memory.gc();
+ } catch (e) {
+ results.failed++;
+ console.error("unload.send() threw an exception.");
+ console.exception(e);
+ };
+
+ require("api-utils/timer").setTimeout(showResults, 1);
+}
+
+function nextIteration(tests) {
+ if (tests) {
+ results.passed += tests.passed;
+ results.failed += tests.failed;
+
+ if (profileMemory)
+ reportMemoryUsage();
+
+ let testRun = [];
+ for each (let test in tests.testRunSummary) {
+ let testCopy = {};
+ for (let info in test) {
+ testCopy[info] = test[info];
+ }
+ testRun.push(testCopy);
+ }
+
+ results.testRuns.push(testRun);
+ iterationsLeft--;
+ }
+
+ if (iterationsLeft && (!stopOnError || results.failed == 0)) {
+ let require = Loader.require.bind(sandbox, module.path);
+ require("api-utils/unit-test").findAndRunTests({
+ testOutOfProcess: require('@packaging').enableE10s,
+ testInProcess: true,
+ stopOnError: stopOnError,
+ filter: filter,
+ onDone: nextIteration
+ });
+ }
+ else {
+ require("api-utils/timer").setTimeout(cleanup, 0);
+ }
+}
+
+var POINTLESS_ERRORS = [
+ "Invalid chrome URI:",
+ "OpenGL LayerManager Initialized Succesfully."
+];
+
+var consoleListener = {
+ errorsLogged: 0,
+ observe: function(object) {
+ if (!(object instanceof Ci.nsIScriptError))
+ return;
+ this.errorsLogged++;
+ var message = object.QueryInterface(Ci.nsIConsoleMessage).message;
+ var pointless = [err for each (err in POINTLESS_ERRORS)
+ if (message.indexOf(err) == 0)];
+ if (pointless.length == 0 && message)
+ print("console: " + message + "\n");
+ }
+};
+
+function TestRunnerConsole(base, options) {
+ this.__proto__ = {
+ errorsLogged: 0,
+ warn: function warn() {
+ this.errorsLogged++;
+ base.warn.apply(base, arguments);
+ },
+ error: function error() {
+ this.errorsLogged++;
+ base.error.apply(base, arguments);
+ },
+ info: function info(first) {
+ if (options.verbose)
+ base.info.apply(base, arguments);
+ else
+ if (first == "pass:")
+ print(".");
+ },
+ __proto__: base
+ };
+}
+
+var runTests = exports.runTests = function runTests(options) {
+ iterationsLeft = options.iterations;
+ filter = options.filter;
+ profileMemory = options.profileMemory;
+ stopOnError = options.stopOnError;
+ onDone = options.onDone;
+ print = options.print;
+
+ try {
+ cService.registerListener(consoleListener);
+
+ var ptc = require("api-utils/plain-text-console");
+ var url = require("api-utils/url");
+ var system = require("api-utils/system");
+
+ print("Running tests on " + system.name + " " + system.version +
+ "/Gecko " + system.platformVersion + " (" +
+ system.id + ") under " +
+ system.platform + "/" + system.architecture + ".\n");
+
+ sandbox = Loader.new(require("@packaging"));
+ Object.defineProperty(sandbox.globals, 'console', {
+ value: new TestRunnerConsole(new ptc.PlainTextConsole(print), options)
+ });
+
+ nextIteration();
+ } catch (e) {
+ print(require("api-utils/traceback").format(e) + "\n" + e + "\n");
+ onDone({passed: 0, failed: 1});
+ }
+};
+
+require("api-utils/unload").when(function() {
+ cService.unregisterListener(consoleListener);
+});
diff --git a/tools/addon-sdk-1.7/packages/test-harness/lib/run-tests.js b/tools/addon-sdk-1.7/packages/test-harness/lib/run-tests.js
new file mode 100644
index 0000000..4eb8570
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/test-harness/lib/run-tests.js
@@ -0,0 +1,101 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+var obsvc = require("api-utils/observer-service");
+var system = require("api-utils/system");
+var options = require('@packaging');
+var {Cc,Ci} = require("chrome");
+
+function runTests(iterations, filter, profileMemory, stopOnError, verbose, exit, print) {
+ var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"]
+ .getService(Ci.nsIWindowWatcher);
+
+ let ns = 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul';
+ let msg = 'Running tests...';
+ let markup = '<?xml version="1.0"?><window xmlns="' + ns +
+ '" windowtype="test:runner"><label>' + msg + '</label></window>';
+ let url = "data:application/vnd.mozilla.xul+xml," + escape(markup);
+
+
+ var window = ww.openWindow(null, url, "harness", "centerscreen", null);
+
+ var harness = require("./harness");
+
+ function onDone(tests) {
+ window.close();
+ if (tests.failed == 0) {
+ if (tests.passed === 0)
+ print("No tests were run\n");
+ exit(0);
+ } else {
+ printFailedTests(tests, verbose, print);
+ exit(1);
+ }
+ };
+
+ // We have to wait for this window to be fully loaded *and* focused
+ // in order to avoid it to mess with our various window/focus tests.
+ // We are first waiting for our window to be fully loaded before ensuring
+ // that it will take the focus, and then we wait for it to be focused.
+ window.addEventListener("load", function onload() {
+ window.removeEventListener("load", onload, true);
+
+ window.addEventListener("focus", function onfocus() {
+ window.removeEventListener("focus", onfocus, true);
+ // Finally, we have to run test on next cycle, otherwise XPCOM components
+ // are not correctly updated.
+ // For ex: nsIFocusManager.getFocusedElementForWindow may throw
+ // NS_ERROR_ILLEGAL_VALUE exception.
+ require("timer").setTimeout(function () {
+ harness.runTests({iterations: iterations,
+ filter: filter,
+ profileMemory: profileMemory,
+ stopOnError: stopOnError,
+ verbose: verbose,
+ print: print,
+ onDone: onDone});
+ }, 0);
+ }, true);
+ window.focus();
+ }, true);
+}
+
+function printFailedTests(tests, verbose, print) {
+ if (!verbose)
+ return;
+
+ let iterationNumber = 0;
+ let singleIteration = tests.testRuns.length == 1;
+ let padding = singleIteration ? "" : " ";
+
+ print("\nThe following tests failed:\n");
+
+ for each (let testRun in tests.testRuns) {
+ iterationNumber++;
+
+ if (!singleIteration)
+ print(" Iteration " + iterationNumber + ":\n");
+
+ for each (let test in testRun) {
+ if (test.failed > 0) {
+ print(padding + " " + test.name + ": " + test.errors +"\n");
+ }
+ }
+ print("\n");
+ }
+}
+
+exports.main = function main() {
+ var testsStarted = false;
+
+ if (!testsStarted) {
+ testsStarted = true;
+ runTests(options.iterations, options.filter,
+ options.profileMemory, options.stopOnError, options.verbose,
+ system.exit,
+ dump);
+ }
+};
diff --git a/tools/addon-sdk-1.7/packages/test-harness/package.json b/tools/addon-sdk-1.7/packages/test-harness/package.json
new file mode 100644
index 0000000..b44fb06
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/test-harness/package.json
@@ -0,0 +1,8 @@
+{
+ "name": "test-harness",
+ "description": "A harness for running Jetpack tests.",
+ "author": "Atul Varma (http://toolness.com/)",
+ "keywords": ["jetpack-low-level"],
+ "license": "MPL 2.0",
+ "dependencies": ["api-utils"]
+}
diff --git a/tools/addon-sdk-1.7/packages/test-harness/tests/test-packaging.js b/tools/addon-sdk-1.7/packages/test-harness/tests/test-packaging.js
new file mode 100644
index 0000000..0628af2
--- /dev/null
+++ b/tools/addon-sdk-1.7/packages/test-harness/tests/test-packaging.js
@@ -0,0 +1,18 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var url = require("url");
+var file = require("file");
+var {Cm,Ci} = require("chrome");
+var options = require("@packaging");
+
+exports.testPackaging = function(test) {
+ test.assertEqual(options.main,
+ 'test-harness/run-tests',
+ "main program should be the test harness");
+
+ test.assertEqual(options.metadata['test-harness'].author,
+ 'Atul Varma (http://toolness.com/)',
+ "packaging metadata should be available");
+};
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/__init__.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/__init__.py
new file mode 100644
index 0000000..9792eb9
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/__init__.py
@@ -0,0 +1,797 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import sys
+import os
+import optparse
+import webbrowser
+
+from copy import copy
+import simplejson as json
+from cuddlefish import packaging
+from cuddlefish._version import get_versions
+
+MOZRUNNER_BIN_NOT_FOUND = 'Mozrunner could not locate your binary'
+MOZRUNNER_BIN_NOT_FOUND_HELP = """
+I can't find the application binary in any of its default locations
+on your system. Please specify one using the -b/--binary option.
+"""
+
+UPDATE_RDF_FILENAME = "%s.update.rdf"
+XPI_FILENAME = "%s.xpi"
+
+usage = """
+%prog [options] command [command-specific options]
+
+Supported Commands:
+ docs - view web-based documentation
+ init - create a sample addon in an empty directory
+ test - run tests
+ run - run program
+ xpi - generate an xpi
+
+Internal Commands:
+ sdocs - export static documentation
+ testcfx - test the cfx tool
+ testex - test all example code
+ testpkgs - test all installed packages
+ testall - test whole environment
+
+Experimental and internal commands and options are not supported and may be
+changed or removed in the future.
+"""
+
+global_options = [
+ (("-v", "--verbose",), dict(dest="verbose",
+ help="enable lots of output",
+ action="store_true",
+ default=False)),
+ ]
+
+parser_groups = (
+ ("Supported Command-Specific Options", [
+ (("", "--update-url",), dict(dest="update_url",
+ help="update URL in install.rdf",
+ metavar=None,
+ default=None,
+ cmds=['xpi'])),
+ (("", "--update-link",), dict(dest="update_link",
+ help="generate update.rdf",
+ metavar=None,
+ default=None,
+ cmds=['xpi'])),
+ (("-p", "--profiledir",), dict(dest="profiledir",
+ help=("profile directory to pass to "
+ "app"),
+ metavar=None,
+ default=None,
+ cmds=['test', 'run', 'testex',
+ 'testpkgs', 'testall'])),
+ (("-b", "--binary",), dict(dest="binary",
+ help="path to app binary",
+ metavar=None,
+ default=None,
+ cmds=['test', 'run', 'testex', 'testpkgs',
+ 'testall'])),
+ (("", "--binary-args",), dict(dest="cmdargs",
+ help=("additional arguments passed to the "
+ "binary"),
+ metavar=None,
+ default=None,
+ cmds=['run', 'test'])),
+ (("", "--dependencies",), dict(dest="dep_tests",
+ help="include tests for all deps",
+ action="store_true",
+ default=False,
+ cmds=['test', 'testex', 'testpkgs',
+ 'testall'])),
+ (("", "--times",), dict(dest="iterations",
+ type="int",
+ help="number of times to run tests",
+ default=1,
+ cmds=['test', 'testex', 'testpkgs',
+ 'testall'])),
+ (("-f", "--filter",), dict(dest="filter",
+ help=("only run tests whose filenames "
+ "match FILENAME and optionally "
+ "match TESTNAME, both regexps"),
+ metavar="FILENAME[:TESTNAME]",
+ default=None,
+ cmds=['test', 'testex', 'testpkgs',
+ 'testall'])),
+ (("-g", "--use-config",), dict(dest="config",
+ help="use named config from local.json",
+ metavar=None,
+ default="default",
+ cmds=['test', 'run', 'xpi', 'testex',
+ 'testpkgs', 'testall'])),
+ (("", "--templatedir",), dict(dest="templatedir",
+ help="XULRunner app/ext. template",
+ metavar=None,
+ default=None,
+ cmds=['run', 'xpi'])),
+ (("", "--package-path",), dict(dest="packagepath", action="append",
+ help="extra directories for package search",
+ metavar=None,
+ default=[],
+ cmds=['run', 'xpi', 'test'])),
+ (("", "--extra-packages",), dict(dest="extra_packages",
+ help=("extra packages to include, "
+ "comma-separated. Default is "
+ "'addon-kit'."),
+ metavar=None,
+ default="addon-kit",
+ cmds=['run', 'xpi', 'test', 'testex',
+ 'testpkgs', 'testall',
+ 'testcfx'])),
+ (("", "--pkgdir",), dict(dest="pkgdir",
+ help=("package dir containing "
+ "package.json; default is "
+ "current directory"),
+ metavar=None,
+ default=None,
+ cmds=['run', 'xpi', 'test'])),
+ (("", "--static-args",), dict(dest="static_args",
+ help="extra harness options as JSON",
+ type="json",
+ metavar=None,
+ default="{}",
+ cmds=['run', 'xpi'])),
+ ]
+ ),
+
+ ("Experimental Command-Specific Options", [
+ (("-a", "--app",), dict(dest="app",
+ help=("app to run: firefox (default), fennec, "
+ "fennec-on-device, xulrunner or "
+ "thunderbird"),
+ metavar=None,
+ type="choice",
+ choices=["firefox", "fennec",
+ "fennec-on-device", "thunderbird",
+ "xulrunner"],
+ default="firefox",
+ cmds=['test', 'run', 'testex', 'testpkgs',
+ 'testall'])),
+ (("", "--no-run",), dict(dest="no_run",
+ help=("Instead of launching the "
+ "application, just show the command "
+ "for doing so. Use this to launch "
+ "the application in a debugger like "
+ "gdb."),
+ action="store_true",
+ default=False,
+ cmds=['run', 'test'])),
+ (("", "--no-strip-xpi",), dict(dest="no_strip_xpi",
+ help="retain unused modules in XPI",
+ action="store_true",
+ default=False,
+ cmds=['xpi'])),
+ (("", "--force-mobile",), dict(dest="enable_mobile",
+ help="Force compatibility with Firefox Mobile",
+ action="store_true",
+ default=False,
+ cmds=['run', 'test', 'xpi', 'testall'])),
+ (("", "--mobile-app",), dict(dest="mobile_app_name",
+ help=("Name of your Android application to "
+ "use. Possible values: 'firefox', "
+ "'firefox_beta', 'fennec_aurora', "
+ "'fennec' (for nightly)."),
+ metavar=None,
+ default=None,
+ cmds=['run', 'test', 'testall'])),
+ (("", "--harness-option",), dict(dest="extra_harness_option_args",
+ help=("Extra properties added to "
+ "harness-options.json"),
+ action="append",
+ metavar="KEY=VALUE",
+ default=[],
+ cmds=['xpi'])),
+ (("", "--stop-on-error",), dict(dest="stopOnError",
+ help="Stop running tests after the first failure",
+ action="store_true",
+ metavar=None,
+ default=False,
+ cmds=['test', 'testex', 'testpkgs'])),
+ ]
+ ),
+
+ ("Internal Command-Specific Options", [
+ (("", "--addons",), dict(dest="addons",
+ help=("paths of addons to install, "
+ "comma-separated"),
+ metavar=None,
+ default=None,
+ cmds=['test', 'run', 'testex', 'testpkgs',
+ 'testall'])),
+ (("", "--baseurl",), dict(dest="baseurl",
+ help=("root of static docs tree: "
+ "for example: 'http://me.com/the_docs/'"),
+ metavar=None,
+ default='',
+ cmds=['sdocs'])),
+ (("", "--test-runner-pkg",), dict(dest="test_runner_pkg",
+ help=("name of package "
+ "containing test runner "
+ "program (default is "
+ "test-harness)"),
+ default="test-harness",
+ cmds=['test', 'testex', 'testpkgs',
+ 'testall'])),
+ # --keydir was removed in 1.0b5, but we keep it around in the options
+ # parser to make life easier for frontends like FlightDeck which
+ # might still pass it. It can go away once the frontends are updated.
+ (("", "--keydir",), dict(dest="keydir",
+ help=("obsolete, ignored"),
+ metavar=None,
+ default=None,
+ cmds=['test', 'run', 'xpi', 'testex',
+ 'testpkgs', 'testall'])),
+ (("", "--e10s",), dict(dest="enable_e10s",
+ help="enable out-of-process Jetpacks",
+ action="store_true",
+ default=False,
+ cmds=['test', 'run', 'testex', 'testpkgs'])),
+ (("", "--logfile",), dict(dest="logfile",
+ help="log console output to file",
+ metavar=None,
+ default=None,
+ cmds=['run', 'test', 'testex', 'testpkgs'])),
+ # TODO: This should default to true once our memory debugging
+ # issues are resolved; see bug 592774.
+ (("", "--profile-memory",), dict(dest="profileMemory",
+ help=("profile memory usage "
+ "(default is false)"),
+ type="int",
+ action="store",
+ default=0,
+ cmds=['test', 'testex', 'testpkgs',
+ 'testall'])),
+ ]
+ ),
+ )
+
+def find_parent_package(cur_dir):
+ tail = True
+ while tail:
+ if os.path.exists(os.path.join(cur_dir, 'package.json')):
+ return cur_dir
+ cur_dir, tail = os.path.split(cur_dir)
+ return None
+
+def check_json(option, opt, value):
+ # We return the parsed JSON here; see bug 610816 for background on why.
+ try:
+ return json.loads(value)
+ except ValueError:
+ raise optparse.OptionValueError("Option %s must be JSON." % opt)
+
+class CfxOption(optparse.Option):
+ TYPES = optparse.Option.TYPES + ('json',)
+ TYPE_CHECKER = copy(optparse.Option.TYPE_CHECKER)
+ TYPE_CHECKER['json'] = check_json
+
+def parse_args(arguments, global_options, usage, version, parser_groups,
+ defaults=None):
+ parser = optparse.OptionParser(usage=usage.strip(), option_class=CfxOption,
+ version=version)
+
+ def name_cmp(a, b):
+ # a[0] = name sequence
+ # a[0][0] = short name (possibly empty string)
+ # a[0][1] = long name
+ names = []
+ for seq in (a, b):
+ names.append(seq[0][0][1:] if seq[0][0] else seq[0][1][2:])
+ return cmp(*names)
+
+ global_options.sort(name_cmp)
+ for names, opts in global_options:
+ parser.add_option(*names, **opts)
+
+ for group_name, options in parser_groups:
+ group = optparse.OptionGroup(parser, group_name)
+ options.sort(name_cmp)
+ for names, opts in options:
+ if 'cmds' in opts:
+ cmds = opts['cmds']
+ del opts['cmds']
+ cmds.sort()
+ if not 'help' in opts:
+ opts['help'] = ""
+ opts['help'] += " (%s)" % ", ".join(cmds)
+ group.add_option(*names, **opts)
+ parser.add_option_group(group)
+
+ if defaults:
+ parser.set_defaults(**defaults)
+
+ (options, args) = parser.parse_args(args=arguments)
+
+ if not args:
+ parser.print_help()
+ parser.exit()
+
+ return (options, args)
+
+# all tests emit progress messages to stderr, not stdout. (the mozrunner
+# console output goes to stderr and is hard to change, and
+# unittest.TextTestRunner prefers stderr, so we send everything else there
+# too, to keep all the messages in order)
+
+def test_all(env_root, defaults):
+ fail = False
+
+ print >>sys.stderr, "Testing cfx..."
+ sys.stderr.flush()
+ result = test_cfx(env_root, defaults['verbose'])
+ if result.failures or result.errors:
+ fail = True
+
+ if not fail or not defaults.get("stopOnError"):
+ print >>sys.stderr, "Testing all examples..."
+ sys.stderr.flush()
+
+ try:
+ test_all_examples(env_root, defaults)
+ except SystemExit, e:
+ fail = (e.code != 0) or fail
+
+ if not fail or not defaults.get("stopOnError"):
+ print >>sys.stderr, "Testing all packages..."
+ sys.stderr.flush()
+ try:
+ test_all_packages(env_root, defaults)
+ except SystemExit, e:
+ fail = (e.code != 0) or fail
+
+ if fail:
+ print >>sys.stderr, "Some tests were unsuccessful."
+ sys.exit(1)
+ print >>sys.stderr, "All tests were successful. Ship it!"
+ sys.exit(0)
+
+def test_cfx(env_root, verbose):
+ import cuddlefish.tests
+
+ # tests write to stderr. flush everything before and after to avoid
+ # confusion later.
+ sys.stdout.flush(); sys.stderr.flush()
+ olddir = os.getcwd()
+ os.chdir(env_root)
+ retval = cuddlefish.tests.run(verbose)
+ os.chdir(olddir)
+ sys.stdout.flush(); sys.stderr.flush()
+ return retval
+
+def test_all_examples(env_root, defaults):
+ examples_dir = os.path.join(env_root, "examples")
+ examples = [dirname for dirname in os.listdir(examples_dir)
+ if os.path.isdir(os.path.join(examples_dir, dirname))]
+ examples.sort()
+ fail = False
+ for dirname in examples:
+ print >>sys.stderr, "Testing %s..." % dirname
+ sys.stderr.flush()
+ try:
+ run(arguments=["test",
+ "--pkgdir",
+ os.path.join(examples_dir, dirname)],
+ defaults=defaults,
+ env_root=env_root)
+ except SystemExit, e:
+ fail = (e.code != 0) or fail
+ if fail and defaults.get("stopOnError"):
+ break
+
+ if fail:
+ print >>sys.stderr, "Some examples tests were unsuccessful."
+ sys.exit(-1)
+
+def test_all_packages(env_root, defaults):
+ packages_dir = os.path.join(env_root, "packages")
+ packages = [dirname for dirname in os.listdir(packages_dir)
+ if os.path.isdir(os.path.join(packages_dir, dirname))]
+ packages.sort()
+ print >>sys.stderr, "Testing all available packages: %s." % (", ".join(packages))
+ sys.stderr.flush()
+ fail = False
+ for dirname in packages:
+ print >>sys.stderr, "Testing %s..." % dirname
+ sys.stderr.flush()
+ try:
+ run(arguments=["test",
+ "--pkgdir",
+ os.path.join(packages_dir, dirname)],
+ defaults=defaults,
+ env_root=env_root)
+ except SystemExit, e:
+ fail = (e.code != 0) or fail
+ if fail and defaults.get('stopOnError'):
+ break
+ if fail:
+ print >>sys.stderr, "Some package tests were unsuccessful."
+ sys.exit(-1)
+
+def get_config_args(name, env_root):
+ local_json = os.path.join(env_root, "local.json")
+ if not (os.path.exists(local_json) and
+ os.path.isfile(local_json)):
+ if name == "default":
+ return []
+ else:
+ print >>sys.stderr, "File does not exist: %s" % local_json
+ sys.exit(1)
+ local_json = packaging.load_json_file(local_json)
+ if 'configs' not in local_json:
+ print >>sys.stderr, "'configs' key not found in local.json."
+ sys.exit(1)
+ if name not in local_json.configs:
+ if name == "default":
+ return []
+ else:
+ print >>sys.stderr, "No config found for '%s'." % name
+ sys.exit(1)
+ config = local_json.configs[name]
+ if type(config) != list:
+ print >>sys.stderr, "Config for '%s' must be a list of strings." % name
+ sys.exit(1)
+ return config
+
+def initializer(env_root, args, out=sys.stdout, err=sys.stderr):
+ from templates import MAIN_JS, PACKAGE_JSON, README_DOC, MAIN_JS_DOC, TEST_MAIN_JS
+ path = os.getcwd()
+ addon = os.path.basename(path)
+ # if more than one argument
+ if len(args) > 1:
+ print >>err, 'Too many arguments.'
+ return 1
+ # avoid clobbering existing files, but we tolerate things like .git
+ existing = [fn for fn in os.listdir(path) if not fn.startswith(".")]
+ if existing:
+ print >>err, 'This command must be run in an empty directory.'
+ return 1
+ for d in ['lib','data','test','doc']:
+ os.mkdir(os.path.join(path,d))
+ print >>out, '*', d, 'directory created'
+ open('README.md','w').write(README_DOC % {'name':addon})
+ print >>out, '* README.md written'
+ open('package.json','w').write(PACKAGE_JSON % {'name':addon.lower(),
+ 'fullName':addon })
+ print >>out, '* package.json written'
+ open(os.path.join(path,'test','test-main.js'),'w').write(TEST_MAIN_JS)
+ print >>out, '* test/test-main.js written'
+ open(os.path.join(path,'lib','main.js'),'w').write(MAIN_JS)
+ print >>out, '* lib/main.js written'
+ open(os.path.join(path,'doc','main.md'),'w').write(MAIN_JS_DOC)
+ print >>out, '* doc/main.md written'
+ print >>out, '\nYour sample add-on is now ready.'
+ print >>out, 'Do "cfx test" to test it and "cfx run" to try it. Have fun!'
+ return 0
+
+def buildJID(target_cfg):
+ if "id" in target_cfg:
+ jid = target_cfg["id"]
+ else:
+ import uuid
+ jid = str(uuid.uuid4())
+ if not ("@" in jid or jid.startswith("{")):
+ jid = jid + "@jetpack"
+ return jid
+
+def run(arguments=sys.argv[1:], target_cfg=None, pkg_cfg=None,
+ defaults=None, env_root=os.environ.get('CUDDLEFISH_ROOT'),
+ stdout=sys.stdout):
+ versions = get_versions()
+ sdk_version = versions["version"]
+ display_version = "Add-on SDK %s (%s)" % (sdk_version, versions["full"])
+ parser_kwargs = dict(arguments=arguments,
+ global_options=global_options,
+ parser_groups=parser_groups,
+ usage=usage,
+ version=display_version,
+ defaults=defaults)
+
+ (options, args) = parse_args(**parser_kwargs)
+
+ config_args = get_config_args(options.config, env_root);
+
+ # reparse configs with arguments from local.json
+ if config_args:
+ parser_kwargs['arguments'] += config_args
+ (options, args) = parse_args(**parser_kwargs)
+
+ command = args[0]
+
+ if command == "init":
+ initializer(env_root, args)
+ return
+ if command == "testpkgs":
+ test_all_packages(env_root, defaults=options.__dict__)
+ return
+ elif command == "testex":
+ test_all_examples(env_root, defaults=options.__dict__)
+ return
+ elif command == "testall":
+ test_all(env_root, defaults=options.__dict__)
+ return
+ elif command == "testcfx":
+ test_cfx(env_root, options.verbose)
+ return
+ elif command == "docs":
+ from cuddlefish.docs import generate
+ if len(args) > 1:
+ docs_home = generate.generate_named_file(env_root, filename=args[1])
+ else:
+ docs_home = generate.generate_local_docs(env_root)
+ webbrowser.open(docs_home)
+ return
+ elif command == "sdocs":
+ from cuddlefish.docs import generate
+ filename = generate.generate_static_docs(env_root)
+ print >>stdout, "Wrote %s." % filename
+ return
+ elif command not in ["xpi", "test", "run"]:
+ print >>sys.stderr, "Unknown command: %s" % command
+ print >>sys.stderr, "Try using '--help' for assistance."
+ sys.exit(1)
+
+ target_cfg_json = None
+ if not target_cfg:
+ if not options.pkgdir:
+ options.pkgdir = find_parent_package(os.getcwd())
+ if not options.pkgdir:
+ print >>sys.stderr, ("cannot find 'package.json' in the"
+ " current directory or any parent.")
+ sys.exit(1)
+ else:
+ options.pkgdir = os.path.abspath(options.pkgdir)
+ if not os.path.exists(os.path.join(options.pkgdir, 'package.json')):
+ print >>sys.stderr, ("cannot find 'package.json' in"
+ " %s." % options.pkgdir)
+ sys.exit(1)
+
+ target_cfg_json = os.path.join(options.pkgdir, 'package.json')
+ target_cfg = packaging.get_config_in_dir(options.pkgdir)
+
+ # At this point, we're either building an XPI or running Jetpack code in
+ # a Mozilla application (which includes running tests).
+
+ use_main = False
+ inherited_options = ['verbose', 'enable_e10s']
+ enforce_timeouts = False
+
+ if command == "xpi":
+ use_main = True
+ elif command == "test":
+ if 'tests' not in target_cfg:
+ target_cfg['tests'] = []
+ inherited_options.extend(['iterations', 'filter', 'profileMemory',
+ 'stopOnError'])
+ enforce_timeouts = True
+ elif command == "run":
+ use_main = True
+ else:
+ assert 0, "shouldn't get here"
+
+ if use_main and 'main' not in target_cfg:
+ # If the user supplies a template dir, then the main
+ # program may be contained in the template.
+ if not options.templatedir:
+ print >>sys.stderr, "package.json does not have a 'main' entry."
+ sys.exit(1)
+
+ if not pkg_cfg:
+ pkg_cfg = packaging.build_config(env_root, target_cfg, options.packagepath)
+
+ target = target_cfg.name
+
+ # TODO: Consider keeping a cache of dynamic UUIDs, based
+ # on absolute filesystem pathname, in the root directory
+ # or something.
+ if command in ('xpi', 'run'):
+ from cuddlefish.preflight import preflight_config
+ if target_cfg_json:
+ config_was_ok, modified = preflight_config(target_cfg,
+ target_cfg_json)
+ if not config_was_ok:
+ if modified:
+ # we need to re-read package.json . The safest approach
+ # is to re-run the "cfx xpi"/"cfx run" command.
+ print >>sys.stderr, ("package.json modified: please re-run"
+ " 'cfx %s'" % command)
+ else:
+ print >>sys.stderr, ("package.json needs modification:"
+ " please update it and then re-run"
+ " 'cfx %s'" % command)
+ sys.exit(1)
+ # if we make it this far, we have a JID
+ else:
+ assert command == "test"
+
+ jid = buildJID(target_cfg)
+
+ targets = [target]
+ if command == "test":
+ targets.append(options.test_runner_pkg)
+
+ extra_packages = []
+ if options.extra_packages:
+ extra_packages = options.extra_packages.split(",")
+ if extra_packages:
+ targets.extend(extra_packages)
+ target_cfg.extra_dependencies = extra_packages
+
+ deps = packaging.get_deps_for_targets(pkg_cfg, targets)
+
+ from cuddlefish.manifest import build_manifest, ModuleNotFoundError
+ # Figure out what loader files should be scanned. This is normally
+ # computed inside packaging.generate_build_for_target(), by the first
+ # dependent package that defines a "loader" property in its package.json.
+ # This property is interpreted as a filename relative to the top of that
+ # file, and stored as a path in build.loader . generate_build_for_target()
+ # cannot be called yet (it needs the list of used_deps that
+ # build_manifest() computes, but build_manifest() needs the list of
+ # loader files that it computes). We could duplicate or factor out this
+ # build.loader logic, but that would be messy, so instead we hard-code
+ # the choice of loader for manifest-generation purposes. In practice,
+ # this means that alternative loaders probably won't work with
+ # --strip-xpi.
+ assert packaging.DEFAULT_LOADER == "api-utils"
+ assert pkg_cfg.packages["api-utils"].loader == "lib/cuddlefish.js"
+ cuddlefish_js_path = os.path.join(pkg_cfg.packages["api-utils"].root_dir,
+ "lib", "cuddlefish.js")
+ loader_modules = [("api-utils", "lib", "cuddlefish", cuddlefish_js_path)]
+ scan_tests = command == "test"
+ test_filter_re = None
+ if scan_tests and options.filter:
+ test_filter_re = options.filter
+ if ":" in options.filter:
+ test_filter_re = options.filter.split(":")[0]
+ try:
+ manifest = build_manifest(target_cfg, pkg_cfg, deps,
+ scan_tests, test_filter_re,
+ loader_modules)
+ except ModuleNotFoundError, e:
+ print str(e)
+ sys.exit(1)
+ used_deps = manifest.get_used_packages()
+ if command == "test":
+ # The test runner doesn't appear to link against any actual packages,
+ # because it loads everything at runtime (invisible to the linker).
+ # If we believe that, we won't set up URI mappings for anything, and
+ # tests won't be able to run.
+ used_deps = deps
+ for xp in extra_packages:
+ if xp not in used_deps:
+ used_deps.append(xp)
+
+ build = packaging.generate_build_for_target(
+ pkg_cfg, target, used_deps,
+ include_dep_tests=options.dep_tests
+ )
+
+ harness_options = {
+ 'jetpackID': jid,
+ 'staticArgs': options.static_args,
+ 'name': target,
+ }
+
+ harness_options.update(build)
+
+ extra_environment = {}
+ if command == "test":
+ # This should be contained in the test runner package.
+ # maybe just do: target_cfg.main = 'test-harness/run-tests'
+ harness_options['main'] = 'test-harness/run-tests'
+ harness_options['mainPath'] = manifest.get_manifest_entry("test-harness", "lib", "run-tests").get_path()
+ else:
+ harness_options['main'] = target_cfg.get('main')
+ harness_options['mainPath'] = manifest.top_path
+ extra_environment["CFX_COMMAND"] = command
+
+ for option in inherited_options:
+ harness_options[option] = getattr(options, option)
+
+ harness_options['metadata'] = packaging.get_metadata(pkg_cfg, used_deps)
+
+ harness_options['sdkVersion'] = sdk_version
+
+ packaging.call_plugins(pkg_cfg, used_deps)
+
+ retval = 0
+
+ if options.templatedir:
+ app_extension_dir = os.path.abspath(options.templatedir)
+ else:
+ mydir = os.path.dirname(os.path.abspath(__file__))
+ app_extension_dir = os.path.join(mydir, "app-extension")
+
+
+ if target_cfg.get('preferences'):
+ harness_options['preferences'] = target_cfg.get('preferences')
+
+ harness_options['manifest'] = manifest.get_harness_options_manifest()
+ harness_options['allTestModules'] = manifest.get_all_test_modules()
+
+ from cuddlefish.rdf import gen_manifest, RDFUpdate
+
+ manifest_rdf = gen_manifest(template_root_dir=app_extension_dir,
+ target_cfg=target_cfg,
+ jid=jid,
+ update_url=options.update_url,
+ bootstrap=True,
+ enable_mobile=options.enable_mobile)
+
+ if command == "xpi" and options.update_link:
+ rdf_name = UPDATE_RDF_FILENAME % target_cfg.name
+ print >>stdout, "Exporting update description to %s." % rdf_name
+ update = RDFUpdate()
+ update.add(manifest_rdf, options.update_link)
+ open(rdf_name, "w").write(str(update))
+
+ # ask the manifest what files were used, so we can construct an XPI
+ # without the rest. This will include the loader (and everything it
+ # uses) because of the "loader_modules" starting points we passed to
+ # build_manifest earlier
+ used_files = None
+ if command == "xpi":
+ used_files = set(manifest.get_used_files())
+
+ if options.no_strip_xpi:
+ used_files = None # disables the filter, includes all files
+
+ if command == 'xpi':
+ from cuddlefish.xpi import build_xpi
+ extra_harness_options = {}
+ for kv in options.extra_harness_option_args:
+ key,value = kv.split("=", 1)
+ extra_harness_options[key] = value
+ xpi_path = XPI_FILENAME % target_cfg.name
+ print >>stdout, "Exporting extension to %s." % xpi_path
+ build_xpi(template_root_dir=app_extension_dir,
+ manifest=manifest_rdf,
+ xpi_path=xpi_path,
+ harness_options=harness_options,
+ limit_to=used_files,
+ extra_harness_options=extra_harness_options)
+ else:
+ from cuddlefish.runner import run_app
+
+ if options.profiledir:
+ options.profiledir = os.path.expanduser(options.profiledir)
+ options.profiledir = os.path.abspath(options.profiledir)
+
+ if options.addons is not None:
+ options.addons = options.addons.split(",")
+
+ try:
+ retval = run_app(harness_root_dir=app_extension_dir,
+ manifest_rdf=manifest_rdf,
+ harness_options=harness_options,
+ app_type=options.app,
+ binary=options.binary,
+ profiledir=options.profiledir,
+ verbose=options.verbose,
+ enforce_timeouts=enforce_timeouts,
+ logfile=options.logfile,
+ addons=options.addons,
+ args=options.cmdargs,
+ extra_environment=extra_environment,
+ norun=options.no_run,
+ used_files=used_files,
+ enable_mobile=options.enable_mobile,
+ mobile_app_name=options.mobile_app_name)
+ except ValueError, e:
+ print ""
+ print "A given cfx option has an inappropriate value:"
+ print >>sys.stderr, " " + " \n ".join(str(e).split("\n"))
+ retval = -1
+ except Exception, e:
+ if str(e).startswith(MOZRUNNER_BIN_NOT_FOUND):
+ print >>sys.stderr, MOZRUNNER_BIN_NOT_FOUND_HELP.strip()
+ retval = -1
+ else:
+ raise
+ sys.exit(retval)
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/_version.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/_version.py
new file mode 100644
index 0000000..61e7178
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/_version.py
@@ -0,0 +1,171 @@
+
+# This file helps to compute a version number in source trees obtained from
+# git-archive tarball (such as those provided by githubs download-from-tag
+# feature). Distribution tarballs (build by setup.py sdist) and build
+# directories (produced by setup.py build) will contain a much shorter file
+# that just contains the computed version number.
+
+# This file is released into the public domain. Generated by versioneer-0.6
+# (https://github.com/warner/python-versioneer)
+
+# these strings will be replaced by git during git-archive
+git_refnames = " (HEAD, 1.7rc2, 1.7, origin/stabilization, stabilization)"
+git_full = "075becdd649500d845fa15aea09129e6aef02bef"
+
+
+import subprocess
+
+def run_command(args, cwd=None, verbose=False):
+ try:
+ # remember shell=False, so use git.cmd on windows, not just git
+ p = subprocess.Popen(args, stdout=subprocess.PIPE, cwd=cwd)
+ except EnvironmentError, e:
+ if verbose:
+ print "unable to run %s" % args[0]
+ print e
+ return None
+ stdout = p.communicate()[0].strip()
+ if p.returncode != 0:
+ if verbose:
+ print "unable to run %s (error)" % args[0]
+ return None
+ return stdout
+
+
+import sys
+import re
+import os.path
+
+def get_expanded_variables(versionfile_source):
+ # the code embedded in _version.py can just fetch the value of these
+ # variables. When used from setup.py, we don't want to import
+ # _version.py, so we do it with a regexp instead. This function is not
+ # used from _version.py.
+ variables = {}
+ try:
+ for line in open(versionfile_source,"r").readlines():
+ if line.strip().startswith("git_refnames ="):
+ mo = re.search(r'=\s*"(.*)"', line)
+ if mo:
+ variables["refnames"] = mo.group(1)
+ if line.strip().startswith("git_full ="):
+ mo = re.search(r'=\s*"(.*)"', line)
+ if mo:
+ variables["full"] = mo.group(1)
+ except EnvironmentError:
+ pass
+ return variables
+
+def versions_from_expanded_variables(variables, tag_prefix):
+ refnames = variables["refnames"].strip()
+ if refnames.startswith("$Format"):
+ return {} # unexpanded, so not in an unpacked git-archive tarball
+ refs = set([r.strip() for r in refnames.strip("()").split(",")])
+ for ref in list(refs):
+ if not re.search(r'\d', ref):
+ refs.discard(ref)
+ # Assume all version tags have a digit. git's %d expansion
+ # behaves like git log --decorate=short and strips out the
+ # refs/heads/ and refs/tags/ prefixes that would let us
+ # distinguish between branches and tags. By ignoring refnames
+ # without digits, we filter out many common branch names like
+ # "release" and "stabilization", as well as "HEAD" and "master".
+ for ref in sorted(refs):
+ # sorting will prefer e.g. "2.0" over "2.0rc1"
+ if ref.startswith(tag_prefix):
+ r = ref[len(tag_prefix):]
+ return { "version": r,
+ "full": variables["full"].strip() }
+ # no suitable tags, so we use the full revision id
+ return { "version": variables["full"].strip(),
+ "full": variables["full"].strip() }
+
+def versions_from_vcs(tag_prefix, versionfile_source, verbose=False):
+ # this runs 'git' from the root of the source tree. That either means
+ # someone ran a setup.py command (and this code is in versioneer.py, thus
+ # the containing directory is the root of the source tree), or someone
+ # ran a project-specific entry point (and this code is in _version.py,
+ # thus the containing directory is somewhere deeper in the source tree).
+ # This only gets called if the git-archive 'subst' variables were *not*
+ # expanded, and _version.py hasn't already been rewritten with a short
+ # version string, meaning we're inside a checked out source tree.
+
+ try:
+ here = os.path.abspath(__file__)
+ except NameError:
+ # some py2exe/bbfreeze/non-CPython implementations don't do __file__
+ return {} # not always correct
+
+ # versionfile_source is the relative path from the top of the source tree
+ # (where the .git directory might live) to this file. Invert this to find
+ # the root from __file__.
+ root = here
+ for i in range(len(versionfile_source.split("/"))):
+ root = os.path.dirname(root)
+ if not os.path.exists(os.path.join(root, ".git")):
+ return {}
+
+ GIT = "git"
+ if sys.platform == "win32":
+ GIT = "git.cmd"
+ stdout = run_command([GIT, "describe", "--tags", "--dirty", "--always"],
+ cwd=root)
+ if stdout is None:
+ return {}
+ if not stdout.startswith(tag_prefix):
+ if verbose:
+ print "tag '%s' doesn't start with prefix '%s'" % (stdout, tag_prefix)
+ return {}
+ tag = stdout[len(tag_prefix):]
+ stdout = run_command([GIT, "rev-parse", "HEAD"], cwd=root)
+ if stdout is None:
+ return {}
+ full = stdout.strip()
+ if tag.endswith("-dirty"):
+ full += "-dirty"
+ return {"version": tag, "full": full}
+
+
+def versions_from_parentdir(parentdir_prefix, versionfile_source, verbose=False):
+ try:
+ here = os.path.abspath(__file__)
+ # versionfile_source is the relative path from the top of the source
+ # tree (where the .git directory might live) to _version.py, when
+ # this is used by the runtime. Invert this to find the root from
+ # __file__.
+ root = here
+ for i in range(len(versionfile_source.split("/"))):
+ root = os.path.dirname(root)
+ except NameError:
+ # try a couple different things to handle py2exe, bbfreeze, and
+ # non-CPython implementations which don't do __file__. This code
+ # either lives in versioneer.py (used by setup.py) or _version.py
+ # (used by the runtime). In the versioneer.py case, sys.argv[0] will
+ # be setup.py, in the root of the source tree. In the _version.py
+ # case, we have no idea what sys.argv[0] is (some
+ # application-specific runner).
+ root = os.path.dirname(os.path.abspath(sys.argv[0]))
+ # Source tarballs conventionally unpack into a directory that includes
+ # both the project name and a version string.
+ dirname = os.path.basename(root)
+ if not dirname.startswith(parentdir_prefix):
+ if verbose:
+ print "dirname '%s' doesn't start with prefix '%s'" % (dirname, parentdir_prefix)
+ return None
+ return {"version": dirname[len(parentdir_prefix):], "full": ""}
+
+tag_prefix = ""
+parentdir_prefix = "addon-sdk-"
+versionfile_source = "python-lib/cuddlefish/_version.py"
+
+def get_versions():
+ variables = { "refnames": git_refnames, "full": git_full }
+ ver = versions_from_expanded_variables(variables, tag_prefix)
+ if not ver:
+ ver = versions_from_vcs(tag_prefix, versionfile_source)
+ if not ver:
+ ver = versions_from_parentdir(parentdir_prefix, versionfile_source)
+ if not ver:
+ ver = {"version": "unknown", "full": ""}
+ return ver
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/app-extension/application.ini b/tools/addon-sdk-1.7/python-lib/cuddlefish/app-extension/application.ini
new file mode 100644
index 0000000..6cec69a
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/app-extension/application.ini
@@ -0,0 +1,11 @@
+[App]
+Vendor=Varma
+Name=Test App
+Version=1.0
+BuildID=20060101
+Copyright=Copyright (c) 2009 Atul Varma
+ID=xulapp@toolness.com
+
+[Gecko]
+MinVersion=1.9.2.0
+MaxVersion=2.0.*
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/app-extension/bootstrap.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/app-extension/bootstrap.js
new file mode 100644
index 0000000..661f2bb
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/app-extension/bootstrap.js
@@ -0,0 +1,216 @@
+/* vim:set ts=2 sw=2 sts=2 expandtab */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// @see http://mxr.mozilla.org/mozilla-central/source/js/src/xpconnect/loader/mozJSComponentLoader.cpp
+
+"use strict";
+
+const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu,
+ results: Cr, manager: Cm } = Components;
+const ioService = Cc['@mozilla.org/network/io-service;1'].
+ getService(Ci.nsIIOService);
+const resourceHandler = ioService.getProtocolHandler('resource')
+ .QueryInterface(Ci.nsIResProtocolHandler);
+const XMLHttpRequest = CC('@mozilla.org/xmlextras/xmlhttprequest;1',
+ 'nsIXMLHttpRequest');
+const prefs = Cc["@mozilla.org/preferences-service;1"].
+ getService(Ci.nsIPrefService).
+ QueryInterface(Ci.nsIPrefBranch2);
+const mozIJSSubScriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
+ getService(Ci.mozIJSSubScriptLoader);
+
+const REASON = [ 'unknown', 'startup', 'shutdown', 'enable', 'disable',
+ 'install', 'uninstall', 'upgrade', 'downgrade' ];
+
+let loader = null;
+let loaderUri = null;
+
+const URI = __SCRIPT_URI_SPEC__.replace(/bootstrap\.js$/, "");
+
+// Initializes default preferences
+function setDefaultPrefs() {
+ let branch = prefs.getDefaultBranch("");
+ let prefLoaderScope = {
+ pref: function(key, val) {
+ switch (typeof val) {
+ case "boolean":
+ branch.setBoolPref(key, val);
+ break;
+ case "number":
+ if (val % 1 == 0) // number must be a integer, otherwise ignore it
+ branch.setIntPref(key, val);
+ break;
+ case "string":
+ branch.setCharPref(key, val);
+ break;
+ }
+ }
+ };
+
+ let uri = ioService.newURI(
+ "defaults/preferences/prefs.js",
+ null,
+ ioService.newURI(URI, null, null));
+
+ // if there is a prefs.js file, then import the default prefs
+ try {
+ // setup default prefs
+ mozIJSSubScriptLoader.loadSubScript(uri.spec, prefLoaderScope);
+ }
+ // errors here should not kill addon
+ catch (e) {
+ Cu.reportError(e);
+ }
+}
+
+// Gets the topic that fit best as application startup event, in according with
+// the current application (e.g. Firefox, Fennec, Thunderbird...)
+function getAppStartupTopic() {
+ // The following mapping of application names to GUIDs was taken
+ // from `xul-app` module. They should keep in sync, so if you change one,
+ // change the other too!
+ let ids = {
+ Firefox: '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}',
+ Mozilla: '{86c18b42-e466-45a9-ae7a-9b95ba6f5640}',
+ Sunbird: '{718e30fb-e89b-41dd-9da7-e25a45638b28}',
+ SeaMonkey: '{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}',
+ Fennec: '{aa3c5121-dab2-40e2-81ca-7ea25febc110}',
+ Thunderbird: '{3550f703-e582-4d05-9a08-453d09bdfdc6}'
+ };
+
+ let id = Cc['@mozilla.org/xre/app-info;1'].getService(Ci.nsIXULAppInfo).ID;
+
+ switch (id) {
+ case ids.Firefox:
+ case ids.SeaMonkey:
+ return 'sessionstore-windows-restored';
+ case ids.Thunderbird:
+ return 'mail-startup-done';
+ // Temporary, until Fennec Birch will support sessionstore event
+ case ids.Fennec:
+ default:
+ return 'final-ui-startup';
+ }
+}
+
+// Utility function that synchronously reads local resource from the given
+// `uri` and returns content string.
+function readURI(uri) {
+ let ioservice = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
+ let channel = ioservice.newChannel(uri, "UTF-8", null);
+ let stream = channel.open();
+
+ let cstream = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(Ci.nsIConverterInputStream);
+ cstream.init(stream, "UTF-8", 0, 0);
+
+ let str = {};
+ let data = "";
+ let read = 0;
+ do {
+ read = cstream.readString(0xffffffff, str);
+ data += str.value;
+ } while (read != 0);
+
+ cstream.close();
+
+ return data;
+}
+
+// Function takes `topic` to be observer via `nsIObserverService` and returns
+// promise that will be delivered once notification is published.
+function on(topic) {
+ return function promise(deliver) {
+ const observerService = Cc['@mozilla.org/observer-service;1'].
+ getService(Ci.nsIObserverService);
+
+ observerService.addObserver({
+ observe: function observer(subject, topic, data) {
+ observerService.removeObserver(this, topic);
+ deliver(subject, topic, data);
+ }
+ }, topic, false);
+ }
+}
+
+// We don't do anything on install & uninstall yet, but in a future
+// we should allow add-ons to cleanup after uninstall.
+function install(data, reason) {}
+function uninstall(data, reason) {}
+
+function startup(data, reason) {
+ // TODO: When bug 564675 is implemented this will no longer be needed
+ // Always set the default prefs, because they disappear on restart
+ setDefaultPrefs();
+
+ // TODO: Maybe we should perform read harness-options.json asynchronously,
+ // since we can't do anything until 'sessionstore-windows-restored' anyway.
+ let options = JSON.parse(readURI(URI + './harness-options.json'));
+ options.loadReason = REASON[reason];
+
+ // URI for the root of the XPI file.
+ // 'jar:' URI if the addon is packed, 'file:' URI otherwise.
+ // (Used by l10n module in order to fetch `locale` folder)
+ options.rootURI = data.resourceURI.spec;
+
+ // Register a new resource "domain" for this addon which is mapping to
+ // XPI's `resources` folder.
+ // Generate the domain name by using jetpack ID, which is the extension ID
+ // by stripping common characters that doesn't work as a domain name:
+ let uuidRe =
+ /^\{([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\}$/;
+ let domain = options.jetpackID.toLowerCase()
+ .replace(/@/g, "-at-")
+ .replace(/\./g, "-dot-")
+ .replace(uuidRe, "$1");
+
+ let resourcesUri = ioService.newURI(URI + '/resources/', null, null);
+ resourceHandler.setSubstitution(domain, resourcesUri);
+ options.uriPrefix = "resource://" + domain + "/";
+
+ // Import loader module using `Cu.imports` and bootstrap module loader.
+ loaderUri = options.uriPrefix + options.loader;
+ loader = Cu.import(loaderUri).Loader.new(options);
+
+ // Creating a promise, that will be delivered once application is ready.
+ // If application is at startup then promise is delivered on
+ // the application startup topic, otherwise it's delivered immediately.
+ let promise = reason === APP_STARTUP ? on(getAppStartupTopic()) :
+ function promise(deliver) deliver()
+
+ // Once application is ready we spawn a new process with main module of
+ // on add-on.
+ promise(function() {
+ try {
+ loader.spawn(options.main, options.mainPath);
+ } catch (error) {
+ // If at this stage we have an error only thing we can do is report about
+ // it via error console. Keep in mind that error won't automatically show
+ // up there when called via observerService.
+ Cu.reportError(error);
+ throw error;
+ }
+ });
+
+};
+
+function shutdown(data, reason) {
+ // If loader is already present unload it, since add-on is disabled.
+ if (loader) {
+ reason = REASON[reason];
+ let system = loader.require('api-utils/system');
+ loader.unload(reason);
+
+ // Bug 724433: We need to unload JSM otherwise it will stay alive
+ // and keep a reference to this compartment.
+ Cu.unload(loaderUri);
+ loader = null;
+
+ // If add-on is lunched via `cfx run` we need to use `system.exit` to let
+ // cfx know we're done (`cfx test` will take care of exit so we don't do
+ // anything here).
+ if (system.env.CFX_COMMAND === 'run' && reason === 'shutdown')
+ system.exit(0);
+ }
+};
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/app-extension/install.rdf b/tools/addon-sdk-1.7/python-lib/cuddlefish/app-extension/install.rdf
new file mode 100644
index 0000000..8bbcacb
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/app-extension/install.rdf
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+
+<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:em="http://www.mozilla.org/2004/em-rdf#">
+ <Description about="urn:mozilla:install-manifest">
+ <em:id>xulapp@toolness.com</em:id>
+ <em:version>1.0</em:version>
+ <em:type>2</em:type>
+ <em:bootstrap>true</em:bootstrap>
+ <em:unpack>false</em:unpack>
+
+ <!-- Firefox -->
+ <em:targetApplication>
+ <Description>
+ <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
+ <em:minVersion>12.0</em:minVersion>
+ <em:maxVersion>13.*</em:maxVersion>
+ </Description>
+ </em:targetApplication>
+
+ <!-- Front End MetaData -->
+ <em:name>Test App</em:name>
+ <em:description>Harness for tests.</em:description>
+ <em:creator>Mozilla Corporation</em:creator>
+ <em:homepageURL></em:homepageURL>
+ <em:optionsType></em:optionsType>
+ <em:updateURL></em:updateURL>
+ </Description>
+</RDF>
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/bunch.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/bunch.py
new file mode 100644
index 0000000..5efa79f
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/bunch.py
@@ -0,0 +1,34 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Taken from Paver's paver.options module.
+
+class Bunch(dict):
+ """A dictionary that provides attribute-style access."""
+
+ def __repr__(self):
+ keys = self.keys()
+ keys.sort()
+ args = ', '.join(['%s=%r' % (key, self[key]) for key in keys])
+ return '%s(%s)' % (self.__class__.__name__, args)
+
+ def __getitem__(self, key):
+ item = dict.__getitem__(self, key)
+ if callable(item):
+ return item()
+ return item
+
+ def __getattr__(self, name):
+ try:
+ return self[name]
+ except KeyError:
+ raise AttributeError(name)
+
+ __setattr__ = dict.__setitem__
+
+ def __delattr__(self, name):
+ try:
+ del self[name]
+ except KeyError:
+ raise AttributeError(name)
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/docs/__init__.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/docs/__init__.py
new file mode 100644
index 0000000..5501cd4
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/docs/__init__.py
@@ -0,0 +1,4 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/docs/apiparser.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/docs/apiparser.py
new file mode 100644
index 0000000..b6ccf22
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/docs/apiparser.py
@@ -0,0 +1,392 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import sys, re, textwrap
+
+VERSION = 4
+
+class ParseError(Exception):
+ # args[1] is the line number that caused the problem
+ def __init__(self, why, lineno):
+ self.why = why
+ self.lineno = lineno
+ def __str__(self):
+ return ("ParseError: the JS API docs were unparseable on line %d: %s" %
+ (self.lineno, self.why))
+
+class Accumulator:
+ def __init__(self, holder, firstline):
+ self.holder = holder
+ self.firstline = firstline
+ self.otherlines = []
+ def addline(self, line):
+ self.otherlines.append(line)
+ def finish(self):
+ # take a list of strings like:
+ # "initial stuff" (this is in firstline)
+ # " more stuff" (this is in lines[0])
+ # " yet more stuff"
+ # " indented block"
+ # " indented block"
+ # " nonindented stuff" (lines[-1])
+ #
+ # calculate the indentation level by looking at all but the first
+ # line, and removing the whitespace they all have in common. Then
+ # join the results with newlines and return a single string.
+ pieces = []
+ if self.firstline:
+ pieces.append(self.firstline)
+ if self.otherlines:
+ pieces.append(textwrap.dedent("\n".join(self.otherlines)))
+ self.holder["description"] = "\n".join(pieces)
+
+
+class APIParser:
+ def parse(self, lines, lineno):
+ api = {"line_number": lineno + 1}
+# assign the name from the first line, of the form "<api name="API_NAME">"
+ title_line = lines[lineno].rstrip("\n")
+ api["name"] = self._parse_title_line(title_line, lineno + 1)
+ lineno += 1
+# finished with the first line, assigned the name
+ working_set = self._initialize_working_set()
+ props = []
+ currentPropHolder = api
+# fetch the next line, of the form "@tag [name] {datatype} description"
+# and parse it into tag, info, description
+ tag, info, firstline = self._parseTypeLine(lines[lineno], lineno + 1)
+ api["type"] = tag
+# if this API element is a property then datatype must be set
+ if tag == 'property':
+ api['datatype'] = info['datatype']
+ # info is ignored
+ currentAccumulator = Accumulator(api, firstline)
+ lineno += 1
+ while (lineno) < len(lines):
+ line = lines[lineno].rstrip("\n")
+ # accumulate any multiline descriptive text belonging to
+ # the preceding "@" section
+ if self._is_description_line(line):
+ currentAccumulator.addline(line)
+ else:
+ currentAccumulator.finish()
+ if line.startswith("<api"):
+ # then we should recursively handle a nested element
+ nested_api, lineno = self.parse(lines, lineno)
+ self._update_working_set(nested_api, working_set)
+ elif line.startswith("</api"):
+ # then we have finished parsing this api element
+ currentAccumulator.finish()
+ if props and currentPropHolder:
+ currentPropHolder["props"] = props
+ self._assemble_api_element(api, working_set)
+ return api, lineno
+ else:
+ # then we are looking at a subcomponent of an <api> element
+ tag, info, desc = self._parseTypeLine(line, lineno + 1)
+ currentAccumulator = Accumulator(info, desc)
+ if tag == "prop":
+ # build up props[]
+ props.append(info)
+ elif tag == "returns":
+ # close off the @prop list
+ if props and currentPropHolder:
+ currentPropHolder["props"] = props
+ props = []
+ api["returns"] = info
+ currentPropHolder = info
+ elif tag == "param":
+ # close off the @prop list
+ if props and currentPropHolder:
+ currentPropHolder["props"] = props
+ props = []
+ working_set["params"].append(info)
+ currentPropHolder = info
+ elif tag == "argument":
+ # close off the @prop list
+ if props and currentPropHolder:
+ currentPropHolder["props"] = props
+ props = []
+ working_set["arguments"].append(info)
+ currentPropHolder = info
+ else:
+ raise ParseError("unknown '@' section header %s in \
+ '%s'" % (tag, line), lineno + 1)
+ lineno += 1
+ raise ParseError("closing </api> tag not found for <api name=\"" +
+ api["name"] + "\">", lineno + 1)
+
+ def _parse_title_line(self, title_line, lineno):
+ if "name" not in title_line:
+ raise ParseError("Opening <api> tag must have a name attribute.",
+ lineno)
+ m = re.search("name=['\"]{0,1}([-\w\.]*?)['\"]", title_line)
+ if not m:
+ raise ParseError("No value for name attribute found in "
+ "opening <api> tag.", lineno)
+ return m.group(1)
+
+ def _is_description_line(self, line):
+ return not ( (line.lstrip().startswith("@")) or
+ (line.lstrip().startswith("<api")) or
+ (line.lstrip().startswith("</api")) )
+
+ def _initialize_working_set(self):
+ # working_set accumulates api elements
+ # that might belong to a parent api element
+ working_set = {}
+ working_set["constructors"] = []
+ working_set["methods"] = []
+ working_set["properties"] = []
+ working_set["params"] = []
+ working_set["events"] = []
+ working_set["arguments"] = []
+ return working_set
+
+ def _update_working_set(self, nested_api, working_set):
+ # add this api element to whichever list is appropriate
+ if nested_api["type"] == "constructor":
+ working_set["constructors"].append(nested_api)
+ if nested_api["type"] == "method":
+ working_set["methods"].append(nested_api)
+ if nested_api["type"] == "property":
+ working_set["properties"].append(nested_api)
+ if nested_api["type"] == "event":
+ working_set["events"].append(nested_api)
+
+ def _assemble_signature(self, api_element, params):
+ signature = api_element["name"] + "("
+ if len(params) > 0:
+ signature += params[0]["name"]
+ for param in params[1:]:
+ signature += ", " + param["name"]
+ signature += ")"
+ api_element["signature"] = signature
+
+ def _assemble_api_element(self, api_element, working_set):
+ # if any of this working set's lists are non-empty,
+ # add it to the current api element
+ if (api_element["type"] == "constructor") or \
+ (api_element["type"] == "function") or \
+ (api_element["type"] == "method"):
+ self._assemble_signature(api_element, working_set["params"])
+ if len(working_set["params"]) > 0:
+ api_element["params"] = working_set["params"]
+ if len(working_set["properties"]) > 0:
+ api_element["properties"] = working_set["properties"]
+ if len(working_set["constructors"]) > 0:
+ api_element["constructors"] = working_set["constructors"]
+ if len(working_set["methods"]) > 0:
+ api_element["methods"] = working_set["methods"]
+ if len(working_set["events"]) > 0:
+ api_element["events"] = working_set["events"]
+ if len(working_set["arguments"]) > 0:
+ api_element["arguments"] = working_set["arguments"]
+
+ def _validate_info(self, tag, info, line, lineno):
+ if tag == 'property':
+ if not 'datatype' in info:
+ raise ParseError("No type found for @property.", lineno)
+ elif tag == "param":
+ if info.get("required", False) and "default" in info:
+ raise ParseError(
+ "required parameters should not have defaults: '%s'"
+ % line, lineno)
+ elif tag == "prop":
+ if "datatype" not in info:
+ raise ParseError("@prop lines must include {type}: '%s'" %
+ line, lineno)
+ if "name" not in info:
+ raise ParseError("@prop lines must provide a name: '%s'" %
+ line, lineno)
+
+ def _parseTypeLine(self, line, lineno):
+ # handle these things:
+ # @method
+ # @returns description
+ # @returns {string} description
+ # @param NAME {type} description
+ # @param NAME
+ # @prop NAME {type} description
+ # @prop NAME
+ # returns:
+ # tag: type of api element
+ # info: linenumber, required, default, name, datatype
+ # description
+
+ info = {"line_number": lineno}
+ line = line.rstrip("\n")
+ pieces = line.split()
+
+ if not pieces:
+ raise ParseError("line is too short: '%s'" % line, lineno)
+ if not pieces[0].startswith("@"):
+ raise ParseError("type line should start with @: '%s'" % line,
+ lineno)
+ tag = pieces[0][1:]
+ skip = 1
+
+ expect_name = tag in ("param", "prop")
+
+ if len(pieces) == 1:
+ description = ""
+ else:
+ if pieces[1].startswith("{"):
+ # NAME is missing, pieces[1] is TYPE
+ pass
+ else:
+ if expect_name:
+ info["required"] = not pieces[1].startswith("[")
+ name = pieces[1].strip("[ ]")
+ if "=" in name:
+ name, info["default"] = name.split("=")
+ info["name"] = name
+ skip += 1
+
+ if len(pieces) > skip and pieces[skip].startswith("{"):
+ info["datatype"] = pieces[skip].strip("{ }")
+ skip += 1
+
+ # we've got the metadata, now extract the description
+ pieces = line.split(None, skip)
+ if len(pieces) > skip:
+ description = pieces[skip]
+ else:
+ description = ""
+ self._validate_info(tag, info, line, lineno)
+ return tag, info, description
+
+def parse_hunks(text):
+ # return a list of tuples. Each is one of:
+ # ("raw", string) : non-API blocks
+ # ("api-json", dict) : API blocks
+ yield ("version", VERSION)
+ lines = text.splitlines(True)
+ line_number = 0
+ markdown_string = ""
+ while line_number < len(lines):
+ line = lines[line_number]
+ if line.startswith("<api"):
+ if len(markdown_string) > 0:
+ yield ("markdown", markdown_string)
+ markdown_string = ""
+ api, line_number = APIParser().parse(lines, line_number)
+ # this business with 'leftover' is a horrible thing to do,
+ # and exists only to collect the \n after the closing /api tag.
+ # It's not needed probably, except to help keep compatibility
+ # with the previous behaviour
+ leftover = lines[line_number].lstrip("</api>")
+ if len(leftover) > 0:
+ markdown_string += leftover
+ line_number = line_number + 1
+ yield ("api-json", api)
+ else:
+ markdown_string += line
+ line_number = line_number + 1
+ if len(markdown_string) > 0:
+ yield ("markdown", markdown_string)
+
+class TestRenderer:
+ # render docs for test purposes
+
+ def getm(self, d, key):
+ return d.get(key, "<MISSING>")
+
+ def join_lines(self, text):
+ return " ".join([line.strip() for line in text.split("\n")])
+
+ def render_prop(self, p):
+ s = "props[%s]: " % self.getm(p, "name")
+ pieces = []
+ for k in ("type", "description", "required", "default"):
+ if k in p:
+ pieces.append("%s=%s" % (k, self.join_lines(str(p[k]))))
+ return s + ", ".join(pieces)
+
+ def render_param(self, p):
+ pieces = []
+ for k in ("name", "type", "description", "required", "default"):
+ if k in p:
+ pieces.append("%s=%s" % (k, self.join_lines(str(p[k]))))
+ yield ", ".join(pieces)
+ for prop in p.get("props", []):
+ yield " " + self.render_prop(prop)
+
+ def render_method(self, method):
+ yield "name= %s" % self.getm(method, "name")
+ yield "type= %s" % self.getm(method, "type")
+ yield "description= %s" % self.getm(method, "description")
+ signature = method.get("signature")
+ if signature:
+ yield "signature= %s" % self.getm(method, "signature")
+ params = method.get("params", [])
+ if params:
+ yield "parameters:"
+ for p in params:
+ for pline in self.render_param(p):
+ yield " " + pline
+ r = method.get("returns", None)
+ if r:
+ yield "returns:"
+ if "type" in r:
+ yield " type= %s" % r["type"]
+ if "description" in r:
+ yield " description= %s" % self.join_lines(r["description"])
+ props = r.get("props", [])
+ for p in props:
+ yield " " + self.render_prop(p)
+
+ def format_api(self, api):
+ for mline in self.render_method(api):
+ yield mline
+ constructors = api.get("constructors", [])
+ if constructors:
+ yield "constructors:"
+ for m in constructors:
+ for mline in self.render_method(m):
+ yield " " + mline
+ methods = api.get("methods", [])
+ if methods:
+ yield "methods:"
+ for m in methods:
+ for mline in self.render_method(m):
+ yield " " + mline
+ properties = api.get("properties", [])
+ if properties:
+ yield "properties:"
+ for p in properties:
+ yield " " + self.render_prop(p)
+
+ def render_docs(self, docs_json, outf=sys.stdout):
+
+ for (t,data) in docs_json:
+ if t == "api-json":
+ for line in self.format_api(data):
+ line = line.rstrip("\n")
+ outf.write("API: " + line + "\n")
+ else:
+ for line in str(data).split("\n"):
+ outf.write("MD :" + line + "\n")
+
+def hunks_to_dict(docs_json):
+ exports = {}
+ for (t,data) in docs_json:
+ if t != "api-json":
+ continue
+ if data["name"]:
+ exports[data["name"]] = data
+ return exports
+
+if __name__ == "__main__":
+ json = False
+ if sys.argv[1] == "--json":
+ json = True
+ del sys.argv[1]
+ docs_text = open(sys.argv[1]).read()
+ docs_parsed = list(parse_hunks(docs_text))
+ if json:
+ import simplejson
+ print simplejson.dumps(docs_parsed, indent=2)
+ else:
+ TestRenderer().render_docs(docs_parsed)
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/docs/apirenderer.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/docs/apirenderer.py
new file mode 100644
index 0000000..36e46ef
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/docs/apirenderer.py
@@ -0,0 +1,302 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import sys, os
+import markdown
+import apiparser
+
+# list of all the 'class' and 'id' attributes assigned to
+# <div> and <span> tags by the renderer.
+API_REFERENCE = 'api_reference'
+MODULE_API_DOCS_CLASS = 'module_api_docs'
+MODULE_API_DOCS_ID = '_module_api_docs'
+API_HEADER = 'api_header'
+API_NAME = 'api_name'
+API_COMPONENT_GROUP = 'api_component_group'
+API_COMPONENT = 'api_component'
+DATATYPE = 'datatype'
+RETURNS = 'returns'
+PARAMETER_SET = 'parameter_set'
+MODULE_DESCRIPTION = 'module_description'
+
+HTML_HEADER = '''
+<!DOCTYPE html>\n
+<html>\n
+<head>\n
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8" />\n
+ <base target="_blank"/>\n
+ <link rel="stylesheet" type="text/css" media="all"\n
+ href="../../../css/base.css" />\n
+ <link rel="stylesheet" type="text/css" media="all"\n
+ href="../../../css/apidocs.css" />\n
+ <title>Add-on SDK Documentation</title>\n
+ <style type="text/css">\n
+ body {\n
+ border: 50px solid #FFFFFF;\n
+ }\n
+ </style>\n
+\n
+ <script type="text/javascript">\n
+ function rewrite_links() {\n
+ var images = document.getElementsByTagName("img");\n
+ for (var i = 0; i < images.length; i++) {\n
+ var before = images[i].src.split("packages/")[0];\n
+ var after = images[i].src.split("/docs")[1];\n
+ images[i].src = before + after;\n
+ }\n
+ }\n
+ </script>\n
+</head>\n
+\n
+<body onload = "rewrite_links()">\n'''
+
+HTML_FOOTER = '''
+</body>\n
+\n
+</html>\n'''
+
+def indent(text_in):
+ text_out = ''
+ lines = text_in.splitlines(True)
+ indentation_level = 0
+ indentation_depth = 2
+ for line in lines:
+ if (line.startswith('<div')):
+ text_out += ((' ' * indentation_depth) * indentation_level) + line
+ if not '</div>' in line:
+ indentation_level += 1
+ else:
+ if (line.startswith('</div>')):
+ indentation_level -= 1
+ text_out += ((' ' * indentation_depth) * indentation_level) + line
+ return text_out
+
+def tag_wrap_id(text, classname, id, tag = 'div'):
+ return ''.join(['\n<'+ tag + ' id="', id, '" class="', \
+ classname, '">\n', text + '\n</' + tag +'>\n'])
+
+def tag_wrap(text, classname, tag = 'div', inline = False):
+ if inline:
+ return ''.join(['\n<' + tag + ' class="', classname, '">', \
+ text, '</'+ tag + '>\n'])
+ else:
+ return ''.join(['\n<' + tag + ' class="', classname, '">', \
+ text, '\n</'+ tag + '>\n'])
+
+def tag_wrap_inline(text, classname, tag = 'div'):
+ return ''.join(['\n<' + tag + ' class="', classname, '">', \
+ text, '</'+ tag + '>\n'])
+
+def span_wrap(text, classname):
+ return ''.join(['<span class="', classname, '">', \
+ text, '</span>'])
+
+class API_Renderer(object):
+ def __init__(self, json, tag):
+ self.name = json.get('name', None)
+ self.tag = tag
+ self.description = json.get('description', '')
+ self.json = json
+
+ def render_name(self):
+ raise Exception('not implemented in this class')
+
+ def render_description(self):
+ return markdown.markdown(self.description)
+
+ def render_subcomponents(self):
+ raise Exception('not implemented in this class')
+
+ def get_tag(self):
+ return self.tag
+
+class Class_Doc(API_Renderer):
+ def __init__(self, json, tag):
+ API_Renderer.__init__(self, json, tag)
+
+ def render_name(self):
+ return self.name
+
+ def render_subcomponents(self):
+ return render_object_contents(self.json, 'h5', 'h6')
+
+class Event_Doc(API_Renderer):
+ def __init__(self, json, tag):
+ API_Renderer.__init__(self, json, tag)
+ self.arguments_json = json.get('arguments', None)
+
+ def render_name(self):
+ return self.name
+
+ def render_subcomponents(self):
+ if not self.arguments_json:
+ return ''
+ text = ''.join([render_comp(Argument_Doc(argument_json, 'div')) \
+ for argument_json in self.arguments_json])
+ return tag_wrap(text, PARAMETER_SET)
+
+class Argument_Doc(API_Renderer):
+ def __init__(self, json, tag):
+ API_Renderer.__init__(self, json, tag)
+ self.datatype = json.get('datatype', None)
+
+ def render_name(self):
+ return span_wrap(self.datatype, DATATYPE)
+
+ def render_subcomponents(self):
+ return ''
+
+class Function_Doc(API_Renderer):
+ def __init__(self, json, tag):
+ API_Renderer.__init__(self, json, tag)
+ self.signature = json['signature']
+ self.returns = json.get('returns', None)
+ self.parameters_json = json.get('params', None)
+
+ def render_name(self):
+ return self.signature
+
+ def render_subcomponents(self):
+ return self._render_parameters() + self._render_returns()
+
+ def _render_parameters(self):
+ if not self.parameters_json:
+ return ''
+ text = ''.join([render_comp(Parameter_Doc(parameter_json, 'div')) \
+ for parameter_json in self.parameters_json])
+ return tag_wrap(text, PARAMETER_SET)
+
+ def _render_returns(self):
+ if not self.returns:
+ return ''
+ text = 'Returns: ' + span_wrap(self.returns['datatype'], DATATYPE)
+ text += markdown.markdown(self.returns['description'])
+ return tag_wrap(text, RETURNS)
+
+class Property_Doc(API_Renderer):
+ def __init__(self, json, tag):
+ API_Renderer.__init__(self, json, tag)
+ self.datatype = json.get('datatype', None)
+ self.required = json.get('required', True)
+ self.default = json.get('default', False)
+
+ def render_name(self):
+ rendered = self.name
+ if self.default:
+ rendered = rendered + " = " + self.default
+ if self.datatype:
+ rendered = rendered + ' : ' + span_wrap(self.datatype, DATATYPE)
+ if not self.required:
+ rendered = '[ ' + rendered + ' ]'
+ return rendered
+
+ def render_subcomponents(self):
+ return render_object_contents(self.json)
+
+class Parameter_Doc(Property_Doc):
+ def __init__(self, json, tag):
+ Property_Doc.__init__(self, json, tag)
+ self.properties_json = json.get('props', None)
+
+ def render_subcomponents(self):
+ if not self.properties_json:
+ return ''
+ text = ''.join([render_comp(Property_Doc(property_json, 'div')) \
+ for property_json in self.properties_json])
+ return text
+
+def render_object_contents(json, tag = 'div', comp_tag = 'div'):
+ ctors = json.get('constructors', None)
+ text = render_comp_group(ctors, 'Constructors', Function_Doc, tag, comp_tag)
+ methods = json.get('methods', None)
+ text += render_comp_group(methods, 'Methods', Function_Doc, tag, comp_tag)
+ properties = json.get('properties', None)
+ text += render_comp_group(properties, 'Properties', Property_Doc, tag, comp_tag)
+ events = json.get('events', None)
+ text += render_comp_group(events, 'Events', Event_Doc, tag, comp_tag)
+ return text
+
+def render_comp(component):
+ # a component is wrapped inside a single div marked 'API_COMPONENT'
+ # containing:
+ # 1) the component name, marked 'API_NAME'
+ text = tag_wrap(component.render_name(), API_NAME, component.get_tag(), True)
+ # 2) the component description
+ text += component.render_description()
+ # 3) the component contents
+ text += component.render_subcomponents()
+ return tag_wrap(text, API_COMPONENT)
+
+def render_comp_group(group, group_name, ctor, tag = 'div', comp_tag = 'div'):
+ if not group:
+ return ''
+ # component group is a list of components in a single div called
+ # 'API_COMPONENT_GROUP' containing:
+ # 1) a title for the group marked with 'API_HEADER'
+ text = tag_wrap(group_name, API_HEADER, tag, True)
+ # 2) each component
+ text += ''.join([render_comp(ctor(api, comp_tag)) for api in group])
+ return tag_wrap(text, API_COMPONENT_GROUP)
+
+def render_descriptions(descriptions_md):
+ text = ''.join([description_md for description_md in descriptions_md])
+ return tag_wrap(markdown.markdown(text), MODULE_DESCRIPTION)
+
+def render_api_reference(api_docs):
+ if (len(api_docs) == 0):
+ return ''
+ # at the top level api reference is in a single div marked 'API_REFERENCE',
+ # containing:
+ # 1) a title 'API Reference' marked with 'API_HEADER'
+ text = tag_wrap('API Reference', API_HEADER, 'h2', True)
+ # 2) a component group called 'Classes' containing any class elements
+ classes = [api for api in api_docs if api['type'] == 'class']
+ text += render_comp_group(classes, 'Classes', Class_Doc, 'h3', 'h4')
+ # 3) a component group called 'Functions' containing any global functions
+ functions = [api for api in api_docs if api['type'] == 'function']
+ text += render_comp_group(functions, 'Functions', Function_Doc, 'h3', 'h4')
+ # 4) a component group called 'Properties' containing any global properties
+ properties = [api for api in api_docs if api['type'] == 'property']
+ text += render_comp_group(properties, 'Properties', Property_Doc, 'h3', 'h4')
+ # 5) a component group called 'Events' containing any global events
+ events = [api for api in api_docs if api['type'] == 'event']
+ text += render_comp_group(events, 'Events', Event_Doc, 'h3', 'h4')
+ return tag_wrap(text, API_REFERENCE)
+
+# take the JSON output of apiparser
+# return the HTML DIV containing the rendered component
+def json_to_div(json, markdown_filename):
+ module_name, ext = os.path.splitext(os.path.basename(markdown_filename))
+ descriptions = [hunk[1] for hunk in json if hunk[0]=='markdown']
+ api_docs = [hunk[1] for hunk in json if hunk[0]=='api-json']
+ text = "<h1>" + module_name + "</h1>"
+ text += render_descriptions(descriptions)
+ text += render_api_reference(api_docs)
+ text = tag_wrap_id(text, MODULE_API_DOCS_CLASS, \
+ module_name + MODULE_API_DOCS_ID)
+ return text.encode('utf8')
+
+# take the JSON output of apiparser
+# return standalone HTML containing the rendered component
+def json_to_html(json, markdown_filename):
+ return indent(HTML_HEADER + \
+ json_to_div(json, markdown_filename) + HTML_FOOTER)
+
+# take the name of a Markdown file
+# return the HTML DIV containing the rendered component
+def md_to_div(markdown_filename):
+ markdown_contents = open(markdown_filename).read().decode('utf8')
+ json = list(apiparser.parse_hunks(markdown_contents))
+ return json_to_div(json, markdown_filename)
+
+# take the name of a Markdown file
+# return standalone HTML containing the rendered component
+def md_to_html(markdown_filename):
+ return indent(HTML_HEADER + md_to_div(markdown_filename) + HTML_FOOTER)
+
+if __name__ == '__main__':
+ if (len(sys.argv) == 0):
+ print 'Supply the name of a docs file to parse'
+ else:
+ print md_to_html(sys.argv[1])
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/docs/generate.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/docs/generate.py
new file mode 100644
index 0000000..19ef109
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/docs/generate.py
@@ -0,0 +1,292 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import sys
+import shutil
+import hashlib
+import tarfile
+import StringIO
+import HTMLParser
+import urlparse
+
+from cuddlefish import packaging
+from cuddlefish.docs import apiparser
+from cuddlefish.docs import apirenderer
+from cuddlefish.docs import webdocs
+import simplejson as json
+
+DIGEST = "status.md5"
+TGZ_FILENAME = "addon-sdk-docs.tgz"
+
+def get_sdk_docs_path(env_root):
+ return os.path.join(env_root, "doc")
+
+def get_base_url(env_root):
+ sdk_docs_path = get_sdk_docs_path(env_root).lstrip("/")
+ return "file://"+"/"+"/".join(sdk_docs_path.split(os.sep))+"/"
+
+def clean_generated_docs(docs_dir):
+ status_file = os.path.join(docs_dir, "status.md5")
+ if os.path.exists(status_file):
+ os.remove(status_file)
+ index_file = os.path.join(docs_dir, "index.html")
+ if os.path.exists(index_file):
+ os.remove(index_file)
+ dev_guide_dir = os.path.join(docs_dir, "dev-guide")
+ if os.path.exists(dev_guide_dir):
+ shutil.rmtree(dev_guide_dir)
+ api_doc_dir = os.path.join(docs_dir, "packages")
+ if os.path.exists(api_doc_dir):
+ shutil.rmtree(api_doc_dir)
+
+def generate_static_docs(env_root):
+ clean_generated_docs(get_sdk_docs_path(env_root))
+ generate_docs(env_root, stdout=StringIO.StringIO())
+ tgz = tarfile.open(TGZ_FILENAME, 'w:gz')
+ tgz.add(get_sdk_docs_path(env_root), "doc")
+ tgz.close()
+ return TGZ_FILENAME
+
+def generate_local_docs(env_root):
+ return generate_docs(env_root, get_base_url(env_root))
+
+def generate_named_file(env_root, filename):
+ web_docs = webdocs.WebDocs(env_root, get_base_url(env_root))
+ # next, generate api doc or guide doc
+ abs_path = os.path.abspath(filename)
+ if abs_path.startswith(os.path.join(env_root, 'packages')):
+ doc_html, dest_dir, filename = generate_api_doc(env_root, abs_path, web_docs)
+ write_file(env_root, doc_html, dest_dir, filename)
+ elif abs_path.startswith(os.path.join(get_sdk_docs_path(env_root), 'dev-guide-source')):
+ doc_html, dest_dir, filename = generate_guide_doc(env_root, abs_path, web_docs)
+ write_file(env_root, doc_html, dest_dir, filename, False)
+ else:
+ raise ValueError("Not a valid path to a documentation file")
+
+def generate_docs(env_root, base_url=None, stdout=sys.stdout):
+ docs_dir = get_sdk_docs_path(env_root)
+ # if the generated docs don't exist, generate everything
+ if not os.path.exists(os.path.join(docs_dir, "dev-guide")):
+ print >>stdout, "Generating documentation..."
+ generate_docs_from_scratch(env_root, base_url)
+ current_status = calculate_current_status(env_root)
+ open(os.path.join(docs_dir, DIGEST), "w").write(current_status)
+ else:
+ current_status = calculate_current_status(env_root)
+ previous_status_file = os.path.join(docs_dir, DIGEST)
+ docs_are_up_to_date = False
+ if os.path.exists(previous_status_file):
+ docs_are_up_to_date = current_status == open(previous_status_file, "r").read()
+ # if the docs are not up to date, generate everything
+ if not docs_are_up_to_date:
+ print >>stdout, "Regenerating documentation..."
+ generate_docs_from_scratch(env_root, base_url)
+ open(os.path.join(docs_dir, DIGEST), "w").write(current_status)
+ return get_base_url(env_root) + "index.html"
+
+# this function builds a hash of the name and last modification date of:
+# * every file in "packages" which ends in ".md"
+# * every file in "static-files" which does not start with "."
+def calculate_current_status(env_root):
+ docs_dir = get_sdk_docs_path(env_root)
+ current_status = hashlib.md5()
+ package_src_dir = os.path.join(env_root, "packages")
+ for (dirpath, dirnames, filenames) in os.walk(package_src_dir):
+ for filename in filenames:
+ if filename.endswith(".md"):
+ current_status.update(filename)
+ current_status.update(str(os.path.getmtime(os.path.join(dirpath, filename))))
+ guide_src_dir = os.path.join(docs_dir, "dev-guide-source")
+ for (dirpath, dirnames, filenames) in os.walk(guide_src_dir):
+ for filename in filenames:
+ if filename.endswith(".md"):
+ current_status.update(filename)
+ current_status.update(str(os.path.getmtime(os.path.join(dirpath, filename))))
+ base_html_file = os.path.join(docs_dir, "static-files", "base.html")
+ current_status.update(base_html_file)
+ current_status.update(str(os.path.getmtime(os.path.join(dirpath, base_html_file))))
+ return current_status.digest()
+
+def generate_docs_from_scratch(env_root, base_url):
+ docs_dir = get_sdk_docs_path(env_root)
+ web_docs = webdocs.WebDocs(env_root, base_url)
+ must_rewrite_links = True
+ if base_url:
+ must_rewrite_links = False
+ clean_generated_docs(docs_dir)
+
+ # py2.5 doesn't have ignore=, so we delete tempfiles afterwards. If we
+ # required >=py2.6, we could use ignore=shutil.ignore_patterns("*~")
+ for (dirpath, dirnames, filenames) in os.walk(docs_dir):
+ for n in filenames:
+ if n.endswith("~"):
+ os.unlink(os.path.join(dirpath, n))
+
+ # generate api docs from all packages
+ os.mkdir(os.path.join(docs_dir, "packages"))
+ # create the index file and save that
+ pkg_cfg = packaging.build_pkg_cfg(env_root)
+ index = json.dumps(packaging.build_pkg_index(pkg_cfg))
+ index_path = os.path.join(docs_dir, "packages", 'index.json')
+ open(index_path, 'w').write(index)
+
+ # for each package, generate its docs
+ for pkg_name, pkg in pkg_cfg['packages'].items():
+ src_dir = pkg.root_dir
+ package_dirname = os.path.basename(src_dir)
+ dest_dir = os.path.join(docs_dir, "packages", package_dirname)
+ os.mkdir(dest_dir)
+
+ src_readme = os.path.join(src_dir, "README.md")
+ if os.path.exists(src_readme):
+ shutil.copyfile(src_readme,
+ os.path.join(dest_dir, "README.md"))
+
+ # create the package page
+ package_filename = os.path.join(dest_dir, "index.html")
+ if not os.path.exists(package_filename):
+ package_doc_html = web_docs.create_package_page(pkg_name)
+ replace_file(env_root, package_filename, package_doc_html, must_rewrite_links)
+
+ # generate all the API docs
+ docs_src_dir = os.path.join(src_dir, "doc")
+ if os.path.isdir(os.path.join(src_dir, "docs")):
+ docs_src_dir = os.path.join(src_dir, "docs")
+ generate_file_tree(env_root, docs_src_dir, web_docs, generate_api_doc, must_rewrite_links)
+
+ # generate all the guide docs
+ dev_guide_src = os.path.join(docs_dir, "dev-guide-source")
+ generate_file_tree(env_root, dev_guide_src, web_docs, generate_guide_doc, must_rewrite_links)
+
+ # make /md/dev-guide/welcome.html the top level index file
+ doc_html, dest_dir, filename = generate_guide_doc(env_root, os.path.join(docs_dir, 'dev-guide-source', 'index.md'), web_docs)
+ write_file(env_root, doc_html, docs_dir, 'index', False)
+
+def generate_file_tree(env_root, src_dir, web_docs, generate_file, must_rewrite_links):
+ for (dirpath, dirnames, filenames) in os.walk(src_dir):
+ assert dirpath.startswith(src_dir) # what is this for??
+ for filename in filenames:
+ if filename.endswith("~"):
+ continue
+ src_path = os.path.join(dirpath, filename)
+ if src_path.endswith(".md"):
+ # write the standalone HTML files
+ doc_html, dest_dir, filename = generate_file(env_root, src_path, web_docs)
+ write_file(env_root, doc_html, dest_dir, filename, must_rewrite_links)
+
+def generate_api_doc(env_root, src_dir, web_docs):
+ doc_html = web_docs.create_module_page(src_dir)
+ dest_dir, filename = get_api_doc_dest_path(env_root, src_dir)
+ return doc_html, dest_dir, filename
+
+def generate_guide_doc(env_root, src_dir, web_docs):
+ doc_html = web_docs.create_guide_page(src_dir)
+ dest_dir, filename = get_guide_doc_dest_path(env_root, src_dir)
+ return doc_html, dest_dir, filename
+
+def write_file(env_root, doc_html, dest_dir, filename, must_rewrite_links):
+ if not os.path.exists(dest_dir):
+ os.makedirs(dest_dir)
+ dest_path_html = os.path.join(dest_dir, filename) + ".html"
+ replace_file(env_root, dest_path_html, doc_html, must_rewrite_links)
+ return dest_path_html
+
+def replace_file(env_root, dest_path, file_contents, must_rewrite_links):
+ if os.path.exists(dest_path):
+ os.remove(dest_path)
+ # before we copy the final version, we'll rewrite the links
+ # I'll do this last, just because we know definitely what the dest_path is at this point
+ if must_rewrite_links and dest_path.endswith(".html"):
+ file_contents = rewrite_links(env_root, file_contents, dest_path)
+ open(dest_path, "w").write(file_contents)
+
+def rewrite_links(env_root, page, dest_path):
+ dest_path_depth = len(dest_path.split(os.sep)) -1 # because dest_path includes filename
+ docs_root_depth = len(get_sdk_docs_path(env_root).split(os.sep))
+ relative_depth = dest_path_depth - docs_root_depth
+ linkRewriter = LinkRewriter("../" * relative_depth)
+ return linkRewriter.rewrite_links(page)
+
+# Given the full path to an API source file, and the root,
+# return a tuple of:
+# 1) the full path to the corresponding HTML file, without the filename
+# 2) the filename without the extension
+def get_guide_doc_dest_path(env_root, src_dir):
+ src_dir_relative = src_dir[len(os.path.join(get_sdk_docs_path(env_root), "dev-guide-source")) + 1:]
+ return os.path.split(os.path.join(get_sdk_docs_path(env_root), "dev-guide", src_dir_relative)[:-3])
+
+# Given the full path to a dev guide source file, and the root,
+# return a tuple of:
+# 1) the full path to the corresponding HTML file, without the filename
+# 2) the filename without the extension
+def get_api_doc_dest_path(env_root, src_dir):
+ src_dir_relative = src_dir[len(env_root) + 1:]
+ src_dir_relative_pieces = src_dir_relative.split(os.sep)
+ del src_dir_relative_pieces[2]
+ src_dir_relative = os.sep.join(src_dir_relative_pieces)
+ return os.path.split(os.path.join(get_sdk_docs_path(env_root), src_dir_relative)[:-3])
+
+class LinkRewriter(HTMLParser.HTMLParser):
+ def __init__(self, link_prefix):
+ HTMLParser.HTMLParser.__init__(self)
+ self.stack = []
+ self.link_prefix = link_prefix
+
+ def rewrite_links(self, page):
+ self.feed(page)
+ self.close()
+ page = ''.join(self.stack)
+ self.stack = []
+ return page
+
+ def handle_decl(self, decl):
+ self.stack.append("<!" + decl + ">")
+
+ def handle_comment(self, decl):
+ self.stack.append("<!--" + decl + "-->")
+
+ def handle_starttag(self, tag, attrs):
+ self.stack.append(self.__html_start_tag(tag, self._rewrite_link(attrs)))
+
+ def handle_entityref(self, name):
+ self.stack.append("&" + name + ";")
+
+ def handle_endtag(self, tag):
+ self.stack.append(self.__html_end_tag(tag))
+
+ def handle_startendtag(self, tag, attrs):
+ self.stack.append(self.__html_startend_tag(tag, self._rewrite_link(attrs)))
+
+ def _rewrite_link(self, attrs):
+ attrs = dict(attrs)
+ href = attrs.get('href', '')
+ if href:
+ parsed = urlparse.urlparse(href)
+ if not parsed.scheme:
+ attrs['href'] = self.link_prefix + href
+ src = attrs.get('src', '')
+ if src:
+ parsed = urlparse.urlparse(src)
+ if not parsed.scheme:
+ attrs['src'] = self.link_prefix + src
+ return attrs
+
+ def handle_data(self, data):
+ self.stack.append(data)
+
+ def __html_start_tag(self, tag, attrs):
+ return '<%s%s>' % (tag, self.__html_attrs(attrs))
+
+ def __html_startend_tag(self, tag, attrs):
+ return '<%s%s/>' % (tag, self.__html_attrs(attrs))
+
+ def __html_end_tag(self, tag):
+ return '</%s>' % (tag)
+
+ def __html_attrs(self, attrs):
+ _attrs = ''
+ if attrs:
+ _attrs = ' %s' % (' '.join([('%s="%s"' % (k,v)) for k,v in dict(attrs).iteritems()]))
+ return _attrs
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/docs/renderapi.readme.md b/tools/addon-sdk-1.7/python-lib/cuddlefish/docs/renderapi.readme.md
new file mode 100644
index 0000000..627c2a6
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/docs/renderapi.readme.md
@@ -0,0 +1,210 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+
+This document describes the structure of the HTML generated by the renderapi.py
+tool, both for use in the API docs shown by "cfx docs" and as exported by
+"cfx sdocs". The particular HTML id and class attributes embedded in the files,
+as well as their organization, represent the interface between the tool and any
+front-end code wanting to style the docs in some particular way.
+
+renderapi generates two sorts of files:
+
+- a file called "<module-name>.div": this is the contents of the parsed
+Markdown file rendered inside a well-defined DIV tag
+
+- a file called "<module-name>.html": this is the DIV from above inserted into
+a simple HTML template that references a sample CSS file which styles the
+contents of the DIV. This CSS file is the same as the one used by the SDK
+itself.
+
+DIV tags
+--------
+The following class and id attributes are used in the DIV:
+
+renderapi uses a number of class attributes and a single id attribute in the DIV:
+
+id attribute <module_name>"_module_api_docs"
+class attribute "api_reference"
+class attribute "module_api_docs"
+class attribute "api_header"
+class attribute "api_name"
+class attribute "api_component_group"
+class attribute "api_component"
+class attribute "datatype"
+class attribute "returns"
+class attribute "parameter_set"
+class attribute "module_description"
+
+DIV structure
+-------------
+The top level DIV is marked with the id attribute and the "module_api_docs" class
+attribute:
+
+ <div id='tabs_module_api_docs' class='module_api_docs'>
+ //module doc contents
+ </div>
+
+
+Inside this:
+
+- the first item is an <h1> heading containing the name of the module:
+
+- all "markdown" hunks (that is, all descriptive text not occurring
+inside <api></api> tags) are rendered inside a DIV marked with the
+"module-description" class attribute
+
+- all <api></api> content is rendered, enclosed in a single tag marked
+with the "api_reference" class attribute:
+
+ <div id='tabs_module_api_docs' class='module_api_docs'>
+ <div class='module_description'>
+ //descriptions
+ </div>
+ <div class='api_reference'>
+ //api reference
+ </div>
+ </div>
+
+If there is no <api></api> content, then the "api-reference" section is absent.
+
+### API Reference structure ###
+
+The first item in API reference is an <h2> heading title marked with the
+"api_header" attribute. This might have the text content "API Reference"
+(but you should not rely on that):
+
+ <div class='api_reference'>
+
+ <h2 class='api_header'>API Reference</h2>
+
+ //api contents
+
+ </div>
+
+After the title come one or more component groups.
+
+#### Component Group ####
+
+A component group is marked with the "api_component_group" attribute. The
+component group is a collection of some sort of component: for example, a group
+of classes, a group of functions, or a group of events.
+
+Each component group starts off with a header marked with the
+"api_header" attribute and is followed by one or more sections marked with the
+"api_component" attribute.
+At the top level (that is, when they are directly under the "API Reference"
+heading), the "api_header" items are <h3> headings, otherwise they are divs.
+
+ <div class='api_reference'>
+
+ <h2 class='api_header'>API Reference</h2>
+
+ <div class='api_component_group'>
+
+ <h3 class='api_header'>Classes</h3>
+
+ <div class='api_component'>
+ // the first class
+ </div>
+
+ <div class='api_component'>
+ // another class
+ </div>
+
+ </div>
+
+ <div class='api_component_group'>
+ //some different components
+
+ <h3 class='api_header'>Functions</h3>
+
+ <div class='api_component'>
+ the first function
+ </div>
+
+ <div class='api_component'>
+ another function
+ </div>
+
+ </div>
+
+ </div>
+
+#### Component ####
+
+API components represent actual objects in the API like classes, functions,
+properties and events.
+
+Each component starts with a section marked with the
+"api_name" tag, which includes the name of the component in the API: for
+example "postMessage(message)".
+
+Components at the top level (i.e., directly under h3 headings) are <h4>
+headings, otherwise they are divs.
+
+After the name, the component's contents are listed. Different sorts of
+components may have different sorts of contents: for example, a function might
+have parameters. If the component is composite then it may contain its own
+component group. For example, a class may contain methods and properties,
+which might be grouped together.
+
+ <div class='api_component'>
+
+ <h4 class='api_name'>Panel</h4>
+
+ <div class='api_component_group'>
+
+ <div class='api_header'>
+ Methods
+ </div>
+
+ <div class='api_component'>
+ show()
+ </div>
+
+ </div>
+
+ </div>
+
+Other attributes
+-----------------------------
+
+### Datatype ###
+All primitive data types, like "string" and "number", are marked with the
+"datatype" class attribute:
+
+ <div class="api_component">
+
+ <div class="api_name">
+ label : <span class="datatype">string</span>
+ </div>
+
+ <p>A required string description of the widget used for accessibility,
+ title bars, and error reporting.</p>
+
+ </div>
+
+### Returns ###
+
+Functions mark return values with the "returns" class attribute.
+
+ <div class="api_component">
+
+ <div class="api_name">
+ get()
+ </div>
+
+ Make a `GET` request.
+
+ <div class="returns">
+ Returns: <span class="datatype">Request</span>
+ </div>
+
+ </div>
+
+### Parameter_set ###
+
+Functions that take parameters mark them with the parameter_set class
+attribute.
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/docs/webdocs.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/docs/webdocs.py
new file mode 100644
index 0000000..dcecc78
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/docs/webdocs.py
@@ -0,0 +1,193 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os, re, errno
+import markdown
+import cgi
+
+from cuddlefish import packaging
+from cuddlefish.docs import apirenderer
+from cuddlefish._version import get_versions
+
+INDEX_PAGE = '/doc/static-files/base.html'
+BASE_URL_INSERTION_POINT = '<base '
+VERSION_INSERTION_POINT = '<div id="version">'
+THIRD_PARTY_PACKAGE_SUMMARIES = '<ul id="third-party-package-summaries">'
+HIGH_LEVEL_PACKAGE_SUMMARIES = '<ul id="high-level-package-summaries">'
+LOW_LEVEL_PACKAGE_SUMMARIES = '<ul id="low-level-package-summaries">'
+CONTENT_ID = '<div id="main-content">'
+TITLE_ID = '<title>'
+DEFAULT_TITLE = 'Add-on SDK Documentation'
+
+def get_documentation(package_name, modules_json, doc_path):
+ documented_modules = []
+ for root, dirs, files in os.walk(doc_path):
+ subdir_path = root.split(os.sep)[len(doc_path.split(os.sep)):]
+ for filename in files:
+ if filename.endswith(".md"):
+ modname = filename[:-len(".md")]
+ modpath = subdir_path + [modname]
+ documented_modules.append(modpath)
+ return documented_modules
+
+def tag_wrap(text, tag, attributes={}):
+ result = '\n<' + tag
+ for name in attributes.keys():
+ result += ' ' + name + '=' + '"' + attributes[name] + '"'
+ result +='>' + text + '</'+ tag + '>\n'
+ return result
+
+def is_third_party(package_json):
+ return (not is_high_level(package_json)) and \
+ (not(is_low_level(package_json)))
+
+def is_high_level(package_json):
+ return 'jetpack-high-level' in package_json.get('keywords', [])
+
+def is_low_level(package_json):
+ return 'jetpack-low-level' in package_json.get('keywords', [])
+
+def insert_after(target, insertion_point_id, text_to_insert):
+ insertion_point = target.find(insertion_point_id) + len(insertion_point_id)
+ return target[:insertion_point] + text_to_insert + target[insertion_point:]
+
+class WebDocs(object):
+ def __init__(self, root, base_url = None):
+ self.root = root
+ self.pkg_cfg = packaging.build_pkg_cfg(root)
+ self.packages_json = packaging.build_pkg_index(self.pkg_cfg)
+ self.base_page = self._create_base_page(root, base_url)
+
+ def create_guide_page(self, path):
+ path, ext = os.path.splitext(path)
+ md_path = path + '.md'
+ md_content = unicode(open(md_path, 'r').read(), 'utf8')
+ guide_content = markdown.markdown(md_content)
+ return self._create_page(guide_content)
+
+ def create_module_page(self, path):
+ path, ext = os.path.splitext(path)
+ md_path = path + '.md'
+ module_content = apirenderer.md_to_div(md_path)
+ return self._create_page(module_content)
+
+ def create_package_page(self, package_name):
+ package_content = self._create_package_detail(package_name)
+ return self._create_page(package_content)
+
+ def _create_page(self, page_content):
+ page = self._insert_title(self.base_page, page_content)
+ page = insert_after(page, CONTENT_ID, page_content)
+ return page.encode('utf8')
+
+ def _create_module_list(self, package_json):
+ package_name = package_json['name']
+ libs = package_json['files'][1]['lib'][1]
+ doc_path = package_json.get('doc', None)
+ if not doc_path:
+ return ''
+ modules = get_documentation(package_name, libs, doc_path)
+ modules.sort()
+ module_items = ''
+ relative_doc_path = doc_path[len(self.root) + 1:]
+ relative_doc_path_pieces = relative_doc_path.split(os.sep)
+ del relative_doc_path_pieces[-1]
+ relative_doc_URL = "/".join(relative_doc_path_pieces)
+ for module in modules:
+ module_link = tag_wrap('/'.join(module), 'a', \
+ {'href': relative_doc_URL + '/' + '/'.join(module) + '.html'})
+ module_items += module_link
+ return module_items
+
+ def _create_package_summaries(self, packages_json, include):
+ packages = ''
+ for package_name in packages_json.keys():
+ package_json = packages_json[package_name]
+ if not include(package_json):
+ continue
+ package_path = self.pkg_cfg["packages"][package_name]["root_dir"]
+ package_directory = package_path[len(self.root) + 1:]
+ package_directory = "/".join(package_directory.split(os.sep))
+ package_link = tag_wrap(package_name, 'a', {'href': \
+ package_directory + "/" \
+ + 'index.html'})
+ text = tag_wrap(package_link, 'h4')
+ text += self._create_module_list(package_json)
+ packages += tag_wrap(text, 'li', {'class':'package-summary', \
+ 'style':'display: block;'})
+ return packages
+
+ def _create_base_page(self, root, base_url):
+ base_page = unicode(open(root + INDEX_PAGE, 'r').read(), 'utf8')
+ if base_url:
+ base_tag = 'href="' + base_url + '"'
+ base_page = insert_after(base_page, BASE_URL_INSERTION_POINT, base_tag)
+ sdk_version = get_versions()["version"]
+ base_page = insert_after(base_page, VERSION_INSERTION_POINT, "Version " + sdk_version)
+ third_party_summaries = \
+ self._create_package_summaries(self.packages_json, is_third_party)
+ base_page = insert_after(base_page, \
+ THIRD_PARTY_PACKAGE_SUMMARIES, third_party_summaries)
+ high_level_summaries = \
+ self._create_package_summaries(self.packages_json, is_high_level)
+ base_page = insert_after(base_page, \
+ HIGH_LEVEL_PACKAGE_SUMMARIES, high_level_summaries)
+ low_level_summaries = \
+ self._create_package_summaries(self.packages_json, is_low_level)
+ base_page = insert_after(base_page, \
+ LOW_LEVEL_PACKAGE_SUMMARIES, low_level_summaries)
+ return base_page
+
+ def _create_package_detail_row(self, field_value, \
+ field_descriptor, field_name):
+ meta = tag_wrap(tag_wrap(field_descriptor, 'span', \
+ {'class':'meta-header'}), 'td')
+ value = tag_wrap(tag_wrap(field_value, 'span', \
+ {'class':field_name}), 'td')
+ return tag_wrap(meta + value, 'tr')
+
+ def _create_package_detail_table(self, package_json):
+ table_contents = ''
+ if package_json.get('author', None):
+ table_contents += self._create_package_detail_row(\
+ cgi.escape(package_json['author']), 'Author', 'author')
+ if package_json.get('version', None):
+ table_contents += self._create_package_detail_row(\
+ package_json['version'], 'Version', 'version')
+ if package_json.get('license', None):
+ table_contents += self._create_package_detail_row(\
+ package_json['license'], 'License', 'license')
+ if package_json.get('dependencies', None):
+ table_contents += self._create_package_detail_row(\
+ ', '.join(package_json['dependencies']), \
+ 'Dependencies', 'dependencies')
+ table_contents += self._create_package_detail_row(\
+ self._create_module_list(package_json), 'Modules', 'modules')
+ return tag_wrap(tag_wrap(table_contents, 'tbody'), 'table', \
+ {'class':'meta-table'})
+
+ def _create_package_detail(self, package_name):
+ package_json = self.packages_json.get(package_name, None)
+ if not package_json:
+ raise IOError(errno.ENOENT, 'Package not found')
+ # pieces of the package detail: 1) title, 2) table, 3) description
+ package_title = tag_wrap(package_name, 'h1')
+ table = self._create_package_detail_table(package_json)
+ description = ''
+ if package_json.get('readme', None):
+ description += tag_wrap(tag_wrap(\
+ markdown.markdown(\
+ package_json['readme']), 'p'), 'div', {'class':'docs'})
+ return tag_wrap(package_title + table + description, 'div', \
+ {'class':'package-detail'})
+
+ def _insert_title(self, target, content):
+ match = re.search('<h1>.*</h1>', content)
+ if match:
+ title = match.group(0)[len('<h1>'):-len('</h1>')] + ' - ' + \
+ DEFAULT_TITLE
+ else:
+ title = DEFAULT_TITLE
+ target = insert_after(target, TITLE_ID, title)
+ return target
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/manifest.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/manifest.py
new file mode 100644
index 0000000..abe37d3
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/manifest.py
@@ -0,0 +1,751 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+import os, sys, re, hashlib
+import simplejson as json
+SEP = os.path.sep
+from cuddlefish.util import filter_filenames, filter_dirnames
+
+def js_zipname(packagename, modulename):
+ return "%s-lib/%s.js" % (packagename, modulename)
+def docs_zipname(packagename, modulename):
+ return "%s-docs/%s.md" % (packagename, modulename)
+def datamap_zipname(packagename):
+ return "%s-data.json" % packagename
+def datafile_zipname(packagename, datapath):
+ return "%s-data/%s" % (packagename, datapath)
+
+def to_json(o):
+ return json.dumps(o, indent=1).encode("utf-8")+"\n"
+
+class ModuleNotFoundError(Exception):
+ def __init__(self, requirement_type, requirement_name,
+ used_by, line_number, looked_in):
+ Exception.__init__(self)
+ self.requirement_type = requirement_type # "require" or "define"
+ self.requirement_name = requirement_name # string, what they require()d
+ self.used_by = used_by # string, full path to module which did require()
+ self.line_number = line_number # int, 1-indexed line number of first require()
+ self.looked_in = looked_in # list of full paths to potential .js files
+ def __str__(self):
+ what = "%s(%s)" % (self.requirement_type, self.requirement_name)
+ where = self.used_by
+ if self.line_number is not None:
+ where = "%s:%d" % (self.used_by, self.line_number)
+ searched = "Looked for it in:\n %s\n" % "\n ".join(self.looked_in)
+ return ("ModuleNotFoundError: unable to satisfy: %s from\n"
+ " %s:\n" % (what, where)) + searched
+
+class BadModuleIdentifier(Exception):
+ pass
+class BadSection(Exception):
+ pass
+class UnreachablePrefixError(Exception):
+ pass
+
+class ManifestEntry:
+ def __init__(self):
+ self.docs_filename = None
+ self.docs_hash = None
+ self.requirements = {}
+ self.datamap = None
+
+ def get_path(self):
+ path = "%s/%s/%s" % \
+ (self.packageName, self.sectionName, self.moduleName)
+ if not path.endswith(".js"):
+ path += ".js"
+ return path
+
+ def get_entry_for_manifest(self):
+ entry = { "packageName": self.packageName,
+ "sectionName": self.sectionName,
+ "moduleName": self.moduleName,
+ "jsSHA256": self.js_hash,
+ "docsSHA256": self.docs_hash,
+ "requirements": {},
+ }
+ for req in self.requirements:
+ if isinstance(self.requirements[req], ManifestEntry):
+ them = self.requirements[req] # this is another ManifestEntry
+ them_path = them.get_path()
+ entry["requirements"][req] = {"path": them_path}
+ else:
+ # something magic. The manifest entry indicates that they're
+ # allowed to require() it
+ entry["requirements"][req] = self.requirements[req]
+ assert isinstance(entry["requirements"][req], dict)
+ if self.datamap:
+ entry["requirements"]["self"] = {
+ "path": "self",
+ "mapSHA256": self.datamap.data_manifest_hash,
+ "mapName": self.packageName+"-data",
+ "dataURIPrefix": "%s/data/" % (self.packageName),
+ }
+ return entry
+
+ def add_js(self, js_filename):
+ self.js_filename = js_filename
+ self.js_hash = hash_file(js_filename)
+ def add_docs(self, docs_filename):
+ self.docs_filename = docs_filename
+ self.docs_hash = hash_file(docs_filename)
+ def add_requirement(self, reqname, reqdata):
+ self.requirements[reqname] = reqdata
+ def add_data(self, datamap):
+ self.datamap = datamap
+
+ def get_js_zipname(self):
+ return js_zipname(self.packagename, self.modulename)
+ def get_docs_zipname(self):
+ if self.docs_hash:
+ return docs_zipname(self.packagename, self.modulename)
+ return None
+ # self.js_filename
+ # self.docs_filename
+
+
+def hash_file(fn):
+ return hashlib.sha256(open(fn,"rb").read()).hexdigest()
+
+def get_datafiles(datadir):
+ # yields pathnames relative to DATADIR, ignoring some files
+ for dirpath, dirnames, filenames in os.walk(datadir):
+ filenames = list(filter_filenames(filenames))
+ # this tells os.walk to prune the search
+ dirnames[:] = filter_dirnames(dirnames)
+ for filename in filenames:
+ fullname = os.path.join(dirpath, filename)
+ assert fullname.startswith(datadir+SEP), "%s%s not in %s" % (datadir, SEP, fullname)
+ yield fullname[len(datadir+SEP):]
+
+
+class DataMap:
+ # one per package
+ def __init__(self, pkg):
+ self.pkg = pkg
+ self.name = pkg.name
+ self.files_to_copy = []
+ datamap = {}
+ datadir = os.path.join(pkg.root_dir, "data")
+ for dataname in get_datafiles(datadir):
+ absname = os.path.join(datadir, dataname)
+ zipname = datafile_zipname(pkg.name, dataname)
+ datamap[dataname] = hash_file(absname)
+ self.files_to_copy.append( (zipname, absname) )
+ self.data_manifest = to_json(datamap)
+ self.data_manifest_hash = hashlib.sha256(self.data_manifest).hexdigest()
+ self.data_manifest_zipname = datamap_zipname(pkg.name)
+ self.data_uri_prefix = "%s/data/" % (self.name)
+
+class BadChromeMarkerError(Exception):
+ pass
+
+class ModuleInfo:
+ def __init__(self, package, section, name, js, docs):
+ self.package = package
+ self.section = section
+ self.name = name
+ self.js = js
+ self.docs = docs
+
+ def __hash__(self):
+ return hash( (self.package.name, self.section, self.name,
+ self.js, self.docs) )
+ def __eq__(self, them):
+ if them.__class__ is not self.__class__:
+ return False
+ if ((them.package.name, them.section, them.name, them.js, them.docs) !=
+ (self.package.name, self.section, self.name, self.js, self.docs) ):
+ return False
+ return True
+
+ def __repr__(self):
+ return "ModuleInfo [%s %s %s] (%s, %s)" % (self.package.name,
+ self.section,
+ self.name,
+ self.js, self.docs)
+
+class ManifestBuilder:
+ def __init__(self, target_cfg, pkg_cfg, deps, extra_modules,
+ stderr=sys.stderr):
+ self.manifest = {} # maps (package,section,module) to ManifestEntry
+ self.target_cfg = target_cfg # the entry point
+ self.pkg_cfg = pkg_cfg # all known packages
+ self.deps = deps # list of package names to search
+ self.used_packagenames = set()
+ self.stderr = stderr
+ self.extra_modules = extra_modules
+ self.modules = {} # maps ModuleInfo to URI in self.manifest
+ self.datamaps = {} # maps package name to DataMap instance
+ self.files = [] # maps manifest index to (absfn,absfn) js/docs pair
+ self.test_modules = [] # for runtime
+
+ def build(self, scan_tests, test_filter_re):
+ # process the top module, which recurses to process everything it
+ # reaches
+ if "main" in self.target_cfg:
+ top_me = self.process_module(self.find_top(self.target_cfg))
+ self.top_path = top_me.get_path()
+ if scan_tests:
+ mi = self._find_module_in_package("test-harness", "lib", "run-tests", [])
+ self.process_module(mi)
+ # also scan all test files in all packages that we use. By making
+ # a copy of self.used_packagenames first, we refrain from
+ # processing tests in packages that our own tests depend upon. If
+ # we're running tests for package A, and either modules in A or
+ # tests in A depend upon modules from package B, we *don't* want
+ # to run tests for package B.
+ test_modules = []
+ dirnames = self.target_cfg["tests"]
+ if isinstance(dirnames, basestring):
+ dirnames = [dirnames]
+ dirnames = [os.path.join(self.target_cfg.root_dir, d)
+ for d in dirnames]
+ for d in dirnames:
+ for filename in os.listdir(d):
+ if filename.startswith("test-") and filename.endswith(".js"):
+ testname = filename[:-3] # require(testname)
+ if test_filter_re:
+ if not re.search(test_filter_re, testname):
+ continue
+ tmi = ModuleInfo(self.target_cfg, "tests", testname,
+ os.path.join(d, filename), None)
+ # scan the test's dependencies
+ tme = self.process_module(tmi)
+ test_modules.append( (testname, tme) )
+ # also add it as an artificial dependency of unit-test-finder, so
+ # the runtime dynamic load can work.
+ test_finder = self.get_manifest_entry("api-utils", "lib",
+ "unit-test-finder")
+ for (testname,tme) in test_modules:
+ test_finder.add_requirement(testname, tme)
+ # finally, tell the runtime about it, so they won't have to
+ # search for all tests. self.test_modules will be passed
+ # through the harness-options.json file in the
+ # .allTestModules property.
+ self.test_modules.append(testname)
+
+ # include files used by the loader
+ for em in self.extra_modules:
+ (pkgname, section, modname, js) = em
+ mi = ModuleInfo(self.pkg_cfg.packages[pkgname], section, modname,
+ js, None)
+ self.process_module(mi)
+
+
+ def get_module_entries(self):
+ return frozenset(self.manifest.values())
+ def get_data_entries(self):
+ return frozenset(self.datamaps.values())
+
+ def get_used_packages(self):
+ used = set()
+ for index in self.manifest:
+ (package, section, module) = index
+ used.add(package)
+ return sorted(used)
+
+ def get_used_files(self):
+ # returns all .js files that we reference, plus data/ files. You will
+ # need to add the loader, off-manifest files that it needs, and
+ # generated metadata.
+ for me in self.get_module_entries():
+ yield me.js_filename
+ if me.datamap:
+ for (zipname, absname) in me.datamap.files_to_copy:
+ yield absname
+
+ def get_all_test_modules(self):
+ return self.test_modules
+
+ def get_harness_options_manifest(self):
+ manifest = {}
+ for me in self.get_module_entries():
+ path = me.get_path()
+ manifest[path] = me.get_entry_for_manifest()
+ return manifest
+
+ def get_manifest_entry(self, package, section, module):
+ index = (package, section, module)
+ if index not in self.manifest:
+ m = self.manifest[index] = ManifestEntry()
+ m.packageName = package
+ m.sectionName = section
+ m.moduleName = module
+ self.used_packagenames.add(package)
+ return self.manifest[index]
+
+ def uri_name_from_path(self, pkg, fn):
+ # given a filename like .../pkg1/lib/bar/foo.js, and a package
+ # specification (with a .root_dir like ".../pkg1" and a .lib list of
+ # paths where .lib[0] is like "lib"), return the appropriate NAME
+ # that can be put into a URI like resource://JID-pkg1-lib/NAME . This
+ # will throw an exception if the file is outside of the lib/
+ # directory, since that means we can't construct a URI that points to
+ # it.
+ #
+ # This should be a lot easier, and shouldn't fail when the file is in
+ # the root of the package. Both should become possible when the XPI
+ # is rearranged and our URI scheme is simplified.
+ fn = os.path.abspath(fn)
+ pkglib = pkg.lib[0]
+ libdir = os.path.abspath(os.path.join(pkg.root_dir, pkglib))
+ # AARGH, section and name! we need to reverse-engineer a
+ # ModuleInfo instance that will produce a URI (in the form
+ # PREFIX/PKGNAME-SECTION/JS) that will map to the existing file.
+ # Until we fix URI generation to get rid of "sections", this is
+ # limited to files in the same .directories.lib as the rest of
+ # the package uses. So if the package's main files are in lib/,
+ # but the main.js is in the package root, there is no URI we can
+ # construct that will point to it, and we must fail.
+ #
+ # This will become much easier (and the failure case removed)
+ # when we get rid of sections and change the URIs to look like
+ # (PREFIX/PKGNAME/PATH-TO-JS).
+
+ # AARGH 2, allowing .lib to be a list is really getting in the
+ # way. That needs to go away eventually too.
+ if not fn.startswith(libdir):
+ raise UnreachablePrefixError("Sorry, but the 'main' file (%s) in package %s is outside that package's 'lib' directory (%s), so I cannot construct a URI to reach it."
+ % (fn, pkg.name, pkglib))
+ name = fn[len(libdir):].lstrip(SEP)[:-len(".js")]
+ return name
+
+
+ def parse_main(self, root_dir, main, check_lib_dir=None):
+ # 'main' can be like one of the following:
+ # a: ./lib/main.js b: ./lib/main c: lib/main
+ # we require it to be a path to the file, though, and ignore the
+ # .directories stuff. So just "main" is insufficient if you really
+ # want something in a "lib/" subdirectory.
+ if main.endswith(".js"):
+ main = main[:-len(".js")]
+ if main.startswith("./"):
+ main = main[len("./"):]
+ # package.json must always use "/", but on windows we'll replace that
+ # with "\" before using it as an actual filename
+ main = os.sep.join(main.split("/"))
+ paths = [os.path.join(root_dir, main+".js")]
+ if check_lib_dir is not None:
+ paths.append(os.path.join(root_dir, check_lib_dir, main+".js"))
+ return paths
+
+ def find_top_js(self, target_cfg):
+ for libdir in target_cfg.lib:
+ for n in self.parse_main(target_cfg.root_dir, target_cfg.main,
+ libdir):
+ if os.path.exists(n):
+ return n
+ raise KeyError("unable to find main module '%s.js' in top-level package" % target_cfg.main)
+
+ def find_top(self, target_cfg):
+ top_js = self.find_top_js(target_cfg)
+ n = os.path.join(target_cfg.root_dir, "README.md")
+ if os.path.exists(n):
+ top_docs = n
+ else:
+ top_docs = None
+ name = self.uri_name_from_path(target_cfg, top_js)
+ return ModuleInfo(target_cfg, "lib", name, top_js, top_docs)
+
+ def process_module(self, mi):
+ pkg = mi.package
+ #print "ENTERING", pkg.name, mi.name
+ # mi.name must be fully-qualified
+ assert (not mi.name.startswith("./") and
+ not mi.name.startswith("../"))
+ # create and claim the manifest row first
+ me = self.get_manifest_entry(pkg.name, mi.section, mi.name)
+
+ me.add_js(mi.js)
+ if mi.docs:
+ me.add_docs(mi.docs)
+
+ js_lines = open(mi.js,"r").readlines()
+ requires, problems, locations = scan_module(mi.js,js_lines,self.stderr)
+ if problems:
+ # the relevant instructions have already been written to stderr
+ raise BadChromeMarkerError()
+
+ # We update our requirements on the way out of the depth-first
+ # traversal of the module graph
+
+ for reqname in sorted(requires.keys()):
+ if reqname in ("chrome", "@packaging", "@loader"):
+ me.add_requirement(reqname, {"path": reqname})
+ elif reqname == "self":
+ # this might reference bundled data, so:
+ # 1: hash that data, add the hash as a dependency
+ # 2: arrange for the data to be copied into the XPI later
+ if pkg.name not in self.datamaps:
+ self.datamaps[pkg.name] = DataMap(pkg)
+ dm = self.datamaps[pkg.name]
+ me.add_data(dm) # 'self' is implicit
+ else:
+ # when two modules require() the same name, do they get a
+ # shared instance? This is a deep question. For now say yes.
+
+ # find_req_for() returns an entry to put in our
+ # 'requirements' dict, and will recursively process
+ # everything transitively required from here. It will also
+ # populate the self.modules[] cache. Note that we must
+ # tolerate cycles in the reference graph.
+ looked_in = [] # populated by subroutines
+ them_me = self.find_req_for(mi, reqname, looked_in)
+ if them_me is None:
+ if mi.section == "tests":
+ # tolerate missing modules in tests, because
+ # test-securable-module.js, and the modules/red.js
+ # that it imports, both do that intentionally
+ continue
+ lineno = locations.get(reqname) # None means define()
+ if lineno is None:
+ reqtype = "define"
+ else:
+ reqtype = "require"
+ err = ModuleNotFoundError(reqtype, reqname,
+ mi.js, lineno, looked_in)
+ raise err
+ else:
+ me.add_requirement(reqname, them_me)
+
+ return me
+ #print "LEAVING", pkg.name, mi.name
+
+ def find_req_for(self, from_module, reqname, looked_in):
+ # handle a single require(reqname) statement from from_module .
+ # Return a uri that exists in self.manifest
+ # Populate looked_in with places we looked.
+ def BAD(msg):
+ return BadModuleIdentifier(msg + " in require(%s) from %s" %
+ (reqname, from_module))
+
+ if not reqname:
+ raise BAD("no actual modulename")
+
+ # Allow things in tests/*.js to require both test code and real code.
+ # But things in lib/*.js can only require real code.
+ if from_module.section == "tests":
+ lookfor_sections = ["tests", "lib"]
+ elif from_module.section == "lib":
+ lookfor_sections = ["lib"]
+ else:
+ raise BadSection(from_module.section)
+ modulename = from_module.name
+
+ #print " %s require(%s))" % (from_module, reqname)
+ bits = reqname.split("/")
+
+ if reqname.startswith("./") or reqname.startswith("../"):
+ # 1: they want something relative to themselves, always from
+ # their own package
+ them = modulename.split("/")[:-1]
+ while bits[0] in (".", ".."):
+ if not bits:
+ raise BAD("no actual modulename")
+ if bits[0] == "..":
+ if not them:
+ raise BAD("too many ..")
+ them.pop()
+ bits.pop(0)
+ bits = them+bits
+ lookfor_pkg = from_module.package.name
+ lookfor_mod = "/".join(bits)
+ return self._get_module_from_package(lookfor_pkg,
+ lookfor_sections, lookfor_mod,
+ looked_in)
+
+ # non-relative import. Might be a short name (requiring a search
+ # through "library" packages), or a fully-qualified one.
+
+ if "/" in reqname:
+ # 2: PKG/MOD: find PKG, look inside for MOD
+ lookfor_pkg = bits[0]
+ lookfor_mod = "/".join(bits[1:])
+ mi = self._get_module_from_package(lookfor_pkg,
+ lookfor_sections, lookfor_mod,
+ looked_in)
+ if mi: # caution, 0==None
+ return mi
+ else:
+ # 3: try finding PKG, if found, use its main.js entry point
+ lookfor_pkg = reqname
+ mi = self._get_entrypoint_from_package(lookfor_pkg, looked_in)
+ if mi:
+ return mi
+
+ # 4: search packages for MOD or MODPARENT/MODCHILD. We always search
+ # their own package first, then the list of packages defined by their
+ # .dependencies list
+ from_pkg = from_module.package.name
+ return self._search_packages_for_module(from_pkg,
+ lookfor_sections, reqname,
+ looked_in)
+
+ def _handle_module(self, mi):
+ if not mi:
+ return None
+
+ # we tolerate cycles in the reference graph, which means we need to
+ # populate the self.modules cache before recursing into
+ # process_module() . We must also check the cache first, so recursion
+ # can terminate.
+ if mi in self.modules:
+ return self.modules[mi]
+
+ # this creates the entry
+ new_entry = self.get_manifest_entry(mi.package.name, mi.section, mi.name)
+ # and populates the cache
+ self.modules[mi] = new_entry
+ self.process_module(mi)
+ return new_entry
+
+ def _get_module_from_package(self, pkgname, sections, modname, looked_in):
+ if pkgname not in self.pkg_cfg.packages:
+ return None
+ mi = self._find_module_in_package(pkgname, sections, modname,
+ looked_in)
+ return self._handle_module(mi)
+
+ def _get_entrypoint_from_package(self, pkgname, looked_in):
+ if pkgname not in self.pkg_cfg.packages:
+ return None
+ pkg = self.pkg_cfg.packages[pkgname]
+ main = pkg.get("main", None)
+ if not main:
+ return None
+ for js in self.parse_main(pkg.root_dir, main):
+ looked_in.append(js)
+ if os.path.exists(js):
+ section = "lib"
+ name = self.uri_name_from_path(pkg, js)
+ docs = None
+ mi = ModuleInfo(pkg, section, name, js, docs)
+ return self._handle_module(mi)
+ return None
+
+ def _search_packages_for_module(self, from_pkg, sections, reqname,
+ looked_in):
+ searchpath = [] # list of package names
+ searchpath.append(from_pkg) # search self first
+ us = self.pkg_cfg.packages[from_pkg]
+ if 'dependencies' in us:
+ # only look in dependencies
+ searchpath.extend(us['dependencies'])
+ else:
+ # they didn't declare any dependencies (or they declared an empty
+ # list, but we'll treat that as not declaring one, because it's
+ # easier), so look in all deps, sorted alphabetically, so
+ # addon-kit comes first. Note that self.deps includes all
+ # packages found by traversing the ".dependencies" lists in each
+ # package.json, starting from the main addon package, plus
+ # everything added by --extra-packages
+ searchpath.extend(sorted(self.deps))
+ for pkgname in searchpath:
+ mi = self._find_module_in_package(pkgname, sections, reqname,
+ looked_in)
+ if mi:
+ return self._handle_module(mi)
+ return None
+
+ def _find_module_in_package(self, pkgname, sections, name, looked_in):
+ # require("a/b/c") should look at ...\a\b\c.js on windows
+ filename = os.sep.join(name.split("/"))
+ # normalize filename, make sure that we do not add .js if it already has
+ # it.
+ if not filename.endswith(".js"):
+ filename += ".js"
+ basename = filename[:-3]
+
+ pkg = self.pkg_cfg.packages[pkgname]
+ if isinstance(sections, basestring):
+ sections = [sections]
+ for section in sections:
+ for sdir in pkg.get(section, []):
+ js = os.path.join(pkg.root_dir, sdir, filename)
+ looked_in.append(js)
+ if os.path.exists(js):
+ docs = None
+ maybe_docs = os.path.join(pkg.root_dir, "docs",
+ basename+".md")
+ if section == "lib" and os.path.exists(maybe_docs):
+ docs = maybe_docs
+ return ModuleInfo(pkg, section, name, js, docs)
+ return None
+
+def build_manifest(target_cfg, pkg_cfg, deps, scan_tests,
+ test_filter_re=None, extra_modules=[]):
+ """
+ Perform recursive dependency analysis starting from entry_point,
+ building up a manifest of modules that need to be included in the XPI.
+ Each entry will map require() names to the URL of the module that will
+ be used to satisfy that dependency. The manifest will be used by the
+ runtime's require() code.
+
+ This returns a ManifestBuilder object, with two public methods. The
+ first, get_module_entries(), returns a set of ManifestEntry objects, each
+ of which can be asked for the following:
+
+ * its contribution to the harness-options.json '.manifest'
+ * the local disk name
+ * the name in the XPI at which it should be placed
+
+ The second is get_data_entries(), which returns a set of DataEntry
+ objects, each of which has:
+
+ * local disk name
+ * name in the XPI
+
+ note: we don't build the XPI here, but our manifest is passed to the
+ code which does, so it knows what to copy into the XPI.
+ """
+
+ mxt = ManifestBuilder(target_cfg, pkg_cfg, deps, extra_modules)
+ mxt.build(scan_tests, test_filter_re)
+ return mxt
+
+
+
+COMMENT_PREFIXES = ["//", "/*", "*", "dump("]
+
+REQUIRE_RE = r"(?<![\'\"])require\s*\(\s*[\'\"]([^\'\"]+?)[\'\"]\s*\)"
+#REQUIRE_RE = r"(?<!goog[.])(?<![\'\"])\brequire\s*\(\s*[\'\"]([^\'\"]+?)[\'\"]\s*\)"
+
+# detect the define idiom of the form:
+# define("module name", ["dep1", "dep2", "dep3"], function() {})
+# by capturing the contents of the list in a group.
+DEF_RE = re.compile(r"(require|define)\s*\(\s*([\'\"][^\'\"]+[\'\"]\s*,)?\s*\[([^\]]+)\]")
+
+# Out of the async dependencies, do not allow quotes in them.
+DEF_RE_ALLOWED = re.compile(r"^[\'\"][^\'\"]+[\'\"]$")
+
+def scan_requirements_with_grep(fn, lines):
+ requires = {}
+ first_location = {}
+ for (lineno0, line) in enumerate(lines):
+ for clause in line.split(";"):
+ clause = clause.strip()
+ iscomment = False
+ for commentprefix in COMMENT_PREFIXES:
+ if clause.startswith(commentprefix):
+ iscomment = True
+ if iscomment:
+ continue
+ mo = re.search(REQUIRE_RE, clause)
+ if mo:
+ modname = mo.group(1)
+ requires[modname] = {}
+ if modname not in first_location:
+ first_location[modname] = lineno0+1
+
+ # define() can happen across multiple lines, so join everyone up.
+ wholeshebang = "\n".join(lines)
+ for match in DEF_RE.finditer(wholeshebang):
+ # this should net us a list of string literals separated by commas
+ for strbit in match.group(3).split(","):
+ strbit = strbit.strip()
+ # There could be a trailing comma netting us just whitespace, so
+ # filter that out. Make sure that only string values with
+ # quotes around them are allowed, and no quotes are inside
+ # the quoted value.
+ if strbit and DEF_RE_ALLOWED.match(strbit):
+ modname = strbit[1:-1]
+ if modname not in ["exports"]:
+ requires[modname] = {}
+ # joining all the lines means we lose line numbers, so we
+ # can't fill first_location[]
+
+ return requires, first_location
+
+CHROME_ALIASES = [
+ (re.compile(r"Components\.classes"), "Cc"),
+ (re.compile(r"Components\.interfaces"), "Ci"),
+ (re.compile(r"Components\.utils"), "Cu"),
+ (re.compile(r"Components\.results"), "Cr"),
+ (re.compile(r"Components\.manager"), "Cm"),
+ ]
+OTHER_CHROME = re.compile(r"Components\.[a-zA-Z]")
+
+def scan_for_bad_chrome(fn, lines, stderr):
+ problems = False
+ old_chrome = set() # i.e. "Cc" when we see "Components.classes"
+ old_chrome_lines = [] # list of (lineno, line.strip()) tuples
+ for lineno,line in enumerate(lines):
+ # note: this scanner is not obligated to spot all possible forms of
+ # chrome access. The scanner is detecting voluntary requests for
+ # chrome. Runtime tools will enforce allowance or denial of access.
+ line = line.strip()
+ iscomment = False
+ for commentprefix in COMMENT_PREFIXES:
+ if line.startswith(commentprefix):
+ iscomment = True
+ break
+ if iscomment:
+ continue
+ old_chrome_in_this_line = set()
+ for (regexp,alias) in CHROME_ALIASES:
+ if regexp.search(line):
+ old_chrome_in_this_line.add(alias)
+ if not old_chrome_in_this_line:
+ if OTHER_CHROME.search(line):
+ old_chrome_in_this_line.add("components")
+ old_chrome.update(old_chrome_in_this_line)
+ if old_chrome_in_this_line:
+ old_chrome_lines.append( (lineno+1, line) )
+
+ if old_chrome:
+ print >>stderr, """
+The following lines from file %(fn)s:
+%(lines)s
+use 'Components' to access chrome authority. To do so, you need to add a
+line somewhat like the following:
+
+ const {%(needs)s} = require("chrome");
+
+Then you can use 'Components' as well as any shortcuts to its properties
+that you import from the 'chrome' module ('Cc', 'Ci', 'Cm', 'Cr', and
+'Cu' for the 'classes', 'interfaces', 'manager', 'results', and 'utils'
+properties, respectively).
+
+(Note: once bug 636145 is fixed, to access 'Components' directly you'll
+need to retrieve it from the 'chrome' module by adding it to the list of
+symbols you import from the module. To avoid having to make this change
+in the future, replace all occurrences of 'Components' in your code with
+the equivalent shortcuts now.)
+""" % { "fn": fn, "needs": ",".join(sorted(old_chrome)),
+ "lines": "\n".join([" %3d: %s" % (lineno,line)
+ for (lineno, line) in old_chrome_lines]),
+ }
+ problems = True
+ return problems
+
+def scan_module(fn, lines, stderr=sys.stderr):
+ filename = os.path.basename(fn)
+ requires, locations = scan_requirements_with_grep(fn, lines)
+ if filename == "cuddlefish.js":
+ # this is the loader: don't scan for chrome
+ problems = False
+ elif "chrome" in requires:
+ # if they declare require("chrome"), we tolerate the use of
+ # Components (see bug 663541 for rationale)
+ problems = False
+ else:
+ problems = scan_for_bad_chrome(fn, lines, stderr)
+ return requires, problems, locations
+
+
+
+if __name__ == '__main__':
+ for fn in sys.argv[1:]:
+ requires, problems, locations = scan_module(fn, open(fn).readlines())
+ print
+ print "---", fn
+ if problems:
+ print "PROBLEMS"
+ sys.exit(1)
+ print "requires: %s" % (",".join(sorted(requires.keys())))
+ print "locations: %s" % locations
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/mobile-utils/bootstrap.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/mobile-utils/bootstrap.js
new file mode 100644
index 0000000..7bf6d84
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/mobile-utils/bootstrap.js
@@ -0,0 +1,78 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cu = Components.utils;
+const Cr = Components.results;
+
+Components.utils.import("resource://gre/modules/Services.jsm");
+
+const DEBUG = false;
+
+let log = DEBUG ? dump : function (){};
+
+
+function startup(data, reason) {
+ // This code allow to make all stdIO work
+ try {
+ Components.utils.import("resource://gre/modules/ctypes.jsm");
+ let libdvm = ctypes.open("libdvm.so");
+ let dvmStdioConverterStartup = libdvm.declare("dvmStdioConverterStartup", ctypes.default_abi, ctypes.void_t);
+ dvmStdioConverterStartup();
+ log("MU: console redirected to adb logcat.\n");
+ } catch(e) {
+ Cu.reportError("MU: unable to execute jsctype hack: "+e);
+ }
+
+ // This code allow to kill firefox from adb
+ try {
+ let Watcher = {
+ window: null,
+ onOpenWindow: function(window) {
+ window = window.docShell.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);
+ window.addEventListener("keydown", this, true);
+ },
+ onCloseWindow: function (window) {},
+ onWindowTitleChange: function () {},
+ handleEvent: function(event) {
+ // This event is dispatched via: abd shell input keycode 19
+ // KEYCODE_DPAD_UP = 19, UP can't be fired by virtual keyboard,
+ // so it should be safe to take this event as a kill signal.
+ // `adb shell input` and `JS keyCode` values doesn't map to same values
+ // In JS, KeyUp maps to DOM_VK_UP = 38:
+ // https://developer.mozilla.org/en/DOM/KeyboardEvent
+ if (event.keyCode == 38 && event.which == 38) {
+ Cu.reportError("Mobile killer triggered!");
+ let appStartup = Cc['@mozilla.org/toolkit/app-startup;1'].
+ getService(Ci.nsIAppStartup);
+ appStartup.quit(Ci.nsIAppStartup.eForceQuit);
+ }
+ }
+ };
+ Services.wm.addListener(Watcher);
+ log("MU: key listener to close firefox set.\n");
+ }
+ catch(e) {
+ log("MU: Unable to register window watcher: " + e + "\n");
+ }
+
+ try {
+ let QuitObserver = {
+ observe: function (aSubject, aTopic, aData) {
+ Services.obs.removeObserver(QuitObserver, "quit-application", false);
+ dump("MU: APPLICATION-QUIT\n");
+ }
+ };
+ Services.obs.addObserver(QuitObserver, "quit-application", false);
+ log("MU: ready to watch firefox exit.\n");
+ } catch(e) {
+ log("MU: unable to register quit-application observer: " + e + "\n");
+ }
+}
+
+function install() {}
+function shutdown() {}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/mobile-utils/install.rdf b/tools/addon-sdk-1.7/python-lib/cuddlefish/mobile-utils/install.rdf
new file mode 100644
index 0000000..0b81a0e
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/mobile-utils/install.rdf
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+
+<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:em="http://www.mozilla.org/2004/em-rdf#">
+ <Description about="urn:mozilla:install-manifest">
+ <em:id>mobile-utils@mozilla.com</em:id>
+ <em:version>1.0</em:version>
+ <em:type>2</em:type>
+ <em:bootstrap>true</em:bootstrap>
+
+ <!-- Fennec-XUL -->
+ <em:targetApplication>
+ <Description>
+ <em:id>{a23983c0-fd0e-11dc-95ff-0800200c9a66}</em:id>
+ <em:minVersion>1</em:minVersion>
+ <em:maxVersion>*</em:maxVersion>
+ </Description>
+ </em:targetApplication>
+
+ <!-- Fennec-NativeUI -->
+ <em:targetApplication>
+ <Description>
+ <em:id>{aa3c5121-dab2-40e2-81ca-7ea25febc110}</em:id>
+ <em:minVersion>1</em:minVersion>
+ <em:maxVersion>*</em:maxVersion>
+ </Description>
+ </em:targetApplication>
+
+ <!-- Front End MetaData -->
+ <em:name>Mobile Addon-SDK utility addon</em:name>
+ <em:description>Allow better integration with cfx tool.</em:description>
+ <em:creator>Mozilla Corporation</em:creator>
+
+ </Description>
+</RDF>
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/options_defaults.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/options_defaults.py
new file mode 100644
index 0000000..5931a26
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/options_defaults.py
@@ -0,0 +1,26 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+def parse_options_defaults(options, jetpack_id):
+ # this returns a unicode string
+ pref_list = []
+
+ for pref in options:
+ if ('value' in pref):
+ value = pref["value"]
+
+ if isinstance(value, float):
+ continue
+ elif isinstance(value, bool):
+ value = str(pref["value"]).lower()
+ elif isinstance(value, str): # presumably ASCII
+ value = "\"" + unicode(pref["value"]) + "\""
+ elif isinstance(value, unicode):
+ value = "\"" + pref["value"] + "\""
+ else:
+ value = str(pref["value"])
+
+ pref_list.append("pref(\"extensions." + jetpack_id + "." + pref["name"] + "\", " + value + ");")
+
+ return "\n".join(pref_list) + "\n"
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/options_xul.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/options_xul.py
new file mode 100644
index 0000000..6f11311
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/options_xul.py
@@ -0,0 +1,64 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from xml.dom.minidom import Document
+
+VALID_PREF_TYPES = ['bool', 'boolint', 'integer', 'string', 'color', 'file',
+ 'directory', 'control']
+
+class Error(Exception):
+ pass
+
+class BadPrefTypeError(Error):
+ pass
+
+class MissingPrefAttr(Error):
+ pass
+
+def validate_prefs(options):
+ for pref in options:
+ # Make sure there is a 'title'
+ if ("title" not in pref):
+ raise MissingPrefAttr("The '%s' pref requires a 'title'" % (pref["name"]))
+
+ # Make sure that the pref type is a valid inline pref type
+ if (pref["type"] not in VALID_PREF_TYPES):
+ raise BadPrefTypeError('%s is not a valid inline pref type' % (pref["type"]))
+
+ # Make sure the 'control' type has a 'label'
+ if (pref["type"] == "control"):
+ if ("label" not in pref):
+ raise MissingPrefAttr("The 'control' inline pref type requires a 'label'")
+
+ # TODO: Check that pref["type"] matches default value type
+
+def parse_options(options, jetpack_id):
+ doc = Document()
+ root = doc.createElement("vbox")
+ root.setAttribute("xmlns", "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul")
+ doc.appendChild(root)
+
+ for pref in options:
+ setting = doc.createElement("setting")
+ setting.setAttribute("pref", "extensions." + jetpack_id + "." + pref["name"])
+ setting.setAttribute("type", pref["type"])
+ setting.setAttribute("title", pref["title"])
+
+ if ("description" in pref):
+ setting.appendChild(doc.createTextNode(pref["description"]))
+
+ if (pref["type"] == "control"):
+ button = doc.createElement("button")
+ button.setAttribute("label", pref["label"])
+ button.setAttribute("oncommand", "Services.obs.notifyObservers(null, '" +
+ jetpack_id + "-cmdPressed', '" +
+ pref["name"] + "');");
+ setting.appendChild(button)
+ elif (pref["type"] == "boolint"):
+ setting.setAttribute("on", pref["on"])
+ setting.setAttribute("off", pref["off"])
+
+ root.appendChild(setting)
+
+ return doc.toprettyxml(indent=" ")
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/packaging.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/packaging.py
new file mode 100644
index 0000000..757d5ac
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/packaging.py
@@ -0,0 +1,435 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import sys
+import re
+import copy
+
+import simplejson as json
+from cuddlefish.bunch import Bunch
+
+MANIFEST_NAME = 'package.json'
+
+DEFAULT_LOADER = 'api-utils'
+
+DEFAULT_PROGRAM_MODULE = 'main'
+
+DEFAULT_ICON = 'icon.png'
+DEFAULT_ICON64 = 'icon64.png'
+
+METADATA_PROPS = ['name', 'description', 'keywords', 'author', 'version',
+ 'contributors', 'license', 'homepage', 'icon', 'icon64',
+ 'main', 'directories']
+
+RESOURCE_HOSTNAME_RE = re.compile(r'^[a-z0-9_\-]+$')
+
+class Error(Exception):
+ pass
+
+class MalformedPackageError(Error):
+ pass
+
+class MalformedJsonFileError(Error):
+ pass
+
+class DuplicatePackageError(Error):
+ pass
+
+class PackageNotFoundError(Error):
+ def __init__(self, missing_package, reason):
+ self.missing_package = missing_package
+ self.reason = reason
+ def __str__(self):
+ return "%s (%s)" % (self.missing_package, self.reason)
+
+class BadChromeMarkerError(Error):
+ pass
+
+def validate_resource_hostname(name):
+ """
+ Validates the given hostname for a resource: URI.
+
+ For more information, see:
+
+ https://bugzilla.mozilla.org/show_bug.cgi?id=566812#c13
+
+ Examples:
+
+ >>> validate_resource_hostname('blarg')
+
+ >>> validate_resource_hostname('bl arg')
+ Traceback (most recent call last):
+ ...
+ ValueError: Error: the name of your package contains an invalid character.
+ Package names can contain only lower-case letters, numbers, underscores, and dashes.
+ Current package name: bl arg
+
+ >>> validate_resource_hostname('BLARG')
+ Traceback (most recent call last):
+ ...
+ ValueError: Error: the name of your package contains upper-case letters.
+ Package names can contain only lower-case letters, numbers, underscores, and dashes.
+ Current package name: BLARG
+
+ >>> validate_resource_hostname('foo@bar')
+ Traceback (most recent call last):
+ ...
+ ValueError: Error: the name of your package contains an invalid character.
+ Package names can contain only lower-case letters, numbers, underscores, and dashes.
+ Current package name: foo@bar
+ """
+
+ # See https://bugzilla.mozilla.org/show_bug.cgi?id=568131 for details.
+ if not name.islower():
+ raise ValueError("""Error: the name of your package contains upper-case letters.
+Package names can contain only lower-case letters, numbers, underscores, and dashes.
+Current package name: %s""" % name)
+
+ if not RESOURCE_HOSTNAME_RE.match(name):
+ raise ValueError("""Error: the name of your package contains an invalid character.
+Package names can contain only lower-case letters, numbers, underscores, and dashes.
+Current package name: %s""" % name)
+
+def find_packages_with_module(pkg_cfg, name):
+ # TODO: Make this support more than just top-level modules.
+ filename = "%s.js" % name
+ packages = []
+ for cfg in pkg_cfg.packages.itervalues():
+ if 'lib' in cfg:
+ matches = [dirname for dirname in resolve_dirs(cfg, cfg.lib)
+ if os.path.exists(os.path.join(dirname, filename))]
+ if matches:
+ packages.append(cfg.name)
+ return packages
+
+def resolve_dirs(pkg_cfg, dirnames):
+ for dirname in dirnames:
+ yield resolve_dir(pkg_cfg, dirname)
+
+def resolve_dir(pkg_cfg, dirname):
+ return os.path.join(pkg_cfg.root_dir, dirname)
+
+def get_metadata(pkg_cfg, deps):
+ metadata = Bunch()
+ for pkg_name in deps:
+ cfg = pkg_cfg.packages[pkg_name]
+ metadata[pkg_name] = Bunch()
+ for prop in METADATA_PROPS:
+ if cfg.get(prop):
+ metadata[pkg_name][prop] = cfg[prop]
+ return metadata
+
+def set_section_dir(base_json, name, base_path, dirnames, allow_root=False):
+ resolved = compute_section_dir(base_json, base_path, dirnames, allow_root)
+ if resolved:
+ base_json[name] = os.path.abspath(resolved)
+
+def compute_section_dir(base_json, base_path, dirnames, allow_root):
+ # PACKAGE_JSON.lib is highest priority
+ # then PACKAGE_JSON.directories.lib
+ # then lib/ (if it exists)
+ # then . (but only if allow_root=True)
+ for dirname in dirnames:
+ if base_json.get(dirname):
+ return os.path.join(base_path, base_json[dirname])
+ if "directories" in base_json:
+ for dirname in dirnames:
+ if dirname in base_json.directories:
+ return os.path.join(base_path, base_json.directories[dirname])
+ for dirname in dirnames:
+ if os.path.isdir(os.path.join(base_path, dirname)):
+ return os.path.join(base_path, dirname)
+ if allow_root:
+ return os.path.abspath(base_path)
+ return None
+
+def normalize_string_or_array(base_json, key):
+ if base_json.get(key):
+ if isinstance(base_json[key], basestring):
+ base_json[key] = [base_json[key]]
+
+def load_json_file(path):
+ data = open(path, 'r').read()
+ try:
+ return Bunch(json.loads(data))
+ except ValueError, e:
+ raise MalformedJsonFileError('%s when reading "%s"' % (str(e),
+ path))
+
+def get_config_in_dir(path):
+ package_json = os.path.join(path, MANIFEST_NAME)
+ if not (os.path.exists(package_json) and
+ os.path.isfile(package_json)):
+ raise MalformedPackageError('%s not found in "%s"' % (MANIFEST_NAME,
+ path))
+ base_json = load_json_file(package_json)
+
+ if 'name' not in base_json:
+ base_json.name = os.path.basename(path)
+
+ # later processing steps will expect to see the following keys in the
+ # base_json that we return:
+ #
+ # name: name of the package
+ # lib: list of directories with .js files
+ # test: list of directories with test-*.js files
+ # doc: list of directories with documentation .md files
+ # data: list of directories with bundled arbitrary data files
+ # packages: ?
+
+ if (not base_json.get('tests') and
+ os.path.isdir(os.path.join(path, 'test'))):
+ base_json['tests'] = 'test'
+
+ set_section_dir(base_json, 'lib', path, ['lib'], True)
+ set_section_dir(base_json, 'tests', path, ['test', 'tests'], False)
+ set_section_dir(base_json, 'doc', path, ['doc', 'docs'])
+ set_section_dir(base_json, 'data', path, ['data'])
+ set_section_dir(base_json, 'packages', path, ['packages'])
+ set_section_dir(base_json, 'locale', path, ['locale'])
+
+ if (not base_json.get('icon') and
+ os.path.isfile(os.path.join(path, DEFAULT_ICON))):
+ base_json['icon'] = DEFAULT_ICON
+
+ if (not base_json.get('icon64') and
+ os.path.isfile(os.path.join(path, DEFAULT_ICON64))):
+ base_json['icon64'] = DEFAULT_ICON64
+
+ for key in ['lib', 'tests', 'dependencies', 'packages']:
+ # TODO: lib/tests can be an array?? consider interaction with
+ # compute_section_dir above
+ normalize_string_or_array(base_json, key)
+
+ if 'main' not in base_json and 'lib' in base_json:
+ for dirname in base_json['lib']:
+ program = os.path.join(path, dirname,
+ '%s.js' % DEFAULT_PROGRAM_MODULE)
+ if os.path.exists(program):
+ base_json['main'] = DEFAULT_PROGRAM_MODULE
+ break
+
+ base_json.root_dir = path
+
+ return base_json
+
+def _is_same_file(a, b):
+ if hasattr(os.path, 'samefile'):
+ return os.path.samefile(a, b)
+ return a == b
+
+def build_config(root_dir, target_cfg, packagepath=[]):
+ dirs_to_scan = []
+
+ def add_packages_from_config(pkgconfig):
+ if 'packages' in pkgconfig:
+ for package_dir in resolve_dirs(pkgconfig, pkgconfig.packages):
+ dirs_to_scan.append(package_dir)
+
+ add_packages_from_config(target_cfg)
+
+ packages_dir = os.path.join(root_dir, 'packages')
+ if os.path.exists(packages_dir) and os.path.isdir(packages_dir):
+ dirs_to_scan.append(packages_dir)
+ dirs_to_scan.extend(packagepath)
+
+ packages = Bunch({target_cfg.name: target_cfg})
+
+ while dirs_to_scan:
+ packages_dir = dirs_to_scan.pop()
+ if os.path.exists(os.path.join(packages_dir, "package.json")):
+ package_paths = [packages_dir]
+ else:
+ package_paths = [os.path.join(packages_dir, dirname)
+ for dirname in os.listdir(packages_dir)
+ if not dirname.startswith('.')]
+ package_paths = [dirname for dirname in package_paths
+ if os.path.isdir(dirname)]
+
+ for path in package_paths:
+ pkgconfig = get_config_in_dir(path)
+ if pkgconfig.name in packages:
+ otherpkg = packages[pkgconfig.name]
+ if not _is_same_file(otherpkg.root_dir, path):
+ raise DuplicatePackageError(path, otherpkg.root_dir)
+ else:
+ packages[pkgconfig.name] = pkgconfig
+ add_packages_from_config(pkgconfig)
+
+ return Bunch(packages=packages)
+
+def get_deps_for_targets(pkg_cfg, targets):
+ visited = []
+ deps_left = [[dep, None] for dep in list(targets)]
+
+ while deps_left:
+ [dep, required_by] = deps_left.pop()
+ if dep not in visited:
+ visited.append(dep)
+ if dep not in pkg_cfg.packages:
+ required_reason = ("required by '%s'" % (required_by)) \
+ if required_by is not None \
+ else "specified as target"
+ raise PackageNotFoundError(dep, required_reason)
+ dep_cfg = pkg_cfg.packages[dep]
+ deps_left.extend([[i, dep] for i in dep_cfg.get('dependencies', [])])
+ deps_left.extend([[i, dep] for i in dep_cfg.get('extra_dependencies', [])])
+
+ return visited
+
+def generate_build_for_target(pkg_cfg, target, deps,
+ include_tests=True,
+ include_dep_tests=False,
+ default_loader=DEFAULT_LOADER):
+
+ build = Bunch(# Contains section directories for all packages:
+ packages=Bunch(),
+ locale=Bunch()
+ )
+
+ def add_section_to_build(cfg, section, is_code=False,
+ is_data=False):
+ if section in cfg:
+ dirnames = cfg[section]
+ if isinstance(dirnames, basestring):
+ # This is just for internal consistency within this
+ # function, it has nothing to do w/ a non-canonical
+ # configuration dict.
+ dirnames = [dirnames]
+ for dirname in resolve_dirs(cfg, dirnames):
+ # ensure that package name is valid
+ try:
+ validate_resource_hostname(cfg.name)
+ except ValueError, err:
+ print err
+ sys.exit(1)
+ # ensure that this package has an entry
+ if not cfg.name in build.packages:
+ build.packages[cfg.name] = Bunch()
+ # detect duplicated sections
+ if section in build.packages[cfg.name]:
+ raise KeyError("package's section already defined",
+ cfg.name, section)
+ # Register this section (lib, data, tests)
+ build.packages[cfg.name][section] = dirname
+
+ def add_locale_to_build(cfg):
+ path = resolve_dir(cfg, cfg['locale'])
+ files = os.listdir(path)
+ for filename in files:
+ fullpath = os.path.join(path, filename)
+ if os.path.isfile(fullpath) and filename.endswith('.properties'):
+ language = filename[:-len('.properties')]
+
+ from property_parser import parse_file, MalformedLocaleFileError
+ try:
+ content = parse_file(fullpath)
+ except MalformedLocaleFileError, msg:
+ print msg[0]
+ sys.exit(1)
+
+ # Merge current locales into global locale hashtable.
+ # Locale files only contains one big JSON object
+ # that act as an hastable of:
+ # "keys to translate" => "translated keys"
+ if language in build.locale:
+ merge = (build.locale[language].items() +
+ content.items())
+ build.locale[language] = Bunch(merge)
+ else:
+ build.locale[language] = content
+
+ def add_dep_to_build(dep):
+ dep_cfg = pkg_cfg.packages[dep]
+ add_section_to_build(dep_cfg, "lib", is_code=True)
+ add_section_to_build(dep_cfg, "data", is_data=True)
+ if include_tests and include_dep_tests:
+ add_section_to_build(dep_cfg, "tests", is_code=True)
+ if 'locale' in dep_cfg:
+ add_locale_to_build(dep_cfg)
+ if ("loader" in dep_cfg) and ("loader" not in build):
+ build.loader = "%s/%s" % (dep,
+ dep_cfg.loader)
+
+ target_cfg = pkg_cfg.packages[target]
+
+ if include_tests and not include_dep_tests:
+ add_section_to_build(target_cfg, "tests", is_code=True)
+
+ for dep in deps:
+ add_dep_to_build(dep)
+
+ if 'loader' not in build:
+ add_dep_to_build(DEFAULT_LOADER)
+
+ if 'icon' in target_cfg:
+ build['icon'] = os.path.join(target_cfg.root_dir, target_cfg.icon)
+ del target_cfg['icon']
+
+ if 'icon64' in target_cfg:
+ build['icon64'] = os.path.join(target_cfg.root_dir, target_cfg.icon64)
+ del target_cfg['icon64']
+
+ if ('preferences' in target_cfg):
+ build['preferences'] = target_cfg.preferences
+
+ return build
+
+def _get_files_in_dir(path):
+ data = {}
+ files = os.listdir(path)
+ for filename in files:
+ fullpath = os.path.join(path, filename)
+ if os.path.isdir(fullpath):
+ data[filename] = _get_files_in_dir(fullpath)
+ else:
+ try:
+ info = os.stat(fullpath)
+ data[filename] = ("file", dict(size=info.st_size))
+ except OSError:
+ pass
+ return ("directory", data)
+
+def build_pkg_index(pkg_cfg):
+ pkg_cfg = copy.deepcopy(pkg_cfg)
+ for pkg in pkg_cfg.packages:
+ root_dir = pkg_cfg.packages[pkg].root_dir
+ files = _get_files_in_dir(root_dir)
+ pkg_cfg.packages[pkg].files = files
+ try:
+ readme = open(root_dir + '/README.md').read()
+ pkg_cfg.packages[pkg].readme = readme
+ except IOError:
+ pass
+ del pkg_cfg.packages[pkg].root_dir
+ return pkg_cfg.packages
+
+def build_pkg_cfg(root):
+ pkg_cfg = build_config(root, Bunch(name='dummy'))
+ del pkg_cfg.packages['dummy']
+ return pkg_cfg
+
+def call_plugins(pkg_cfg, deps):
+ for dep in deps:
+ dep_cfg = pkg_cfg.packages[dep]
+ dirnames = dep_cfg.get('python-lib', [])
+ for dirname in resolve_dirs(dep_cfg, dirnames):
+ sys.path.append(dirname)
+ module_names = dep_cfg.get('python-plugins', [])
+ for module_name in module_names:
+ module = __import__(module_name)
+ module.init(root_dir=dep_cfg.root_dir)
+
+def call_cmdline_tool(env_root, pkg_name):
+ pkg_cfg = build_config(env_root, Bunch(name='dummy'))
+ if pkg_name not in pkg_cfg.packages:
+ print "This tool requires the '%s' package." % pkg_name
+ sys.exit(1)
+ cfg = pkg_cfg.packages[pkg_name]
+ for dirname in resolve_dirs(cfg, cfg['python-lib']):
+ sys.path.append(dirname)
+ module_name = cfg.get('python-cmdline-tool')
+ module = __import__(module_name)
+ module.run()
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/preflight.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/preflight.py
new file mode 100755
index 0000000..8b500ec
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/preflight.py
@@ -0,0 +1,77 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os, sys
+import base64
+import simplejson as json
+
+def create_jid():
+ """Return 'jid1-XYZ', where 'XYZ' is a randomly-generated string. (in the
+ previous jid0- series, the string securely identified a specific public
+ key). To get a suitable add-on ID, append '@jetpack' to this string.
+ """
+ # per https://developer.mozilla.org/en/Install_Manifests#id all XPI id
+ # values must either be in the form of a 128-bit GUID (crazy braces
+ # and all) or in the form of an email address (crazy @ and all).
+ # Firefox will refuse to install an add-on with an id that doesn't
+ # match one of these forms. The actual regexp is at:
+ # http://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/extensions/XPIProvider.jsm#130
+ # So the JID needs an @-suffix, and the only legal punctuation is
+ # "-._". So we start with a base64 encoding, and replace the
+ # punctuation (+/) with letters (AB), losing a few bits of integrity.
+
+ # even better: windows has a maximum path length limitation of 256
+ # characters:
+ # http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx
+ # (unless all paths are prefixed with "\\?\", I kid you not). The
+ # typical install will put add-on code in a directory like:
+ # C:\Documents and Settings\<username>\Application Data\Mozilla\Firefox\Profiles\232353483.default\extensions\$JID\...
+ # (which is 108 chars long without the $JID).
+ # Then the unpacked XPI contains packaged resources like:
+ # resources/$JID-api-utils-lib/main.js (35 chars plus the $JID)
+ #
+ # We create a random 80 bit string, base64 encode that (with
+ # AB instead of +/ to be path-safe), then bundle it into
+ # "jid1-XYZ@jetpack". This gives us 27 characters. The resulting
+ # main.js will have a path length of 211 characters, leaving us 45
+ # characters of margin.
+ #
+ # 80 bits is enough to generate one billion JIDs and still maintain lower
+ # than a one-in-a-million chance of accidental collision. (1e9 JIDs is 30
+ # bits, square for the "birthday-paradox" to get 60 bits, add 20 bits for
+ # the one-in-a-million margin to get 80 bits)
+
+ # if length were no issue, we'd prefer to use this:
+ h = os.urandom(80/8)
+ s = base64.b64encode(h, "AB").strip("=")
+ jid = "jid1-" + s
+ return jid
+
+def preflight_config(target_cfg, filename, stderr=sys.stderr):
+ modified = False
+ config = json.load(open(filename, 'r'))
+
+ if "id" not in config:
+ print >>stderr, ("No 'id' in package.json: creating a new ID for you.")
+ jid = create_jid()
+ config["id"] = jid
+ modified = True
+
+ if modified:
+ i = 0
+ backup = filename + ".backup"
+ while os.path.exists(backup):
+ if i > 1000:
+ raise ValueError("I'm having problems finding a good name"
+ " for the backup file. Please move %s out"
+ " of the way and try again."
+ % (filename + ".backup"))
+ backup = filename + ".backup-%d" % i
+ i += 1
+ os.rename(filename, backup)
+ new_json = json.dumps(config, indent=4)
+ open(filename, 'w').write(new_json+"\n")
+ return False, True
+
+ return True, False
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/prefs.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/prefs.py
new file mode 100644
index 0000000..8d20039
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/prefs.py
@@ -0,0 +1,115 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+DEFAULT_COMMON_PREFS = {
+ # allow debug output via dump to be printed to the system console
+ # (setting it here just in case, even though PlainTextConsole also
+ # sets this preference)
+ 'browser.dom.window.dump.enabled': True,
+ # warn about possibly incorrect code
+ 'javascript.options.strict': True,
+ 'javascript.options.showInConsole': True,
+
+ 'extensions.checkCompatibility.nightly' : False,
+
+ # Disable extension updates and notifications.
+ 'extensions.update.enabled' : False,
+ 'extensions.update.notifyUser' : False,
+
+ # From:
+ # http://hg.mozilla.org/mozilla-central/file/1dd81c324ac7/build/automation.py.in#l372
+ # Only load extensions from the application and user profile.
+ # AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_APPLICATION
+ 'extensions.enabledScopes' : 5,
+ # Disable metadata caching for installed add-ons by default
+ 'extensions.getAddons.cache.enabled' : False,
+ # Disable intalling any distribution add-ons
+ 'extensions.installDistroAddons' : False,
+ # Allow installing extensions dropped into the profile folder
+ 'extensions.autoDisableScopes' : 10,
+
+ # Point update checks to a nonexistent local URL for fast failures.
+ 'extensions.update.url' : 'http://localhost/extensions-dummy/updateURL',
+ 'extensions.blocklist.url' : 'http://localhost/extensions-dummy/blocklistURL',
+ # Make sure opening about:addons won't hit the network.
+ 'extensions.webservice.discoverURL' : 'http://localhost/extensions-dummy/discoveryURL'
+}
+
+DEFAULT_FENNEC_PREFS = {
+ 'browser.console.showInPanel': True,
+ 'browser.firstrun.show.uidiscovery': False
+}
+
+# When launching a temporary new Firefox profile, use these preferences.
+DEFAULT_FIREFOX_PREFS = {
+ 'browser.startup.homepage' : 'about:blank',
+ 'startup.homepage_welcome_url' : 'about:blank',
+ 'devtools.errorconsole.enabled' : True,
+
+ # Disable the feedback extension
+ 'extensions.testpilot.runStudies' : False,
+
+ # From:
+ # http://hg.mozilla.org/mozilla-central/file/1dd81c324ac7/build/automation.py.in#l388
+ # Make url-classifier updates so rare that they won't affect tests.
+ 'urlclassifier.updateinterval' : 172800,
+ # Point the url-classifier to a nonexistent local URL for fast failures.
+ 'browser.safebrowsing.provider.0.gethashURL' : 'http://localhost/safebrowsing-dummy/gethash',
+ 'browser.safebrowsing.provider.0.keyURL' : 'http://localhost/safebrowsing-dummy/newkey',
+ 'browser.safebrowsing.provider.0.updateURL' : 'http://localhost/safebrowsing-dummy/update',
+ }
+
+# When launching a temporary new Thunderbird profile, use these preferences.
+# Note that these were taken from:
+# http://mxr.mozilla.org/comm-central/source/mail/test/mozmill/runtest.py
+DEFAULT_THUNDERBIRD_PREFS = {
+ # say no to slow script warnings
+ 'dom.max_chrome_script_run_time': 200,
+ 'dom.max_script_run_time': 0,
+ # do not ask about being the default mail client
+ 'mail.shell.checkDefaultClient': False,
+ # disable non-gloda indexing daemons
+ 'mail.winsearch.enable': False,
+ 'mail.winsearch.firstRunDone': True,
+ 'mail.spotlight.enable': False,
+ 'mail.spotlight.firstRunDone': True,
+ # disable address books for undisclosed reasons
+ 'ldap_2.servers.osx.position': 0,
+ 'ldap_2.servers.oe.position': 0,
+ # disable the first use junk dialog
+ 'mailnews.ui.junk.firstuse': False,
+ # other unknown voodoo
+ # -- dummied up local accounts to stop the account wizard
+ 'mail.account.account1.server' : "server1",
+ 'mail.account.account2.identities' : "id1",
+ 'mail.account.account2.server' : "server2",
+ 'mail.accountmanager.accounts' : "account1,account2",
+ 'mail.accountmanager.defaultaccount' : "account2",
+ 'mail.accountmanager.localfoldersserver' : "server1",
+ 'mail.identity.id1.fullName' : "Tinderbox",
+ 'mail.identity.id1.smtpServer' : "smtp1",
+ 'mail.identity.id1.useremail' : "tinderbox@invalid.com",
+ 'mail.identity.id1.valid' : True,
+ 'mail.root.none-rel' : "[ProfD]Mail",
+ 'mail.root.pop3-rel' : "[ProfD]Mail",
+ 'mail.server.server1.directory-rel' : "[ProfD]Mail/Local Folders",
+ 'mail.server.server1.hostname' : "Local Folders",
+ 'mail.server.server1.name' : "Local Folders",
+ 'mail.server.server1.type' : "none",
+ 'mail.server.server1.userName' : "nobody",
+ 'mail.server.server2.check_new_mail' : False,
+ 'mail.server.server2.directory-rel' : "[ProfD]Mail/tinderbox",
+ 'mail.server.server2.download_on_biff' : True,
+ 'mail.server.server2.hostname' : "tinderbox",
+ 'mail.server.server2.login_at_startup' : False,
+ 'mail.server.server2.name' : "tinderbox@invalid.com",
+ 'mail.server.server2.type' : "pop3",
+ 'mail.server.server2.userName' : "tinderbox",
+ 'mail.smtp.defaultserver' : "smtp1",
+ 'mail.smtpserver.smtp1.hostname' : "tinderbox",
+ 'mail.smtpserver.smtp1.username' : "tinderbox",
+ 'mail.smtpservers' : "smtp1",
+ 'mail.startup.enabledMailCheckOnce' : True,
+ 'mailnews.start_page_override.mstone' : "ignore",
+ }
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/property_parser.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/property_parser.py
new file mode 100644
index 0000000..b3f554d
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/property_parser.py
@@ -0,0 +1,106 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import re
+import codecs
+
+class MalformedLocaleFileError(Exception):
+ pass
+
+def parse_file(path):
+ return parse(read_file(path), path)
+
+def read_file(path):
+ try:
+ return codecs.open( path, "r", "utf-8" ).readlines()
+ except UnicodeDecodeError, e:
+ raise MalformedLocaleFileError(
+ 'Following locale file is not a valid ' +
+ 'UTF-8 file: %s\n%s"' % (path, str(e)))
+
+COMMENT = re.compile(r'\s*#')
+EMPTY = re.compile(r'^\s+$')
+KEYVALUE = re.compile(r"\s*([^=:]+)(=|:)\s*(.*)")
+
+def parse(lines, path=None):
+ lines = iter(lines)
+ lineNo = 1
+ pairs = dict()
+ for line in lines:
+ if COMMENT.match(line) or EMPTY.match(line) or len(line) == 0:
+ continue
+ m = KEYVALUE.match(line)
+ if not m:
+ raise MalformedLocaleFileError(
+ 'Following locale file is not a valid .properties file: %s\n'
+ 'Line %d is incorrect:\n%s' % (path, lineNo, line))
+
+ # All spaces are strip. Spaces at the beginning are stripped
+ # by the regular expression. We have to strip spaces at the end.
+ key = m.group(1).rstrip()
+ val = m.group(3).rstrip()
+
+ # `key` can be empty when key is only made of spaces
+ if not key:
+ raise MalformedLocaleFileError(
+ 'Following locale file is not a valid .properties file: %s\n'
+ 'Key is invalid on line %d is incorrect:\n%s' %
+ (path, lineNo, line))
+
+ # Multiline value: keep reading lines, while lines end with backslash
+ # and strip spaces at the beginning of lines except the last line
+ # that doesn't end up with backslash, we strip all spaces for this one.
+ if val.endswith("\\"):
+ val = val[:-1]
+ try:
+ # remove spaces before/after and especially the \n at EOL
+ line = lines.next().strip()
+ while line.endswith("\\"):
+ val += line[:-1].lstrip()
+ line = lines.next()
+ lineNo += 1
+ val += line.strip()
+ except StopIteration:
+ raise MalformedLocaleFileError(
+ 'Following locale file is not a valid .properties file: %s\n'
+ 'Unexpected EOF in multiline sequence at line %d:\n%s' %
+ (path, lineNo, line))
+ # Save this new pair
+ pairs[key] = val
+ lineNo += 1
+
+ normalize_plural(path, pairs)
+ return pairs
+
+# Plural forms in properties files are defined like this:
+# key = other form
+# key[one] = one form
+# key[...] = ...
+# Parse them and merge each key into one object containing all forms:
+# key: {
+# other: "other form",
+# one: "one form",
+# ...: ...
+# }
+PLURAL_FORM = re.compile(r'^(.*)\[(zero|one|two|few|many|other)\]$')
+def normalize_plural(path, pairs):
+ for key in list(pairs.keys()):
+ m = PLURAL_FORM.match(key)
+ if not m:
+ continue
+ main_key = m.group(1)
+ plural_form = m.group(2)
+ if not main_key in pairs:
+ raise MalformedLocaleFileError(
+ 'Following locale file is not a valid UTF-8 file: %s\n'
+ 'This plural form doesn\'t have a matching generic form:\n'
+ '%s\n'
+ 'You have to defined following key:\n%s'
+ % (path, key, main_key))
+ # convert generic form into an object if it is still a string
+ if isinstance(pairs[main_key], unicode):
+ pairs[main_key] = {"other": pairs[main_key]}
+ # then, add this new plural form
+ pairs[main_key][plural_form] = pairs[key]
+ del pairs[key]
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/rdf.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/rdf.py
new file mode 100644
index 0000000..389f512
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/rdf.py
@@ -0,0 +1,190 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import xml.dom.minidom
+import StringIO
+
+RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+EM_NS = "http://www.mozilla.org/2004/em-rdf#"
+
+class RDF(object):
+ def __str__(self):
+ # real files have an .encoding attribute and use it when you
+ # write() unicode into them: they read()/write() unicode and
+ # put encoded bytes in the backend file. StringIO objects
+ # read()/write() unicode and put unicode in the backing store,
+ # so we must encode the output of getvalue() to get a
+ # bytestring. (cStringIO objects are weirder: they effectively
+ # have .encoding hardwired to "ascii" and put only bytes in
+ # the backing store, so we can't use them here).
+ #
+ # The encoding= argument to dom.writexml() merely sets the XML header's
+ # encoding= attribute. It still writes unencoded unicode to the output file,
+ # so we have to encode it for real afterwards.
+ #
+ # Also see: https://bugzilla.mozilla.org/show_bug.cgi?id=567660
+
+ buf = StringIO.StringIO()
+ self.dom.writexml(buf, encoding="utf-8")
+ return buf.getvalue().encode('utf-8')
+
+class RDFUpdate(RDF):
+ def __init__(self):
+ impl = xml.dom.minidom.getDOMImplementation()
+ self.dom = impl.createDocument(RDF_NS, "RDF", None)
+ self.dom.documentElement.setAttribute("xmlns", RDF_NS)
+ self.dom.documentElement.setAttribute("xmlns:em", EM_NS)
+
+ def _make_node(self, name, value, parent):
+ elem = self.dom.createElement(name)
+ elem.appendChild(self.dom.createTextNode(value))
+ parent.appendChild(elem)
+ return elem
+
+ def add(self, manifest, update_link):
+ desc = self.dom.createElement("Description")
+ desc.setAttribute(
+ "about",
+ "urn:mozilla:extension:%s" % manifest.get("em:id")
+ )
+ self.dom.documentElement.appendChild(desc)
+
+ updates = self.dom.createElement("em:updates")
+ desc.appendChild(updates)
+
+ seq = self.dom.createElement("Seq")
+ updates.appendChild(seq)
+
+ li = self.dom.createElement("li")
+ seq.appendChild(li)
+
+ li_desc = self.dom.createElement("Description")
+ li.appendChild(li_desc)
+
+ self._make_node("em:version", manifest.get("em:version"),
+ li_desc)
+
+ apps = manifest.dom.documentElement.getElementsByTagName(
+ "em:targetApplication"
+ )
+
+ for app in apps:
+ target_app = self.dom.createElement("em:targetApplication")
+ li_desc.appendChild(target_app)
+
+ ta_desc = self.dom.createElement("Description")
+ target_app.appendChild(ta_desc)
+
+ for name in ["em:id", "em:minVersion", "em:maxVersion"]:
+ elem = app.getElementsByTagName(name)[0]
+ self._make_node(name, elem.firstChild.nodeValue, ta_desc)
+
+ self._make_node("em:updateLink", update_link, ta_desc)
+
+class RDFManifest(RDF):
+ def __init__(self, path):
+ self.dom = xml.dom.minidom.parse(path)
+
+ def set(self, property, value):
+ elements = self.dom.documentElement.getElementsByTagName(property)
+ if not elements:
+ raise ValueError("Element with value not found: %s" % property)
+ if not elements[0].firstChild:
+ elements[0].appendChild(self.dom.createTextNode(value))
+ else:
+ elements[0].firstChild.nodeValue = value
+
+ def get(self, property, default=None):
+ elements = self.dom.documentElement.getElementsByTagName(property)
+ if not elements:
+ return default
+ return elements[0].firstChild.nodeValue
+
+ def remove(self, property):
+ elements = self.dom.documentElement.getElementsByTagName(property)
+ if not elements:
+ return True
+ else:
+ for i in elements:
+ i.parentNode.removeChild(i);
+
+ return True;
+
+def gen_manifest(template_root_dir, target_cfg, jid,
+ update_url=None, bootstrap=True, enable_mobile=False):
+ install_rdf = os.path.join(template_root_dir, "install.rdf")
+ manifest = RDFManifest(install_rdf)
+ dom = manifest.dom
+
+ manifest.set("em:id", jid)
+ manifest.set("em:version",
+ target_cfg.get('version', '1.0'))
+ manifest.set("em:name",
+ target_cfg.get('fullName', target_cfg['name']))
+ manifest.set("em:description",
+ target_cfg.get("description", ""))
+ manifest.set("em:creator",
+ target_cfg.get("author", ""))
+ manifest.set("em:bootstrap", str(bootstrap).lower())
+ # XPIs remain packed by default, but package.json can override that. The
+ # RDF format accepts "true" as True, anything else as False. We expect
+ # booleans in the .json file, not strings.
+ manifest.set("em:unpack", "true" if target_cfg.get("unpack") else "false")
+
+ for contributor in target_cfg.get("contributors", [ ]):
+ elem = dom.createElement("em:contributor");
+ elem.appendChild(dom.createTextNode(contributor))
+ dom.documentElement.getElementsByTagName("Description")[0].appendChild(elem)
+
+ if update_url:
+ manifest.set("em:updateURL", update_url)
+ else:
+ manifest.remove("em:updateURL")
+
+ if target_cfg.get("preferences"):
+ manifest.set("em:optionsType", "2")
+ else:
+ manifest.remove("em:optionsType")
+
+ if enable_mobile:
+ target_app = dom.createElement("em:targetApplication")
+ dom.documentElement.getElementsByTagName("Description")[0].appendChild(target_app)
+
+ ta_desc = dom.createElement("Description")
+ target_app.appendChild(ta_desc)
+
+ elem = dom.createElement("em:id")
+ elem.appendChild(dom.createTextNode("{aa3c5121-dab2-40e2-81ca-7ea25febc110}"))
+ ta_desc.appendChild(elem)
+
+ elem = dom.createElement("em:minVersion")
+ elem.appendChild(dom.createTextNode("10.0"))
+ ta_desc.appendChild(elem)
+
+ elem = dom.createElement("em:maxVersion")
+ elem.appendChild(dom.createTextNode("13.0a1"))
+ ta_desc.appendChild(elem)
+
+ if target_cfg.get("homepage"):
+ manifest.set("em:homepageURL", target_cfg.get("homepage"))
+ else:
+ manifest.remove("em:homepageURL")
+
+ return manifest
+
+if __name__ == "__main__":
+ print "Running smoke test."
+ root = os.path.join(os.path.dirname(__file__), 'app-extension')
+ manifest = gen_manifest(root, {'name': 'test extension'},
+ 'fakeid', 'http://foo.com/update.rdf')
+ update = RDFUpdate()
+ update.add(manifest, "https://foo.com/foo.xpi")
+ exercise_str = str(manifest) + str(update)
+ for tagname in ["em:targetApplication", "em:version", "em:id"]:
+ if not len(update.dom.getElementsByTagName(tagname)):
+ raise Exception("tag does not exist: %s" % tagname)
+ if not update.dom.getElementsByTagName(tagname)[0].firstChild:
+ raise Exception("tag has no children: %s" % tagname)
+ print "Success!"
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/runner.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/runner.py
new file mode 100644
index 0000000..76be215
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/runner.py
@@ -0,0 +1,696 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import sys
+import time
+import tempfile
+import atexit
+import shlex
+import subprocess
+import re
+
+import mozrunner
+from cuddlefish.prefs import DEFAULT_COMMON_PREFS
+from cuddlefish.prefs import DEFAULT_FIREFOX_PREFS
+from cuddlefish.prefs import DEFAULT_THUNDERBIRD_PREFS
+from cuddlefish.prefs import DEFAULT_FENNEC_PREFS
+
+# Used to remove noise from ADB output
+CLEANUP_ADB = re.compile(r'^(I|E)/(stdout|stderr|GeckoConsole)\s*\(\s*\d+\):\s*(.*)$')
+# Used to filter only messages send by `console` module
+FILTER_ONLY_CONSOLE_FROM_ADB = re.compile(r'^I/(stderr)\s*\(\s*\d+\):\s*((info|warning|error|debug): .*)$')
+
+# Maximum time we'll wait for tests to finish, in seconds.
+# The purpose of this timeout is to recover from infinite loops. It should be
+# longer than the amount of time any test run takes, including those on slow
+# machines running slow (debug) versions of Firefox.
+RUN_TIMEOUT = 30 * 60 # 30 minutes
+
+# Maximum time we'll wait for tests to emit output, in seconds.
+# The purpose of this timeout is to recover from hangs. It should be longer
+# than the amount of time any test takes to report results.
+OUTPUT_TIMEOUT = 60 # one minute
+
+def follow_file(filename):
+ """
+ Generator that yields the latest unread content from the given
+ file, or None if no new content is available.
+
+ For example:
+
+ >>> f = open('temp.txt', 'w')
+ >>> f.write('hello')
+ >>> f.flush()
+ >>> tail = follow_file('temp.txt')
+ >>> tail.next()
+ 'hello'
+ >>> tail.next() is None
+ True
+ >>> f.write('there')
+ >>> f.flush()
+ >>> tail.next()
+ 'there'
+ >>> f.close()
+ >>> os.remove('temp.txt')
+ """
+
+ last_pos = 0
+ last_size = 0
+ while True:
+ newstuff = None
+ if os.path.exists(filename):
+ size = os.stat(filename).st_size
+ if size > last_size:
+ last_size = size
+ f = open(filename, 'r')
+ f.seek(last_pos)
+ newstuff = f.read()
+ last_pos = f.tell()
+ f.close()
+ yield newstuff
+
+# subprocess.check_output only appeared in python2.7, so this code is taken
+# from python source code for compatibility with py2.5/2.6
+class CalledProcessError(Exception):
+ def __init__(self, returncode, cmd, output=None):
+ self.returncode = returncode
+ self.cmd = cmd
+ self.output = output
+ def __str__(self):
+ return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode)
+
+def check_output(*popenargs, **kwargs):
+ if 'stdout' in kwargs:
+ raise ValueError('stdout argument not allowed, it will be overridden.')
+ process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
+ output, unused_err = process.communicate()
+ retcode = process.poll()
+ if retcode:
+ cmd = kwargs.get("args")
+ if cmd is None:
+ cmd = popenargs[0]
+ raise CalledProcessError(retcode, cmd, output=output)
+ return output
+
+
+class FennecProfile(mozrunner.Profile):
+ preferences = {}
+ names = ['fennec']
+
+class FennecRunner(mozrunner.Runner):
+ profile_class = FennecProfile
+
+ names = ['fennec']
+
+ __DARWIN_PATH = '/Applications/Fennec.app/Contents/MacOS/fennec'
+
+ def __init__(self, binary=None, **kwargs):
+ if sys.platform == 'darwin' and binary and binary.endswith('.app'):
+ # Assume it's a Fennec app dir.
+ binary = os.path.join(binary, 'Contents/MacOS/fennec')
+
+ self.__real_binary = binary
+
+ mozrunner.Runner.__init__(self, **kwargs)
+
+ def find_binary(self):
+ if not self.__real_binary:
+ if sys.platform == 'darwin':
+ if os.path.exists(self.__DARWIN_PATH):
+ return self.__DARWIN_PATH
+ self.__real_binary = mozrunner.Runner.find_binary(self)
+ return self.__real_binary
+
+
+class RemoteFennecRunner(mozrunner.Runner):
+ profile_class = FennecProfile
+
+ names = ['fennec']
+
+ _REMOTE_PATH = '/mnt/sdcard/jetpack-profile'
+ _INTENT_PREFIX = 'org.mozilla.'
+
+ _adb_path = None
+
+ def __init__(self, binary=None, **kwargs):
+ # Check that we have a binary set
+ if not binary:
+ raise ValueError("You have to define `--binary` option set to the "
+ "path to your ADB executable.")
+ # Ensure that binary refer to a valid ADB executable
+ output = subprocess.Popen([binary], stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE).communicate()
+ output = "".join(output)
+ if not ("Android Debug Bridge" in output):
+ raise ValueError("`--binary` option should be the path to your "
+ "ADB executable.")
+ self.binary = binary
+
+ mobile_app_name = kwargs['cmdargs'][0]
+ self.profile = kwargs['profile']
+ self._adb_path = binary
+
+ # This pref has to be set to `false` otherwise, we do not receive
+ # output of adb commands!
+ subprocess.call([self._adb_path, "shell",
+ "setprop log.redirect-stdio false"])
+
+ # Android apps are launched by their "intent" name,
+ # Automatically detect already installed firefox by using `pm` program
+ # or use name given as cfx `--mobile-app` argument.
+ intents = self.getIntentNames()
+ if not intents:
+ raise ValueError("Unable to found any Firefox "
+ "application on your device.")
+ elif mobile_app_name:
+ if not mobile_app_name in intents:
+ raise ValueError("Unable to found Firefox application "
+ "with intent name '%s'\n"
+ "Available ones are: %s" %
+ (mobile_app_name, ", ".join(intents)))
+ self._intent_name = self._INTENT_PREFIX + mobile_app_name
+ else:
+ if "firefox" in intents:
+ self._intent_name = self._INTENT_PREFIX + "firefox"
+ elif "firefox_beta" in intents:
+ self._intent_name = self._INTENT_PREFIX + "firefox_beta"
+ elif "firefox_nightly" in intents:
+ self._intent_name = self._INTENT_PREFIX + "firefox_nightly"
+ else:
+ self._intent_name = self._INTENT_PREFIX + intents[0]
+
+ print "Launching mobile application with intent name " + self._intent_name
+
+ # First try to kill firefox if it is already running
+ pid = self.getProcessPID(self._intent_name)
+ if pid != None:
+ # Send a key "up" signal to mobile-utils addon
+ # in order to kill running firefox instance
+ # KEYCODE_DPAD_UP = 19
+ # http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_DPAD_UP
+ print "Killing running Firefox instance ..."
+ subprocess.call([self._adb_path, "shell", "input keyevent 19"])
+ subprocess.Popen(self.command, stdout=subprocess.PIPE).wait()
+ time.sleep(2)
+
+ print "Pushing the addon to your device"
+
+ # Create a clean empty profile on the sd card
+ subprocess.call([self._adb_path, "shell", "rm -r " + self._REMOTE_PATH])
+ subprocess.call([self._adb_path, "shell", "mkdir " + self._REMOTE_PATH])
+
+ # Push the profile folder created by mozrunner to the device
+ # (we can't simply use `adb push` as it doesn't copy empty folders)
+ localDir = self.profile.profile
+ remoteDir = self._REMOTE_PATH
+ for root, dirs, files in os.walk(localDir, followlinks='true'):
+ relRoot = os.path.relpath(root, localDir)
+ # Note about os.path usage below:
+ # Local files may be using Windows `\` separators but
+ # remote are always `/`, so we need to convert local ones to `/`
+ for file in files:
+ localFile = os.path.join(root, file)
+ remoteFile = remoteDir.replace("/", os.sep)
+ if relRoot != ".":
+ remoteFile = os.path.join(remoteFile, relRoot)
+ remoteFile = os.path.join(remoteFile, file)
+ remoteFile = "/".join(remoteFile.split(os.sep))
+ subprocess.Popen([self._adb_path, "push", localFile, remoteFile],
+ stderr=subprocess.PIPE).wait()
+ for dir in dirs:
+ targetDir = remoteDir.replace("/", os.sep)
+ if relRoot != ".":
+ targetDir = os.path.join(targetDir, relRoot)
+ targetDir = os.path.join(targetDir, dir)
+ targetDir = "/".join(targetDir.split(os.sep))
+ # `-p` option is not supported on all devices!
+ subprocess.call([self._adb_path, "shell", "mkdir " + targetDir])
+
+ @property
+ def command(self):
+ """Returns the command list to run."""
+ return [self._adb_path,
+ "shell",
+ "am start " +
+ "-a android.activity.MAIN " +
+ "-n " + self._intent_name + "/" + self._intent_name + ".App " +
+ "--es args \"-profile " + self._REMOTE_PATH + "\""
+ ]
+
+ def start(self):
+ subprocess.call(self.command)
+
+ def getProcessPID(self, processName):
+ p = subprocess.Popen([self._adb_path, "shell", "ps"],
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ line = p.stdout.readline()
+ while line:
+ columns = line.split()
+ pid = columns[1]
+ name = columns[-1]
+ line = p.stdout.readline()
+ if processName in name:
+ return pid
+ return None
+
+ def getIntentNames(self):
+ p = subprocess.Popen([self._adb_path, "shell", "pm list packages"],
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ names = []
+ for line in p.stdout.readlines():
+ line = re.sub("(^package:)|\s", "", line)
+ if self._INTENT_PREFIX in line:
+ names.append(line.replace(self._INTENT_PREFIX, ""))
+ return names
+
+
+class XulrunnerAppProfile(mozrunner.Profile):
+ preferences = {}
+ names = []
+
+class XulrunnerAppRunner(mozrunner.Runner):
+ """
+ Runner for any XULRunner app. Can use a Firefox binary in XULRunner
+ mode to execute the app, or can use XULRunner itself. Expects the
+ app's application.ini to be passed in as one of the items in
+ 'cmdargs' in the constructor.
+
+ This class relies a lot on the particulars of mozrunner.Runner's
+ implementation, and does some unfortunate acrobatics to get around
+ some of the class' limitations/assumptions.
+ """
+
+ profile_class = XulrunnerAppProfile
+
+ # This is a default, and will be overridden in the instance if
+ # Firefox is used in XULRunner mode.
+ names = ['xulrunner']
+
+ # Default location of XULRunner on OS X.
+ __DARWIN_PATH = "/Library/Frameworks/XUL.framework/xulrunner-bin"
+ __LINUX_PATH = "/usr/bin/xulrunner"
+
+ # What our application.ini's path looks like if it's part of
+ # an "installed" XULRunner app on OS X.
+ __DARWIN_APP_INI_SUFFIX = '.app/Contents/Resources/application.ini'
+
+ def __init__(self, binary=None, **kwargs):
+ if sys.platform == 'darwin' and binary and binary.endswith('.app'):
+ # Assume it's a Firefox app dir.
+ binary = os.path.join(binary, 'Contents/MacOS/firefox-bin')
+
+ self.__app_ini = None
+ self.__real_binary = binary
+
+ mozrunner.Runner.__init__(self, **kwargs)
+
+ # See if we're using a genuine xulrunner-bin from the XULRunner SDK,
+ # or if we're being asked to use Firefox in XULRunner mode.
+ self.__is_xulrunner_sdk = 'xulrunner' in self.binary
+
+ if sys.platform == 'linux2' and not self.env.get('LD_LIBRARY_PATH'):
+ self.env['LD_LIBRARY_PATH'] = os.path.dirname(self.binary)
+
+ newargs = []
+ for item in self.cmdargs:
+ if 'application.ini' in item:
+ self.__app_ini = item
+ else:
+ newargs.append(item)
+ self.cmdargs = newargs
+
+ if not self.__app_ini:
+ raise ValueError('application.ini not found in cmdargs')
+ if not os.path.exists(self.__app_ini):
+ raise ValueError("file does not exist: '%s'" % self.__app_ini)
+
+ if (sys.platform == 'darwin' and
+ self.binary == self.__DARWIN_PATH and
+ self.__app_ini.endswith(self.__DARWIN_APP_INI_SUFFIX)):
+ # If the application.ini is in an app bundle, then
+ # it could be inside an "installed" XULRunner app.
+ # If this is the case, use the app's actual
+ # binary instead of the XUL framework's, so we get
+ # a proper app icon, etc.
+ new_binary = '/'.join(self.__app_ini.split('/')[:-2] +
+ ['MacOS', 'xulrunner'])
+ if os.path.exists(new_binary):
+ self.binary = new_binary
+
+ @property
+ def command(self):
+ """Returns the command list to run."""
+
+ if self.__is_xulrunner_sdk:
+ return [self.binary, self.__app_ini, '-profile',
+ self.profile.profile]
+ else:
+ return [self.binary, '-app', self.__app_ini, '-profile',
+ self.profile.profile]
+
+ def __find_xulrunner_binary(self):
+ if sys.platform == 'darwin':
+ if os.path.exists(self.__DARWIN_PATH):
+ return self.__DARWIN_PATH
+ if sys.platform == 'linux2':
+ if os.path.exists(self.__LINUX_PATH):
+ return self.__LINUX_PATH
+ return None
+
+ def find_binary(self):
+ # This gets called by the superclass constructor. It will
+ # always get called, even if a binary was passed into the
+ # constructor, because we want to have full control over
+ # what the exact setting of self.binary is.
+
+ if not self.__real_binary:
+ self.__real_binary = self.__find_xulrunner_binary()
+ if not self.__real_binary:
+ dummy_profile = {}
+ runner = mozrunner.FirefoxRunner(profile=dummy_profile)
+ self.__real_binary = runner.find_binary()
+ self.names = runner.names
+ return self.__real_binary
+
+def run_app(harness_root_dir, manifest_rdf, harness_options,
+ app_type, binary=None, profiledir=None, verbose=False,
+ enforce_timeouts=False,
+ logfile=None, addons=None, args=None, extra_environment={},
+ norun=None,
+ used_files=None, enable_mobile=False,
+ mobile_app_name=None):
+ if binary:
+ binary = os.path.expanduser(binary)
+
+ if addons is None:
+ addons = []
+ else:
+ addons = list(addons)
+
+ cmdargs = []
+ preferences = dict(DEFAULT_COMMON_PREFS)
+
+ # For now, only allow running on Mobile with --force-mobile argument
+ if app_type in ["fennec", "fennec-on-device"] and not enable_mobile:
+ print """
+ WARNING: Firefox Mobile support is still experimental.
+ If you would like to run an addon on this platform, use --force-mobile flag:
+
+ cfx --force-mobile"""
+ return 0
+
+ if app_type == "fennec-on-device":
+ profile_class = FennecProfile
+ preferences.update(DEFAULT_FENNEC_PREFS)
+ runner_class = RemoteFennecRunner
+ # We pass the intent name through command arguments
+ cmdargs.append(mobile_app_name)
+ elif enable_mobile or app_type == "fennec":
+ profile_class = FennecProfile
+ preferences.update(DEFAULT_FENNEC_PREFS)
+ runner_class = FennecRunner
+ elif app_type == "xulrunner":
+ profile_class = XulrunnerAppProfile
+ runner_class = XulrunnerAppRunner
+ cmdargs.append(os.path.join(harness_root_dir, 'application.ini'))
+ elif app_type == "firefox":
+ profile_class = mozrunner.FirefoxProfile
+ preferences.update(DEFAULT_FIREFOX_PREFS)
+ runner_class = mozrunner.FirefoxRunner
+ elif app_type == "thunderbird":
+ profile_class = mozrunner.ThunderbirdProfile
+ preferences.update(DEFAULT_THUNDERBIRD_PREFS)
+ runner_class = mozrunner.ThunderbirdRunner
+ else:
+ raise ValueError("Unknown app: %s" % app_type)
+ if sys.platform == 'darwin' and app_type != 'xulrunner':
+ cmdargs.append('-foreground')
+
+ if args:
+ cmdargs.extend(shlex.split(args))
+
+ # TODO: handle logs on remote device
+ if app_type != "fennec-on-device":
+ # tempfile.gettempdir() was constant, preventing two simultaneous "cfx
+ # run"/"cfx test" on the same host. On unix it points at /tmp (which is
+ # world-writeable), enabling a symlink attack (e.g. imagine some bad guy
+ # does 'ln -s ~/.ssh/id_rsa /tmp/harness_result'). NamedTemporaryFile
+ # gives us a unique filename that fixes both problems. We leave the
+ # (0-byte) file in place until the browser-side code starts writing to
+ # it, otherwise the symlink attack becomes possible again.
+ fileno,resultfile = tempfile.mkstemp(prefix="harness-result-")
+ os.close(fileno)
+ harness_options['resultFile'] = resultfile
+
+ def maybe_remove_logfile():
+ if os.path.exists(logfile):
+ os.remove(logfile)
+
+ logfile_tail = None
+
+ # We always buffer output through a logfile for two reasons:
+ # 1. On Windows, it's the only way to print console output to stdout/err.
+ # 2. It enables us to keep track of the last time output was emitted,
+ # so we can raise an exception if the test runner hangs.
+ if not logfile:
+ fileno,logfile = tempfile.mkstemp(prefix="harness-log-")
+ os.close(fileno)
+ logfile_tail = follow_file(logfile)
+ atexit.register(maybe_remove_logfile)
+
+ logfile = os.path.abspath(os.path.expanduser(logfile))
+ maybe_remove_logfile()
+
+ if app_type != "fennec-on-device":
+ harness_options['logFile'] = logfile
+
+ env = {}
+ env.update(os.environ)
+ env['MOZ_NO_REMOTE'] = '1'
+ env['XPCOM_DEBUG_BREAK'] = 'stack'
+ env['NS_TRACE_MALLOC_DISABLE_STACKS'] = '1'
+ env.update(extra_environment)
+ if norun:
+ cmdargs.append("-no-remote")
+
+ # Create the addon XPI so mozrunner will copy it to the profile it creates.
+ # We delete it below after getting mozrunner to create the profile.
+ from cuddlefish.xpi import build_xpi
+ xpi_path = tempfile.mktemp(suffix='cfx-tmp.xpi')
+ build_xpi(template_root_dir=harness_root_dir,
+ manifest=manifest_rdf,
+ xpi_path=xpi_path,
+ harness_options=harness_options,
+ limit_to=used_files)
+ addons.append(xpi_path)
+
+ starttime = last_output_time = time.time()
+
+ # Redirect runner output to a file so we can catch output not generated
+ # by us.
+ # In theory, we could do this using simple redirection on all platforms
+ # other than Windows, but this way we only have a single codepath to
+ # maintain.
+ fileno,outfile = tempfile.mkstemp(prefix="harness-stdout-")
+ os.close(fileno)
+ outfile_tail = follow_file(outfile)
+ def maybe_remove_outfile():
+ if os.path.exists(outfile):
+ os.remove(outfile)
+ atexit.register(maybe_remove_outfile)
+ outf = open(outfile, "w")
+ popen_kwargs = { 'stdout': outf, 'stderr': outf}
+
+ profile = None
+
+ if app_type == "fennec-on-device":
+ # Install a special addon when we run firefox on mobile device
+ # in order to be able to kill it
+ mydir = os.path.dirname(os.path.abspath(__file__))
+ addon_dir = os.path.join(mydir, "mobile-utils")
+ addons.append(addon_dir)
+
+ # the XPI file is copied into the profile here
+ profile = profile_class(addons=addons,
+ profile=profiledir,
+ preferences=preferences)
+
+ # Delete the temporary xpi file
+ os.remove(xpi_path)
+
+ runner = runner_class(profile=profile,
+ binary=binary,
+ env=env,
+ cmdargs=cmdargs,
+ kp_kwargs=popen_kwargs)
+
+ sys.stdout.flush(); sys.stderr.flush()
+
+ if app_type == "fennec-on-device":
+ if not enable_mobile:
+ print >>sys.stderr, """
+ WARNING: Firefox Mobile support is still experimental.
+ If you would like to run an addon on this platform, use --force-mobile flag:
+
+ cfx --force-mobile"""
+ return 0
+
+ # In case of mobile device, we need to get stdio from `adb logcat` cmd:
+
+ # First flush logs in order to avoid catching previous ones
+ subprocess.call([binary, "logcat", "-c"])
+
+ # Launch adb command
+ runner.start()
+
+ # We can immediatly remove temporary profile folder
+ # as it has been uploaded to the device
+ profile.cleanup()
+ # We are not going to use the output log file
+ outf.close()
+
+ # Then we simply display stdout of `adb logcat`
+ p = subprocess.Popen([binary, "logcat", "stderr:V stdout:V GeckoConsole:V *:S"], stdout=subprocess.PIPE)
+ while True:
+ line = p.stdout.readline()
+ if line == '':
+ break
+ # mobile-utils addon contains an application quit event observer
+ # that will print this string:
+ if "APPLICATION-QUIT" in line:
+ break
+
+ if verbose:
+ # if --verbose is given, we display everything:
+ # All JS Console messages, stdout and stderr.
+ m = CLEANUP_ADB.match(line)
+ if not m:
+ print line.rstrip()
+ continue
+ print m.group(3)
+ else:
+ # Otherwise, display addons messages dispatched through
+ # console.[info, log, debug, warning, error](msg)
+ m = FILTER_ONLY_CONSOLE_FROM_ADB.match(line)
+ if m:
+ print m.group(2)
+
+ print >>sys.stderr, "Program terminated successfully."
+ return 0
+
+
+ print >>sys.stderr, "Using binary at '%s'." % runner.binary
+
+ # Ensure cfx is being used with Firefox 4.0+.
+ # TODO: instead of dying when Firefox is < 4, warn when Firefox is outside
+ # the minVersion/maxVersion boundaries.
+ version_output = check_output(runner.command + ["-v"])
+ # Note: this regex doesn't handle all valid versions in the Toolkit Version
+ # Format <https://developer.mozilla.org/en/Toolkit_version_format>, just the
+ # common subset that we expect Mozilla apps to use.
+ mo = re.search(r"Mozilla (Firefox|Iceweasel|Fennec) ((\d+)\.\S*)",
+ version_output)
+ if not mo:
+ # cfx may be used with Thunderbird, SeaMonkey or an exotic Firefox
+ # version.
+ print """
+ WARNING: cannot determine Firefox version; please ensure you are running
+ a Mozilla application equivalent to Firefox 4.0 or greater.
+ """
+ elif mo.group(1) == "Fennec":
+ # For now, only allow running on Mobile with --force-mobile argument
+ if not enable_mobile:
+ print """
+ WARNING: Firefox Mobile support is still experimental.
+ If you would like to run an addon on this platform, use --force-mobile flag:
+
+ cfx --force-mobile"""
+ return
+ else:
+ version = mo.group(3)
+ if int(version) < 4:
+ print """
+ cfx requires Firefox 4 or greater and is unable to find a compatible
+ binary. Please install a newer version of Firefox or provide the path to
+ your existing compatible version with the --binary flag:
+
+ cfx --binary=PATH_TO_FIREFOX_BINARY"""
+ return
+
+ # Set the appropriate extensions.checkCompatibility preference to false,
+ # so the tests run even if the SDK is not marked as compatible with the
+ # version of Firefox on which they are running, and we don't have to
+ # ensure we update the maxVersion before the version of Firefox changes
+ # every six weeks.
+ #
+ # The regex we use here is effectively the same as BRANCH_REGEX from
+ # /toolkit/mozapps/extensions/content/extensions.js, which toolkit apps
+ # use to determine whether or not to load an incompatible addon.
+ #
+ br = re.search(r"^([^\.]+\.[0-9]+[a-z]*).*", mo.group(2), re.I)
+ if br:
+ prefname = 'extensions.checkCompatibility.' + br.group(1)
+ profile.preferences[prefname] = False
+ # Calling profile.set_preferences here duplicates the list of prefs
+ # in prefs.js, since the profile calls self.set_preferences in its
+ # constructor, but that is ok, because it doesn't change the set of
+ # preferences that are ultimately registered in Firefox.
+ profile.set_preferences(profile.preferences)
+
+ print >>sys.stderr, "Using profile at '%s'." % profile.profile
+ sys.stderr.flush()
+
+ if norun:
+ print "To launch the application, enter the following command:"
+ print " ".join(runner.command) + " " + (" ".join(runner.cmdargs))
+ return 0
+
+ runner.start()
+
+ done = False
+ result = None
+ try:
+ while not done:
+ time.sleep(0.05)
+ for tail in (logfile_tail, outfile_tail):
+ if tail:
+ new_chars = tail.next()
+ if new_chars:
+ last_output_time = time.time()
+ sys.stderr.write(new_chars)
+ sys.stderr.flush()
+ if os.path.exists(resultfile):
+ result = open(resultfile).read()
+ if result:
+ if result in ['OK', 'FAIL']:
+ done = True
+ else:
+ sys.stderr.write("Hrm, resultfile (%s) contained something weird (%d bytes)\n" % (resultfile, len(result)))
+ sys.stderr.write("'"+result+"'\n")
+ if enforce_timeouts:
+ if time.time() - last_output_time > OUTPUT_TIMEOUT:
+ raise Exception("Test output exceeded timeout (%ds)." %
+ OUTPUT_TIMEOUT)
+ if time.time() - starttime > RUN_TIMEOUT:
+ raise Exception("Test run exceeded timeout (%ds)." %
+ RUN_TIMEOUT)
+ except:
+ runner.stop()
+ raise
+ else:
+ runner.wait(10)
+ finally:
+ outf.close()
+ if profile:
+ profile.cleanup()
+
+ print >>sys.stderr, "Total time: %f seconds" % (time.time() - starttime)
+
+ if result == 'OK':
+ print >>sys.stderr, "Program terminated successfully."
+ return 0
+ else:
+ print >>sys.stderr, "Program terminated unsuccessfully."
+ return -1
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/templates.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/templates.py
new file mode 100644
index 0000000..a04bb9a
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/templates.py
@@ -0,0 +1,83 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#Template used by main.js
+MAIN_JS = '''\
+const widgets = require("widget");
+const tabs = require("tabs");
+
+var widget = widgets.Widget({
+ id: "mozilla-link",
+ label: "Mozilla website",
+ contentURL: "http://www.mozilla.org/favicon.ico",
+ onClick: function() {
+ tabs.open("http://www.mozilla.org/");
+ }
+});
+
+console.log("The add-on is running.");
+'''
+
+#Template used by test-main.js
+TEST_MAIN_JS = '''\
+const main = require("main");
+
+exports.test_test_run = function(test) {
+ test.pass("Unit test running!");
+};
+
+exports.test_id = function(test) {
+ test.assert(require("self").id.length > 0);
+};
+
+exports.test_url = function(test) {
+ require("request").Request({
+ url: "http://www.mozilla.org/",
+ onComplete: function(response) {
+ test.assertEqual(response.statusText, "OK");
+ test.done();
+ }
+ }).get();
+ test.waitUntilDone(20000);
+};
+
+exports.test_open_tab = function(test) {
+ const tabs = require("tabs");
+ tabs.open({
+ url: "http://www.mozilla.org/",
+ onReady: function(tab) {
+ test.assertEqual(tab.url, "http://www.mozilla.org/");
+ test.done();
+ }
+ });
+ test.waitUntilDone(20000);
+};
+'''
+
+#Template used by main.md
+MAIN_JS_DOC = '''\
+The main module is a program that creates a widget. When a user clicks on
+the widget, the program loads the mozilla.org website in a new tab.
+'''
+
+#Template used by README.md
+README_DOC = '''\
+This is the %(name)s add-on. It contains:
+
+* A program (lib/main.js).
+* A few tests.
+* Some meager documentation.
+'''
+
+#Template used by package.json
+PACKAGE_JSON = '''\
+{
+ "name": "%(name)s",
+ "fullName": "%(fullName)s",
+ "description": "a basic add-on",
+ "author": "",
+ "license": "MPL 2.0",
+ "version": "0.1"
+}
+'''
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/__init__.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/__init__.py
new file mode 100644
index 0000000..c1a7fd2
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/__init__.py
@@ -0,0 +1,65 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import unittest
+import doctest
+import glob
+
+env_root = os.environ['CUDDLEFISH_ROOT']
+
+def get_tests():
+ import cuddlefish
+ import cuddlefish.tests
+
+ tests = []
+ packages = [cuddlefish, cuddlefish.tests]
+ for package in packages:
+ path = os.path.abspath(package.__path__[0])
+ pynames = glob.glob(os.path.join(path, '*.py'))
+ for filename in pynames:
+ basename = os.path.basename(filename)
+ module_name = os.path.splitext(basename)[0]
+ full_name = "%s.%s" % (package.__name__, module_name)
+ module = __import__(full_name, fromlist=[package.__name__])
+
+ loader = unittest.TestLoader()
+ suite = loader.loadTestsFromModule(module)
+ for test in suite:
+ tests.append(test)
+
+ finder = doctest.DocTestFinder()
+ doctests = finder.find(module)
+ for test in doctests:
+ if len(test.examples) > 0:
+ tests.append(doctest.DocTestCase(test))
+
+ md_dir = os.path.join(env_root, 'dev-guide')
+ doctest_opts = (doctest.NORMALIZE_WHITESPACE |
+ doctest.REPORT_UDIFF)
+ for dirpath, dirnames, filenames in os.walk(md_dir):
+ for filename in filenames:
+ if filename.endswith('.md'):
+ absname = os.path.join(dirpath, filename)
+ tests.append(doctest.DocFileTest(
+ absname,
+ module_relative=False,
+ optionflags=doctest_opts
+ ))
+
+ return tests
+
+def run(verbose=False):
+ if verbose:
+ verbosity = 2
+ else:
+ verbosity = 1
+
+ tests = get_tests()
+ suite = unittest.TestSuite(tests)
+ runner = unittest.TextTestRunner(verbosity=verbosity)
+ return runner.run(suite)
+
+if __name__ == '__main__':
+ run()
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/addons/simplest-test/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/addons/simplest-test/main.js
new file mode 100644
index 0000000..980ea88
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/addons/simplest-test/main.js
@@ -0,0 +1,17 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const { Cc, Ci } = require("chrome");
+
+exports.main = function(options, callbacks) {
+ // Close Firefox window. Firefox should quit.
+ require("api-utils/window-utils").activeBrowserWindow.close();
+
+ // But not on Mac where it stay alive! We have to request application quit.
+ if (require("api-utils/runtime").OS == "Darwin") {
+ let appStartup = Cc['@mozilla.org/toolkit/app-startup;1'].
+ getService(Ci.nsIAppStartup);
+ appStartup.quit(appStartup.eAttemptQuit);
+ }
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/addons/simplest-test/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/addons/simplest-test/package.json
new file mode 100644
index 0000000..afbc158
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/addons/simplest-test/package.json
@@ -0,0 +1,6 @@
+{
+ "id": "simplest-test",
+ "directories": {
+ "lib": "."
+ }
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/addons/simplest-test/tests/test-minimal.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/addons/simplest-test/tests/test-minimal.js
new file mode 100644
index 0000000..533cd34
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/addons/simplest-test/tests/test-minimal.js
@@ -0,0 +1,7 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.minimalTest = function(test) {
+ test.assert(true);
+};
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/explicit-icon/explicit-icon.png b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/explicit-icon/explicit-icon.png
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/explicit-icon/explicit-icon.png
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/explicit-icon/explicit-icon64.png b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/explicit-icon/explicit-icon64.png
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/explicit-icon/explicit-icon64.png
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/explicit-icon/lib/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/explicit-icon/lib/main.js
new file mode 100644
index 0000000..b7e0a1d
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/explicit-icon/lib/main.js
@@ -0,0 +1,4 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/explicit-icon/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/explicit-icon/package.json
new file mode 100644
index 0000000..8d56d74
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/explicit-icon/package.json
@@ -0,0 +1,5 @@
+{
+ "loader": "lib/main.js",
+ "icon": "explicit-icon.png",
+ "icon64": "explicit-icon64.png"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/implicit-icon/icon.png b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/implicit-icon/icon.png
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/implicit-icon/icon.png
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/implicit-icon/icon64.png b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/implicit-icon/icon64.png
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/implicit-icon/icon64.png
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/implicit-icon/lib/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/implicit-icon/lib/main.js
new file mode 100644
index 0000000..b7e0a1d
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/implicit-icon/lib/main.js
@@ -0,0 +1,4 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/implicit-icon/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/implicit-icon/package.json
new file mode 100644
index 0000000..3f0e241
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/implicit-icon/package.json
@@ -0,0 +1,3 @@
+{
+ "loader": "lib/main.js"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/no-icon/lib/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/no-icon/lib/main.js
new file mode 100644
index 0000000..b7e0a1d
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/no-icon/lib/main.js
@@ -0,0 +1,4 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/no-icon/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/no-icon/package.json
new file mode 100644
index 0000000..3f0e241
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588119-files/packages/no-icon/package.json
@@ -0,0 +1,3 @@
+{
+ "loader": "lib/main.js"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588661-files/packages/bar/lib/bar-loader.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588661-files/packages/bar/lib/bar-loader.js
new file mode 100644
index 0000000..b7e0a1d
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588661-files/packages/bar/lib/bar-loader.js
@@ -0,0 +1,4 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588661-files/packages/bar/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588661-files/packages/bar/package.json
new file mode 100644
index 0000000..e83a9d4
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588661-files/packages/bar/package.json
@@ -0,0 +1,3 @@
+{
+ "loader": "lib/bar-loader.js"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588661-files/packages/foo/lib/foo-loader.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588661-files/packages/foo/lib/foo-loader.js
new file mode 100644
index 0000000..b7e0a1d
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588661-files/packages/foo/lib/foo-loader.js
@@ -0,0 +1,4 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588661-files/packages/foo/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588661-files/packages/foo/package.json
new file mode 100644
index 0000000..4648df6
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-588661-files/packages/foo/package.json
@@ -0,0 +1,4 @@
+{
+ "loader": "lib/foo-loader.js",
+ "dependencies": ["bar"]
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-611495-files/jspath-one/docs/main.md b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-611495-files/jspath-one/docs/main.md
new file mode 100644
index 0000000..54518d3
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-611495-files/jspath-one/docs/main.md
@@ -0,0 +1,5 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+minimal docs
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-611495-files/jspath-one/lib/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-611495-files/jspath-one/lib/main.js
new file mode 100644
index 0000000..aeda0e7
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-611495-files/jspath-one/lib/main.js
@@ -0,0 +1,8 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.main = function(options, callbacks) {
+ console.log("minimal");
+ callbacks.quit();
+};
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-611495-files/jspath-one/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-611495-files/jspath-one/package.json
new file mode 100644
index 0000000..45d409a
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-611495-files/jspath-one/package.json
@@ -0,0 +1,5 @@
+{
+ "name": "jspath-one",
+ "author": "Jon Smith",
+ "description": "A package w/ a main module; can be built into an extension."
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/commonjs-naming/doc/foo.md b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/commonjs-naming/doc/foo.md
new file mode 100644
index 0000000..c92ddb8
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/commonjs-naming/doc/foo.md
@@ -0,0 +1,5 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+I am documentation for foo.
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/commonjs-naming/lib/foo-loader.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/commonjs-naming/lib/foo-loader.js
new file mode 100644
index 0000000..2daeb35
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/commonjs-naming/lib/foo-loader.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/commonjs-naming/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/commonjs-naming/package.json
new file mode 100644
index 0000000..ccc61b2
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/commonjs-naming/package.json
@@ -0,0 +1,3 @@
+{
+ "loader": "lib/foo-loader.js"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/commonjs-naming/test/test-foo.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/commonjs-naming/test/test-foo.js
new file mode 100644
index 0000000..bd0cfa9
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/commonjs-naming/test/test-foo.js
@@ -0,0 +1,7 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.testThing = function(test) {
+ test.assertEqual(2, 1 + 1);
+};
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/original-naming/docs/foo.md b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/original-naming/docs/foo.md
new file mode 100644
index 0000000..c92ddb8
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/original-naming/docs/foo.md
@@ -0,0 +1,5 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+I am documentation for foo.
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/original-naming/lib/foo-loader.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/original-naming/lib/foo-loader.js
new file mode 100644
index 0000000..2daeb35
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/original-naming/lib/foo-loader.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/original-naming/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/original-naming/package.json
new file mode 100644
index 0000000..ccc61b2
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/original-naming/package.json
@@ -0,0 +1,3 @@
+{
+ "loader": "lib/foo-loader.js"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/original-naming/tests/test-foo.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/original-naming/tests/test-foo.js
new file mode 100644
index 0000000..bd0cfa9
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-614712-files/packages/original-naming/tests/test-foo.js
@@ -0,0 +1,7 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.testThing = function(test) {
+ test.assertEqual(2, 1 + 1);
+};
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/doc/foo.md b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/doc/foo.md
new file mode 100644
index 0000000..c92ddb8
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/doc/foo.md
@@ -0,0 +1,5 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+I am documentation for foo.
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/lib/foo.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/lib/foo.js
new file mode 100644
index 0000000..2daeb35
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/lib/foo.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/lib/loader.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/lib/loader.js
new file mode 100644
index 0000000..2daeb35
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/lib/loader.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/package.json
new file mode 100644
index 0000000..c2d22aa
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/package.json
@@ -0,0 +1,3 @@
+{
+ "loader": "lib/loader.js"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/test/test-foo.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/test/test-foo.js
new file mode 100644
index 0000000..bd0cfa9
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-lib/test/test-foo.js
@@ -0,0 +1,7 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.testThing = function(test) {
+ test.assertEqual(2, 1 + 1);
+};
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-locale/locale/emptyFolder b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-locale/locale/emptyFolder
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-locale/locale/emptyFolder
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-locale/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-locale/package.json
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-locale/package.json
@@ -0,0 +1 @@
+{}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/doc/foo.md b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/doc/foo.md
new file mode 100644
index 0000000..c92ddb8
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/doc/foo.md
@@ -0,0 +1,5 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+I am documentation for foo.
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/foo.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/foo.js
new file mode 100644
index 0000000..2daeb35
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/foo.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/loader.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/loader.js
new file mode 100644
index 0000000..2daeb35
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/loader.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/package.json
new file mode 100644
index 0000000..100249f
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/package.json
@@ -0,0 +1,3 @@
+{
+ "loader": "loader.js"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/test/test-foo.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/test/test-foo.js
new file mode 100644
index 0000000..bd0cfa9
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/default-root/test/test-foo.js
@@ -0,0 +1,7 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.testThing = function(test) {
+ test.assertEqual(2, 1 + 1);
+};
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/alt-lib/foo.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/alt-lib/foo.js
new file mode 100644
index 0000000..2daeb35
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/alt-lib/foo.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/alt-lib/loader.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/alt-lib/loader.js
new file mode 100644
index 0000000..2daeb35
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/alt-lib/loader.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/doc/foo.md b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/doc/foo.md
new file mode 100644
index 0000000..c92ddb8
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/doc/foo.md
@@ -0,0 +1,5 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+I am documentation for foo.
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/package.json
new file mode 100644
index 0000000..f79250e
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/package.json
@@ -0,0 +1,4 @@
+{
+ "directories": { "lib": "./alt-lib" },
+ "loader": "alt-lib/loader.js"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/test/test-foo.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/test/test-foo.js
new file mode 100644
index 0000000..bd0cfa9
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-dir-lib/test/test-foo.js
@@ -0,0 +1,7 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.testThing = function(test) {
+ test.assertEqual(2, 1 + 1);
+};
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/alt2-lib/foo.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/alt2-lib/foo.js
new file mode 100644
index 0000000..2daeb35
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/alt2-lib/foo.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/alt2-lib/loader.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/alt2-lib/loader.js
new file mode 100644
index 0000000..2daeb35
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/alt2-lib/loader.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/doc/foo.md b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/doc/foo.md
new file mode 100644
index 0000000..c92ddb8
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/doc/foo.md
@@ -0,0 +1,5 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+I am documentation for foo.
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/package.json
new file mode 100644
index 0000000..b017baa
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/package.json
@@ -0,0 +1,4 @@
+{
+ "lib": "./alt2-lib",
+ "loader": "alt2-lib/loader.js"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/test/test-foo.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/test/test-foo.js
new file mode 100644
index 0000000..bd0cfa9
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-652227-files/packages/explicit-lib/test/test-foo.js
@@ -0,0 +1,7 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.testThing = function(test) {
+ test.assertEqual(2, 1 + 1);
+};
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-669274-files/packages/extra-options/docs/main.md b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-669274-files/packages/extra-options/docs/main.md
new file mode 100644
index 0000000..54518d3
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-669274-files/packages/extra-options/docs/main.md
@@ -0,0 +1,5 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+minimal docs
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-669274-files/packages/extra-options/lib/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-669274-files/packages/extra-options/lib/main.js
new file mode 100644
index 0000000..aeda0e7
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-669274-files/packages/extra-options/lib/main.js
@@ -0,0 +1,8 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.main = function(options, callbacks) {
+ console.log("minimal");
+ callbacks.quit();
+};
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-669274-files/packages/extra-options/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-669274-files/packages/extra-options/package.json
new file mode 100644
index 0000000..de868f7
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-669274-files/packages/extra-options/package.json
@@ -0,0 +1,6 @@
+{
+ "name": "extra-options",
+ "author": "Jon Smith",
+ "description": "A package w/ a main module; can be built into an extension.",
+ "loader": "lib/main.js"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-715340-files/pkg-1-pack/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-715340-files/pkg-1-pack/package.json
new file mode 100644
index 0000000..d18aa3d
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-715340-files/pkg-1-pack/package.json
@@ -0,0 +1,10 @@
+{
+ "name": "empty",
+ "license": "MPL 2.0",
+ "author": "",
+ "version": "0.1",
+ "fullName": "empty",
+ "id": "jid1-80fr8b6qeRlQSQ",
+ "unpack": false,
+ "description": "test unpack= support"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-715340-files/pkg-2-unpack/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-715340-files/pkg-2-unpack/package.json
new file mode 100644
index 0000000..9bcf1eb
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-715340-files/pkg-2-unpack/package.json
@@ -0,0 +1,10 @@
+{
+ "name": "empty",
+ "license": "MPL 2.0",
+ "author": "",
+ "version": "0.1",
+ "fullName": "empty",
+ "id": "jid1-80fr8b6qeRlQSQ",
+ "unpack": true,
+ "description": "test unpack= support"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-715340-files/pkg-3-pack/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-715340-files/pkg-3-pack/package.json
new file mode 100644
index 0000000..45d1d91
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/bug-715340-files/pkg-3-pack/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "empty",
+ "license": "MPL 2.0",
+ "author": "",
+ "version": "0.1",
+ "fullName": "empty",
+ "id": "jid1-80fr8b6qeRlQSQ",
+ "description": "test unpack= support"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/e10s-adapter-files/packages/foo/lib/bar-e10s-adapter.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/e10s-adapter-files/packages/foo/lib/bar-e10s-adapter.js
new file mode 100644
index 0000000..ad54ae7
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/e10s-adapter-files/packages/foo/lib/bar-e10s-adapter.js
@@ -0,0 +1,11 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+if (this.sendMessage) {
+} else {
+ require('bar');
+
+ exports.register = function(process) {
+ };
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/e10s-adapter-files/packages/foo/lib/bar.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/e10s-adapter-files/packages/foo/lib/bar.js
new file mode 100644
index 0000000..fe9e4fb
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/e10s-adapter-files/packages/foo/lib/bar.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+require('chrome');
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/e10s-adapter-files/packages/foo/lib/foo.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/e10s-adapter-files/packages/foo/lib/foo.js
new file mode 100644
index 0000000..55633d1
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/e10s-adapter-files/packages/foo/lib/foo.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+require('bar');
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/e10s-adapter-files/packages/foo/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/e10s-adapter-files/packages/foo/package.json
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/e10s-adapter-files/packages/foo/package.json
@@ -0,0 +1 @@
+{}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/five/lib/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/five/lib/main.js
new file mode 100644
index 0000000..e32a30f
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/five/lib/main.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.main = "'main' mainly reigns in main(.js)";
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/five/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/five/package.json
new file mode 100644
index 0000000..98e4b85
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/five/package.json
@@ -0,0 +1,3 @@
+{ "name": "five",
+ "main": "./lib/main"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four-deps/four-a/lib/misc.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four-deps/four-a/lib/misc.js
new file mode 100644
index 0000000..7e1ce7e
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four-deps/four-a/lib/misc.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.main = 42;
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four-deps/four-a/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four-deps/four-a/package.json
new file mode 100644
index 0000000..3010fae
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four-deps/four-a/package.json
@@ -0,0 +1,4 @@
+{ "name": "four-a",
+ "directories": {"lib": "lib"},
+ "main": "./topfiles/main.js"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four-deps/four-a/topfiles/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four-deps/four-a/topfiles/main.js
new file mode 100644
index 0000000..7e1ce7e
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four-deps/four-a/topfiles/main.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.main = 42;
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four/lib/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four/lib/main.js
new file mode 100644
index 0000000..b95f7bd
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four/lib/main.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var a = require("four-a");
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four/package.json
new file mode 100644
index 0000000..53180b9
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/four/package.json
@@ -0,0 +1,3 @@
+{ "name": "four",
+ "main": "main"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/one/lib/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/one/lib/main.js
new file mode 100644
index 0000000..7b1f0de
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/one/lib/main.js
@@ -0,0 +1,9 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var panel = require("panel");
+var two = require("two.js");
+var a = require("./two");
+var b = require("addon-kit/tabs.js");
+var c = require("./subdir/three");
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/one/lib/subdir/three.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/one/lib/subdir/three.js
new file mode 100644
index 0000000..b594f3c
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/one/lib/subdir/three.js
@@ -0,0 +1,6 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.foo = 1;
+var main = require("../main");
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/one/lib/two.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/one/lib/two.js
new file mode 100644
index 0000000..9765219
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/one/lib/two.js
@@ -0,0 +1,8 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+// this ought to find our sibling, not packages/development-mode/lib/main.js
+var main = require("main");
+exports.foo = 1;
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/one/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/one/package.json
new file mode 100644
index 0000000..edd2b17
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/one/package.json
@@ -0,0 +1,4 @@
+{ "name": "one",
+ "id": "jid1@jetpack",
+ "main": "main"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/seven/data/text.data b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/seven/data/text.data
new file mode 100644
index 0000000..1269488
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/seven/data/text.data
@@ -0,0 +1 @@
+data
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/seven/lib/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/seven/lib/main.js
new file mode 100644
index 0000000..b860821
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/seven/lib/main.js
@@ -0,0 +1,6 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var self = require("self"); // trigger inclusion of data
+exports.main = function () { console.log("main"); };
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/seven/lib/unused.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/seven/lib/unused.js
new file mode 100644
index 0000000..a7b1c14
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/seven/lib/unused.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.unused = "just pretend I'm not here";
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/seven/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/seven/package.json
new file mode 100644
index 0000000..922c77d
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/seven/package.json
@@ -0,0 +1,4 @@
+{
+ "name": "seven",
+ "id": "jid7"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/six/lib/unused.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/six/lib/unused.js
new file mode 100644
index 0000000..ada31ef
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/six/lib/unused.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.unused = "I am.";
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/six/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/six/package.json
new file mode 100644
index 0000000..906b249
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/six/package.json
@@ -0,0 +1,3 @@
+{ "name": "six",
+ "main": "./unreachable"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/six/unreachable.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/six/unreachable.js
new file mode 100644
index 0000000..e8b229c
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/six/unreachable.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.main = "I am outside lib/ and cannot be reached, yet";
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/data/msg.txt b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/data/msg.txt
new file mode 100644
index 0000000..3b18e51
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/data/msg.txt
@@ -0,0 +1 @@
+hello world
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/data/subdir/submsg.txt b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/data/subdir/submsg.txt
new file mode 100644
index 0000000..d2cfe80
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/data/subdir/submsg.txt
@@ -0,0 +1 @@
+hello subdir
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/lib/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/lib/main.js
new file mode 100644
index 0000000..cee7380
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/lib/main.js
@@ -0,0 +1,8 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.main = 42;
+require("./subdir/subfile");
+require("self"); // trigger inclusion of our data/ directory
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/lib/subdir/subfile.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/lib/subdir/subfile.js
new file mode 100644
index 0000000..aec24d0
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/lib/subdir/subfile.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.main = "I should be included in a subdir";
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/lib/unused.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/lib/unused.js
new file mode 100644
index 0000000..36c4a4e
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/lib/unused.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.main = "unused, linker should not include me in the XPI";
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/locale/fr-FR.properties b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/locale/fr-FR.properties
new file mode 100644
index 0000000..980ac46
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/locale/fr-FR.properties
@@ -0,0 +1,5 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+Yes= Oui
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/package.json
new file mode 100644
index 0000000..6b796fc
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-a/package.json
@@ -0,0 +1,3 @@
+{ "name": "three-a",
+ "main": "./lib/main.js"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-b/lib/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-b/lib/main.js
new file mode 100644
index 0000000..7e1ce7e
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-b/lib/main.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.main = 42;
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-b/locale/fr-FR.properties b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-b/locale/fr-FR.properties
new file mode 100644
index 0000000..c1bf146
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-b/locale/fr-FR.properties
@@ -0,0 +1,6 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+No= Non
+one= un
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-b/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-b/package.json
new file mode 100644
index 0000000..c0ff5ee
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-b/package.json
@@ -0,0 +1,3 @@
+{ "name": "three-b",
+ "main": "./lib/main"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-c/lib/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-c/lib/main.js
new file mode 100644
index 0000000..7e1ce7e
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-c/lib/main.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.main = 42;
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-c/lib/sub/foo.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-c/lib/sub/foo.js
new file mode 100644
index 0000000..5878496
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-c/lib/sub/foo.js
@@ -0,0 +1,6 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.foo = "you found me down here";
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-c/locale/fr-FR.properties b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-c/locale/fr-FR.properties
new file mode 100644
index 0000000..dac3f13
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-c/locale/fr-FR.properties
@@ -0,0 +1,9 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+No= Nein
+What?= Quoi?
+plural=other
+plural[one]=one
+uft8_value=é
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-c/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-c/package.json
new file mode 100644
index 0000000..169c914
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three-deps/three-c/package.json
@@ -0,0 +1,3 @@
+{ "name": "three-c",
+ "main": "lib/main"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/lib/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/lib/main.js
new file mode 100644
index 0000000..4f59443
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/lib/main.js
@@ -0,0 +1,8 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var a = require("three-a");
+var b = require("three-b");
+var c = require("three-c");
+var c3 = require("three-c/sub/foo");
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/package.json
new file mode 100644
index 0000000..cbfbc5b
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/package.json
@@ -0,0 +1,3 @@
+{ "name": "three",
+ "main": "main"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/tests/nontest.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/tests/nontest.js
new file mode 100644
index 0000000..edbc08e
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/tests/nontest.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// dummy
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/tests/test-one.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/tests/test-one.js
new file mode 100644
index 0000000..edbc08e
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/tests/test-one.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// dummy
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/tests/test-two.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/tests/test-two.js
new file mode 100644
index 0000000..edbc08e
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/linker-files/three/tests/test-two.js
@@ -0,0 +1,5 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// dummy
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/preferences-files/packages/no-prefs/lib/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/preferences-files/packages/no-prefs/lib/main.js
new file mode 100644
index 0000000..b7e0a1d
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/preferences-files/packages/no-prefs/lib/main.js
@@ -0,0 +1,4 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/preferences-files/packages/no-prefs/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/preferences-files/packages/no-prefs/package.json
new file mode 100644
index 0000000..f1d51b0
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/preferences-files/packages/no-prefs/package.json
@@ -0,0 +1,6 @@
+{
+ "id": "jid1-fZHqN9JfrDBa8A",
+ "fullName": "No Prefs Test",
+ "author": "Erik Vold",
+ "loader": "lib/main.js"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/preferences-files/packages/simple-prefs/lib/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/preferences-files/packages/simple-prefs/lib/main.js
new file mode 100644
index 0000000..b7e0a1d
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/preferences-files/packages/simple-prefs/lib/main.js
@@ -0,0 +1,4 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/preferences-files/packages/simple-prefs/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/preferences-files/packages/simple-prefs/package.json
new file mode 100644
index 0000000..1b82728
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/preferences-files/packages/simple-prefs/package.json
@@ -0,0 +1,18 @@
+{
+ "id": "jid1-fZHqN9JfrDBa8A",
+ "fullName": "Simple Prefs Test",
+ "author": "Erik Vold",
+ "preferences": [{
+ "name": "test",
+ "type": "bool",
+ "title": "tëst",
+ "value": false
+ },
+ {
+ "name": "test2",
+ "type": "string",
+ "title": "tëst",
+ "value": "ünicødé"
+ }],
+ "loader": "lib/main.js"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/dev-guide-source/index.md b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/dev-guide-source/index.md
new file mode 100644
index 0000000..0f03259
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/dev-guide-source/index.md
@@ -0,0 +1,7 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+# An Imposing Title #
+
+*Some words!*
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/dev-guide-source/no_h1.md b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/dev-guide-source/no_h1.md
new file mode 100644
index 0000000..9859f33
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/dev-guide-source/no_h1.md
@@ -0,0 +1,7 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+## A heading ##
+
+*Some words!*
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/static-files/another.html b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/static-files/another.html
new file mode 100644
index 0000000..d40a2e8
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/static-files/another.html
@@ -0,0 +1,5 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+another file \ No newline at end of file
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/static-files/base.html b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/static-files/base.html
new file mode 100644
index 0000000..56c993d
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/static-files/base.html
@@ -0,0 +1,161 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+"http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en">
+<head>
+ <base >
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
+ <script type="text/javascript" src="static-files/syntaxhighlighter/scripts/shCore.js"></script>
+ <script type="text/javascript" src="static-files/syntaxhighlighter/scripts/shBrushCss.js"></script>
+ <script type="text/javascript" src="static-files/syntaxhighlighter/scripts/shBrushXml.js"></script>
+ <script type="text/javascript" src="static-files/syntaxhighlighter/scripts/shBrushJScript.js"></script>
+ <link rel="stylesheet" type="text/css" media="all" href="static-files/css/base.css">
+ <link rel="stylesheet" type="text/css" media="all" href="static-files/css/header.css">
+ <link rel="stylesheet" type="text/css" media="all" href="static-files/css/footer.css">
+ <link rel="stylesheet" type="text/css" media="all" href="static-files/css/sdk-docs.css">
+ <link rel="stylesheet" type="text/css" media="all" href="static-files/css/api-reference.css">
+ <link rel="stylesheet" type="text/css" href="static-files/syntaxhighlighter/styles/shCore.css">
+ <link rel="stylesheet" type="text/css" href="static-files/syntaxhighlighter/styles/shThemeDefault.css">
+ <!--[if IE]>
+ <style type="text/css">
+ .package-summary .module,
+ .package-entry .module,
+ .package-detail .module {
+ display: block;
+ }
+ </style>
+ <![endif]-->
+
+ <link rel="shortcut icon" type="image/x-icon" href="static-files/media/favicon.png">
+ <title></title>
+</head>
+<body>
+
+<header id="global-header">
+ <div class="funnel">
+ <a id="mozilla-tab" href="http://www.mozilla.org/?ref=logo">Mozilla</a>
+ <div class="menu">
+ <p>
+ <a href="https://builder.addons.mozilla.org/">Add-on Builder</a>
+ </p>
+ <p>
+ <a href="https://addons.mozilla.org/en-US/developers/">Developer Hub</a>
+ </p>
+ </div>
+</header>
+
+
+<header id="site-header">
+ <div class="funnel">
+ <h1>
+ <a href="dev-guide/welcome.html">Add-on SDK<span></span></a>
+ </h1>
+ <div id="version"></div>
+ </div>
+</header>
+
+ <div id="container">
+
+ <div id="columns">
+
+ <div id="main-content-column" class="column">
+ <div id="toc"></div>
+ <div id="main-content"></div>
+ </div>
+
+ <div id="sidebar" class="column">
+ <div class="sidebar-section" id="addon-development">
+ <h2 class="sidebar-section-header">Developer Guide</h2>
+ <ul class="sidebar-section-contents" id="default-section-contents">
+
+ <li class="sidebar-subsection">
+ <a href="dev-guide/tutorials/installation.html"><h3>Installation</h3></a>
+ </li>
+ <li class="sidebar-subsection">
+ <a href="dev-guide/tutorials/tutorials.html"><h3 class="sidebar-subsection-header">Tutorials</h3></a>
+ </li>
+
+ <li class="sidebar-subsection">
+ <a href="dev-guide/guides/index.html"><h3 class="sidebar-subsection-header">Guides</h3></a>
+ </li>
+
+ <li class="sidebar-subsection" id="third-party-packages-subsection">
+ <a href="dev-guide/third-party-apis.html"><h3 class="sidebar-subsection-header">Third-Party APIs</h3></a>
+ <div class="sidebar-subsection-contents">
+ <ul id="third-party-package-summaries"></ul>
+ </div>
+ </li>
+
+ <li class="sidebar-subsection">
+ <a href="dev-guide/high-level-apis.html"><h3 class="sidebar-subsection-header">High-Level APIs</h3></a>
+ <div class="sidebar-subsection-contents">
+ <ul id="high-level-package-summaries"></ul>
+ </div>
+ </li>
+
+ <li class="sidebar-subsection">
+ <h3 class="sidebar-subsection-header">Tools Reference</h3>
+ <div class="sidebar-subsection-contents">
+ <a href="dev-guide/console.html">console</a>
+ <a href="dev-guide/cfx-tool.html">cfx</a>
+ <a href="dev-guide/package-spec.html">package.json</a>
+ </div>
+ </li>
+
+ <li class="sidebar-subsection">
+ <a href="dev-guide/low-level-apis.html"><h3 class="sidebar-subsection-header">Low-Level APIs</h3></a>
+ <div class="sidebar-subsection-contents">
+ <ul id="low-level-package-summaries"></ul>
+ </div>
+ </li>
+
+ </ul>
+ </div>
+
+ <ul class="sidebar-section" id="appendices">
+ <li><a href="https://wiki.mozilla.org/Labs/Jetpack/Release_Notes"><h3>Release Notes</h3></a></li>
+ <li><a href="https://wiki.mozilla.org/Labs/Jetpack"><h3>Jetpack Wiki</h3></a></li>
+ <li><a href="dev-guide/glossary.html"><h3>Glossary</h3></a></li>
+ <li><a href="dev-guide/credits.html"><h3>Credits</h3></a></li>
+
+ </ul>
+<!--end of sidebar column-->
+ </div>
+<!--end of 'columns'-->
+<div class="clearfooter"></div>
+</div>
+</div>
+
+<div role="contentinfo" id="footer">
+ <div class="section">
+ <img alt="" src="static-files/media/footer-logo-med.png" class="footerlogo">
+ <div id="social-footer">
+ <ul>
+ <li>get to know <b>add-ons</b></li>
+ <li><a href="https://addons.mozilla.org/en-US/firefox/about">About</a></li>
+ <li><a href="http://blog.mozilla.com/addons">Blog</a></li>
+ <li class="footer-devhub-link"><a href="https://addons.mozilla.org/en-US/developers/">Developer Hub</a></li>
+ <li><a href="https://addons.mozilla.org/en-US/firefox/faq">FAQ</a></li>
+ <li><a href="https://forums.addons.mozilla.org">Forum</a></li>
+ </ul>
+ </div>
+
+ <div id="copyright">
+ <p id="footer-links">
+ <a href="http://mozilla.com/privacy-policy.html">Privacy Policy</a> &nbsp;|&nbsp;
+ <a href="http://mozilla.com/about/legal.html">Legal Notices</a> &nbsp;|&nbsp;
+ <a href="http://mozilla.com/legal/fraud-report/index.html">Report Trademark Abuse</a>
+ &nbsp;|&nbsp;<a href="https://addons.mozilla.org/z/en-US/developers/" class="mobile-link">View Mobile Site</a>
+ </p>
+ <p>
+ Except where otherwise <a href="http://mozilla.com/about/legal.html#site">noted</a>, content on this site is licensed under the <br> <a href="http://creativecommons.org/licenses/by-sa/3.0/"> Creative Commons Attribution Share-Alike License v3.0 </a> or any later version.
+ </p>
+ </div>
+ </div>
+</div>
+
+<script type="text/javascript" src="static-files/js/jquery.js"></script>
+<script type="text/javascript" src="static-files/js/main.js"></script>
+
+</body>
+
+</html>
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/static-files/index.html b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/static-files/index.html
new file mode 100644
index 0000000..1909a18
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/doc/static-files/index.html
@@ -0,0 +1,27 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<html>
+
+<head>
+
+ <title></title>
+
+</head>
+
+<body>
+
+<div id="left-column">
+
+<ul><li id="high-level-package-summaries"></li></ul>
+
+<ul><li id="low-level-package-summaries"></li></ul>
+
+</div>
+
+<div id="right-column"></div>
+
+</body>
+
+</html>
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/docs/APIreference.html b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/docs/APIreference.html
new file mode 100644
index 0000000..e302641
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/docs/APIreference.html
@@ -0,0 +1,469 @@
+
+<!DOCTYPE html>
+
+<html>
+
+<head>
+
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+
+ <base target="_blank"/>
+
+ <link rel="stylesheet" type="text/css" media="all"
+
+ href="../../../css/base.css" />
+
+ <link rel="stylesheet" type="text/css" media="all"
+
+ href="../../../css/apidocs.css" />
+
+ <title>Add-on SDK Documentation</title>
+
+ <style type="text/css">
+
+ body {
+
+ border: 50px solid #FFFFFF;
+
+ }
+
+ </style>
+
+
+
+ <script type="text/javascript">
+
+ function rewrite_links() {
+
+ var images = document.getElementsByTagName("img");
+
+ for (var i = 0; i < images.length; i++) {
+
+ var before = images[i].src.split("packages/")[0];
+
+ var after = images[i].src.split("/docs")[1];
+
+ images[i].src = before + after;
+
+ }
+
+ }
+
+ </script>
+
+</head>
+
+
+
+<body onload = "rewrite_links()">
+
+<div id="APIsample_module_api_docs" class="module_api_docs">
+ <h1>APIsample</h1>
+ <div class="module_description"><!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+ <h1>Title</h1>
+ <p>Some text here</p>
+ <p>This text appears between the API blocks.</p>
+ <p>Wooo, more text.</p>
+ <p>Some more text here, at the end of the file.</p>
+ </div>
+
+ <div class="api_reference">
+ <h2 class="api_header">API Reference</h2>
+
+ <div class="api_component_group">
+ <h3 class="api_header">Classes</h3>
+
+ <div class="api_component">
+ <h4 class="api_name">empty-class</h4>
+ <p>This class contains nothing.</p>
+ </div>
+
+ <div class="api_component">
+ <h4 class="api_name">only-one-ctor</h4>
+ <p>This class contains only one constructor.</p>
+ <div class="api_component_group">
+ <h5 class="api_header">Constructors</h5>
+
+ <div class="api_component">
+ <h6 class="api_name">one-constructor(options)</h6>
+
+ <div class="parameter_set">
+ <div class="api_component">
+ <div class="api_name">[ options ]</div>
+ <p>An object-bag of goodies.</p>
+ </div>
+
+ </div>
+
+ </div>
+
+ </div>
+
+ </div>
+
+ <div class="api_component">
+ <h4 class="api_name">two-ctors</h4>
+ <p>This class contains two constructors.</p>
+ <div class="api_component_group">
+ <h5 class="api_header">Constructors</h5>
+
+ <div class="api_component">
+ <h6 class="api_name">one-constructor(options)</h6>
+ <p>The first constructor.</p>
+ <div class="parameter_set">
+ <div class="api_component">
+ <div class="api_name">[ options ]</div>
+ <p>An object-bag of goodies.</p>
+ </div>
+
+ </div>
+
+ </div>
+
+ <div class="api_component">
+ <h6 class="api_name">another-constructor(options)</h6>
+ <p>The second constructor.</p>
+ <div class="parameter_set">
+ <div class="api_component">
+ <div class="api_name">[ options ]</div>
+ <p>An object-bag of goodies.</p>
+ </div>
+
+ </div>
+
+ </div>
+
+ </div>
+
+ </div>
+
+ <div class="api_component">
+ <h4 class="api_name">ctor-and-method</h4>
+ <p>This class contains one constructor and one method.</p>
+ <div class="api_component_group">
+ <h5 class="api_header">Constructors</h5>
+
+ <div class="api_component">
+ <h6 class="api_name">one-constructor(options)</h6>
+ <p>The first constructor.</p>
+ <div class="parameter_set">
+ <div class="api_component">
+ <div class="api_name">[ options ]</div>
+ <p>An object-bag of goodies.</p>
+ </div>
+
+ </div>
+
+ </div>
+
+ </div>
+
+ <div class="api_component_group">
+ <h5 class="api_header">Methods</h5>
+
+ <div class="api_component">
+ <h6 class="api_name">a-method(options)</h6>
+ <p>Does things.</p>
+ <div class="parameter_set">
+ <div class="api_component">
+ <div class="api_name">[ options ]</div>
+ <p>An argument.</p>
+ </div>
+
+ </div>
+
+ </div>
+
+ </div>
+
+ </div>
+
+ <div class="api_component">
+ <h4 class="api_name">ctor-method-prop-event</h4>
+ <p>This class contains one constructor, one method, one property and an event.</p>
+ <div class="api_component_group">
+ <h5 class="api_header">Constructors</h5>
+
+ <div class="api_component">
+ <h6 class="api_name">one-constructor(options)</h6>
+ <p>The first constructor.</p>
+ <div class="parameter_set">
+ <div class="api_component">
+ <div class="api_name">[ options ]</div>
+ <p>An object-bag of goodies.</p>
+ </div>
+
+ </div>
+
+ </div>
+
+ </div>
+
+ <div class="api_component_group">
+ <h5 class="api_header">Methods</h5>
+
+ <div class="api_component">
+ <h6 class="api_name">a-method(options)</h6>
+ <p>Does things.</p>
+ <div class="parameter_set">
+ <div class="api_component">
+ <div class="api_name">[ options ]</div>
+ <p>An argument.</p>
+ </div>
+
+ </div>
+
+ </div>
+
+ </div>
+
+ <div class="api_component_group">
+ <h5 class="api_header">Properties</h5>
+
+ <div class="api_component">
+ <h6 class="api_name">a-property : <span class="datatype">bool</span></h6>
+ <p>Represents stuff.</p>
+ </div>
+
+ </div>
+
+ <div class="api_component_group">
+ <h5 class="api_header">Events</h5>
+
+ <div class="api_component">
+ <h6 class="api_name">message</h6>
+ <p>Event emitted when the content script sends a message to the add-on.</p>
+ <div class="parameter_set">
+ <div class="api_component">
+ <div class="api_name"><span class="datatype">JSON</span></div>
+ <p>The message itself as a JSON-serialized object.</p>
+ </div>
+
+ </div>
+
+ </div>
+
+ </div>
+
+ </div>
+
+ </div>
+
+ <div class="api_component_group">
+ <h3 class="api_header">Functions</h3>
+
+ <div class="api_component">
+ <h4 class="api_name">test(argOne, argTwo, argThree, options)</h4>
+ <p>This is a function which does nothing in particular.</p>
+ <div class="parameter_set">
+ <div class="api_component">
+ <div class="api_name">argOne : <span class="datatype">string</span></div>
+ <p>This is the first argument.</p>
+ </div>
+
+ <div class="api_component">
+ <div class="api_name">[ argTwo : <span class="datatype">bool</span> ]</div>
+ <p>This is the second argument.</p>
+ </div>
+
+ <div class="api_component">
+ <div class="api_name">[ argThree = default : <span class="datatype">uri</span> ]</div>
+ <p>This is the third and final argument. And this is
+ a test of the ability to do multiple lines of
+ text.</p>
+ </div>
+
+ <div class="api_component">
+ <div class="api_name">[ options ]</div>
+ <p>Options Bag</p>
+ <div class="api_component">
+ <div class="api_name">[ style : <span class="datatype">string</span> ]</div>
+ <p>Some style information.</p>
+ </div>
+
+ <div class="api_component">
+ <div class="api_name">[ secondToLastOption = True : <span class="datatype">bool</span> ]</div>
+ <p>The last property.</p>
+ </div>
+
+ <div class="api_component">
+ <div class="api_name">[ lastOption : <span class="datatype">uri</span> ]</div>
+ <p>And this time we have
+ A multiline description
+ Written as haiku</p>
+ </div>
+
+ </div>
+
+ </div>
+
+ <div class="returns">Returns: <span class="datatype">object</span>
+ </div>
+
+ </div>
+
+ <div class="api_component">
+ <h4 class="api_name">append(options)</h4>
+ <p>This is a list of options to specify modifications to your slideBar instance.</p>
+ <div class="parameter_set">
+ <div class="api_component">
+ <div class="api_name">options</div>
+ <p>Pass in all of your options here.</p>
+ <div class="api_component">
+ <div class="api_name">[ icon : <span class="datatype">uri</span> ]</div>
+ <p>The HREF of an icon to show as the method of accessing your features slideBar</p>
+ </div>
+
+ <div class="api_component">
+ <div class="api_name">[ html : <span class="datatype">string/xml</span> ]</div>
+ <p>The content of the feature, either as an HTML string,
+ or an E4X document fragment.</p>
+ </div>
+
+ <div class="api_component">
+ <div class="api_name">[ url : <span class="datatype">uri</span> ]</div>
+ <p>The url to load into the content area of the feature</p>
+ </div>
+
+ <div class="api_component">
+ <div class="api_name">[ width : <span class="datatype">int</span> ]</div>
+ <p>Width of the content area and the selected slide size</p>
+ </div>
+
+ <div class="api_component">
+ <div class="api_name">[ persist : <span class="datatype">bool</span> ]</div>
+ <p>Default slide behavior when being selected as follows:
+ If true: blah; If false: double blah.</p>
+ </div>
+
+ <div class="api_component">
+ <div class="api_name">[ autoReload : <span class="datatype">bool</span> ]</div>
+ <p>Automatically reload content on select</p>
+ </div>
+
+ <div class="api_component">
+ <div class="api_name">[ onClick : <span class="datatype">function</span> ]</div>
+ <p>Callback when the icon is clicked</p>
+ </div>
+
+ <div class="api_component">
+ <div class="api_name">[ onSelect : <span class="datatype">function</span> ]</div>
+ <p>Callback when the feature is selected</p>
+ </div>
+
+ <div class="api_component">
+ <div class="api_name">[ onReady : <span class="datatype">function</span> ]</div>
+ <p>Callback when featured is loaded</p>
+ </div>
+
+ </div>
+
+ </div>
+
+ </div>
+
+ <div class="api_component">
+ <h4 class="api_name">cool-func.dot(howMuch, double, options, onemore, options2)</h4>
+
+ <div class="parameter_set">
+ <div class="api_component">
+ <div class="api_name">howMuch : <span class="datatype">string</span></div>
+ <p>How much cool it is.</p>
+ </div>
+
+ <div class="api_component">
+ <div class="api_name">[ double = true : <span class="datatype">bool</span> ]</div>
+ <p>In case you just really need to double it.</p>
+ </div>
+
+ <div class="api_component">
+ <div class="api_name">[ options ]</div>
+ <p>An object-bag of goodies.</p>
+ <div class="api_component">
+ <div class="api_name">callback : <span class="datatype">function</span></div>
+ <p>The callback</p>
+ </div>
+
+ <div class="api_component">
+ <div class="api_name">[ random : <span class="datatype">bool</span> ]</div>
+ <p>Do something random?</p>
+ </div>
+
+ </div>
+
+ <div class="api_component">
+ <div class="api_name">[ onemore : <span class="datatype">bool</span> ]</div>
+ <p>One more paramater</p>
+ </div>
+
+ <div class="api_component">
+ <div class="api_name">[ options2 ]</div>
+ <p>This is a full description of something
+ that really sucks. Because I now have a multiline
+ description of this thingy.</p>
+ <div class="api_component">
+ <div class="api_name">monkey : <span class="datatype">string</span></div>
+ <p>You heard me right</p>
+ </div>
+
+ <div class="api_component">
+ <div class="api_name">[ freak = true : <span class="datatype">bool</span> ]</div>
+ <p>Yes, you are a freak.</p>
+ </div>
+
+ </div>
+
+ </div>
+
+ <div class="returns">Returns: <span class="datatype">string</span><p>A value telling you just how cool you are.
+ A boa-constructor!
+ This description can go on for a while, and can even contain
+ some <strong>realy</strong> fancy things. Like <code>code</code>, or even
+ ~~~~{.javascript}
+ // Some code!
+ ~~~~</p>
+ </div>
+
+ </div>
+
+ <div class="api_component">
+ <h4 class="api_name">random()</h4>
+ <p>A function that returns a random integer between 0 and 10.</p>
+ <div class="returns">Returns: <span class="datatype">int</span><p>The random number.</p>
+ </div>
+
+ </div>
+
+ </div>
+
+ <div class="api_component_group">
+ <h3 class="api_header">Events</h3>
+
+ <div class="api_component">
+ <h4 class="api_name">open</h4>
+ <p>A module-level event called open.</p>
+ <div class="parameter_set">
+ <div class="api_component">
+ <div class="api_name"><span class="datatype">bool</span></div>
+ <p>Yes, it's open.</p>
+ </div>
+
+ </div>
+
+ </div>
+
+ </div>
+
+ </div>
+
+</div>
+
+</body>
+
+
+
+</html>
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/docs/APIsample.md b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/docs/APIsample.md
new file mode 100644
index 0000000..c5090c3
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/docs/APIsample.md
@@ -0,0 +1,162 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+# Title #
+
+Some text here
+
+<api name="test">
+@function
+This is a function which does nothing in particular.
+@returns {object}
+ @prop firststring {string} First string
+ @prop firsturl {url} First URL
+@param argOne {string} This is the first argument.
+@param [argTwo] {bool} This is the second argument.
+@param [argThree=default] {uri}
+ This is the third and final argument. And this is
+ a test of the ability to do multiple lines of
+ text.
+@param [options] Options Bag
+ @prop [style] {string} Some style information.
+ @prop [secondToLastOption=True] {bool} The last property.
+ @prop [lastOption] {uri}
+ And this time we have
+ A multiline description
+ Written as haiku
+</api>
+
+This text appears between the API blocks.
+
+<api name="append">
+@function
+This is a list of options to specify modifications to your slideBar instance.
+@param options
+ Pass in all of your options here.
+ @prop [icon] {uri} The HREF of an icon to show as the method of accessing your features slideBar
+ @prop [html] {string/xml}
+ The content of the feature, either as an HTML string,
+ or an E4X document fragment.
+ @prop [url] {uri} The url to load into the content area of the feature
+ @prop [width] {int} Width of the content area and the selected slide size
+ @prop [persist] {bool}
+ Default slide behavior when being selected as follows:
+ If true: blah; If false: double blah.
+ @prop [autoReload] {bool} Automatically reload content on select
+ @prop [onClick] {function} Callback when the icon is clicked
+ @prop [onSelect] {function} Callback when the feature is selected
+ @prop [onReady] {function} Callback when featured is loaded
+</api>
+
+Wooo, more text.
+
+<api name="cool-func.dot">
+@function
+@returns {string} A value telling you just how cool you are.
+A boa-constructor!
+This description can go on for a while, and can even contain
+some **realy** fancy things. Like `code`, or even
+~~~~{.javascript}
+// Some code!
+~~~~
+@param howMuch {string} How much cool it is.
+@param [double=true] {bool}
+ In case you just really need to double it.
+@param [options] An object-bag of goodies.
+ @prop callback {function} The callback
+ @prop [random] {bool} Do something random?
+@param [onemore] {bool} One more paramater
+@param [options2]
+ This is a full description of something
+ that really sucks. Because I now have a multiline
+ description of this thingy.
+ @prop monkey {string} You heard me right
+ @prop [freak=true] {bool}
+ Yes, you are a freak.
+</api>
+
+<api name="random">
+@function
+A function that returns a random integer between 0 and 10.
+@returns {int} The random number.
+</api>
+
+<api name="empty-class">
+@class
+This class contains nothing.
+</api>
+
+<api name="only-one-ctor">
+@class
+This class contains only one constructor.
+<api name="one-constructor">
+@constructor
+@param [options] An object-bag of goodies.
+</api>
+</api>
+
+<api name="two-ctors">
+@class
+This class contains two constructors.
+<api name="one-constructor">
+@constructor
+The first constructor.
+@param [options] An object-bag of goodies.
+</api>
+<api name="another-constructor">
+@constructor
+The second constructor.
+@param [options] An object-bag of goodies.
+</api>
+</api>
+
+<api name="ctor-and-method">
+@class
+This class contains one constructor and one method.
+<api name="one-constructor">
+@constructor
+The first constructor.
+@param [options] An object-bag of goodies.
+</api>
+<api name="a-method">
+@method
+Does things.
+@param [options] An argument.
+</api>
+</api>
+
+<api name="ctor-method-prop-event">
+@class
+This class contains one constructor, one method, one property and an event.
+<api name="one-constructor">
+@constructor
+The first constructor.
+@param [options] An object-bag of goodies.
+</api>
+<api name="a-method">
+@method
+Does things.
+@param [options] An argument.
+</api>
+<api name="a-property">
+@property {bool}
+Represents stuff.
+</api>
+<api name="message">
+@event
+Event emitted when the content script sends a message to the add-on.
+@argument {JSON}
+The message itself as a JSON-serialized object.
+</api>
+</api>
+
+<api name="open">
+@event
+A module-level event called open.
+@argument {bool}
+Yes, it's open.
+</api>
+
+Some more text here, at the end of the file.
+
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/doc/aardvark-feeder.md b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/doc/aardvark-feeder.md
new file mode 100644
index 0000000..3845955
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/doc/aardvark-feeder.md
@@ -0,0 +1,12 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+The `aardvark-feeder` module simplifies feeding aardvarks.
+
+<api name="feed">
+@function
+ Feed the aardvark.
+@param food {string}
+ The food. Aardvarks will eat anything.
+</api>
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/doc/main.md b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/doc/main.md
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/doc/main.md
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/lib/ignore_me b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/lib/ignore_me
new file mode 100644
index 0000000..014242c
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/lib/ignore_me
@@ -0,0 +1,3 @@
+The docs processor should tolerate (by ignoring) random non-.js files in lib
+directories, such as those left around by editors, version-control systems,
+or OS metadata like .DS_Store . This file exercises that tolerance.
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/lib/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/lib/main.js
new file mode 100644
index 0000000..0264872
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/lib/main.js
@@ -0,0 +1,8 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.main = function(options, callbacks) {
+ console.log("1 + 1 =", require("bar-module").add(1, 1));
+ callbacks.quit();
+};
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/lib/surprise.js/ignore_me_too b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/lib/surprise.js/ignore_me_too
new file mode 100644
index 0000000..066f9b5
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/lib/surprise.js/ignore_me_too
@@ -0,0 +1,2 @@
+The docs processor should also ignore directories named *.js, and their
+contents.
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/package.json
new file mode 100644
index 0000000..07eb9b9
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/aardvark/package.json
@@ -0,0 +1,7 @@
+{
+ "author": "Jon Smith",
+ "description": "A package w/ a main module; can be built into an extension.",
+ "keywords": ["potato"],
+ "version": "1.0",
+ "dependencies": ["api-utils", "barbeque"]
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/anteater_files/lib/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/anteater_files/lib/main.js
new file mode 100644
index 0000000..0264872
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/anteater_files/lib/main.js
@@ -0,0 +1,8 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.main = function(options, callbacks) {
+ console.log("1 + 1 =", require("bar-module").add(1, 1));
+ callbacks.quit();
+};
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/anteater_files/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/anteater_files/package.json
new file mode 100644
index 0000000..0e2b552
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/anteater_files/package.json
@@ -0,0 +1,8 @@
+{
+ "name": "anteater",
+ "author": "Jon Smith",
+ "description": "A package w/ a main module; can be built into an extension.",
+ "keywords": ["potato"],
+ "version": "1.0",
+ "dependencies": ["api-utils", "barbeque"]
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/api-utils/lib/loader.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/api-utils/lib/loader.js
new file mode 100644
index 0000000..361846d
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/api-utils/lib/loader.js
@@ -0,0 +1,7 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// This module will be imported by the XPCOM harness/boostrapper
+// via Components.utils.import() and is responsible for creating a
+// CommonJS module loader.
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/api-utils/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/api-utils/package.json
new file mode 100644
index 0000000..64eb065
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/api-utils/package.json
@@ -0,0 +1,5 @@
+{
+ "description": "A foundational package that provides a CommonJS module loader implementation.",
+ "keywords": ["potato", "jetpack-low-level"],
+ "loader": "lib/loader.js"
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/barbeque/lib/bar-module.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/barbeque/lib/bar-module.js
new file mode 100644
index 0000000..ff982ae
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/barbeque/lib/bar-module.js
@@ -0,0 +1,7 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.add = function add(a, b) {
+ return a + b;
+};
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/barbeque/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/barbeque/package.json
new file mode 100644
index 0000000..62e3c12
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/barbeque/package.json
@@ -0,0 +1,4 @@
+{
+ "keywords": ["potato", "jetpack-low-level"],
+ "description": "A package used by 'aardvark' as a library."
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/minimal/docs/main.md b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/minimal/docs/main.md
new file mode 100644
index 0000000..54518d3
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/minimal/docs/main.md
@@ -0,0 +1,5 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+minimal docs
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/minimal/lib/main.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/minimal/lib/main.js
new file mode 100644
index 0000000..aeda0e7
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/minimal/lib/main.js
@@ -0,0 +1,8 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+exports.main = function(options, callbacks) {
+ console.log("minimal");
+ callbacks.quit();
+};
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/minimal/package.json b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/minimal/package.json
new file mode 100644
index 0000000..530f3c2
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/packages/minimal/package.json
@@ -0,0 +1,4 @@
+{
+ "author": "Jon Smith",
+ "description": "A package w/ a main module; can be built into an extension."
+}
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/xpi-template/components/harness.js b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/xpi-template/components/harness.js
new file mode 100644
index 0000000..a20bf3f
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/static-files/xpi-template/components/harness.js
@@ -0,0 +1,8 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// This file contains XPCOM code that bootstraps an SDK-based add-on
+// by loading its harness-options.json, registering all its resource
+// directories, executing its loader, and then executing its program's
+// main() function.
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_apiparser.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_apiparser.py
new file mode 100644
index 0000000..c24f5c3
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_apiparser.py
@@ -0,0 +1,538 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+import os
+import unittest
+from cuddlefish.docs.apiparser import parse_hunks, ParseError
+
+tests_path = os.path.abspath(os.path.dirname(__file__))
+static_files_path = os.path.join(tests_path, "static-files")
+
+class ParserTests(unittest.TestCase):
+ def pathname(self, filename):
+ return os.path.join(static_files_path, "docs", filename)
+
+ def parse_text(self, text):
+ return list(parse_hunks(text))
+
+ def parse(self, pathname):
+ return self.parse_text(open(pathname).read())
+
+ def test_parser(self):
+ parsed = self.parse(self.pathname("APIsample.md"))
+ #for i,h in enumerate(parsed):
+ # print i, h
+ self.assertEqual(parsed[0],
+ ("version", 4))
+ self.assertEqual(parsed[1],
+ ("markdown", """\
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+# Title #
+
+Some text here
+
+"""))
+
+ self.assertEqual(parsed[2][0], "api-json")
+ p_test = parsed[2][1]
+ self.assertEqual(p_test["name"], "test")
+ self.assertEqual(p_test["type"], "function")
+ self.assertEqual(p_test["signature"], "test(argOne, argTwo, \
+argThree, options)")
+ self.assertEqual(p_test["description"],
+ "This is a function which does nothing in \
+particular.")
+ r = p_test["returns"]
+ self.assertEqual(r["datatype"], "object")
+ self.assertEqual(r["description"], "")
+ self.assertEqual(len(r["props"]), 2)
+ self.assertEqual(r["props"][0]["datatype"], "string")
+ self.assertEqual(r["props"][0]["description"], "First string")
+ self.assertEqual(r["props"][1]["datatype"], "url")
+ self.assertEqual(r["props"][1]["description"], "First URL")
+
+ self.assertEqual(p_test["params"][0],
+ {"name": "argOne",
+ "required": True,
+ "datatype": "string",
+ "description": "This is the first argument.",
+ "line_number": 15,
+ })
+
+ self.assertEqual(p_test["params"][1],
+ {"name": "argTwo",
+ "required": False,
+ "datatype": "bool",
+ "description": "This is the second argument.",
+ "line_number": 16,
+ })
+
+ self.assertEqual(p_test["params"][2],
+ {"name": "argThree",
+ "required": False,
+ "default": "default",
+ "datatype": "uri",
+ "line_number": 17,
+ "description": """\
+This is the third and final argument. And this is
+a test of the ability to do multiple lines of
+text.""",
+ })
+ p3 = p_test["params"][3]
+ self.assertEqual(p3["name"], "options")
+ self.assertEqual(p3["required"], False)
+ self.failIf("type" in p3)
+ self.assertEqual(p3["description"], "Options Bag")
+ self.assertEqual(p3["props"][0],
+ {"name": "style",
+ "required": False,
+ "datatype": "string",
+ "description": "Some style information.",
+ "line_number": 22,
+ })
+ self.assertEqual(p3["props"][1],
+ {"name": "secondToLastOption",
+ "required": False,
+ "default": "True",
+ "datatype": "bool",
+ "description": "The last property.",
+ "line_number": 23,
+ })
+ self.assertEqual(p3["props"][2]["name"], "lastOption")
+ self.assertEqual(p3["props"][2]["required"], False)
+ self.assertEqual(p3["props"][2]["datatype"], "uri")
+ self.assertEqual(p3["props"][2]["description"], """\
+And this time we have
+A multiline description
+Written as haiku""")
+
+ self.assertEqual(parsed[3][0], "markdown")
+ self.assertEqual(parsed[3][1], "\n\nThis text appears between the \
+API blocks.\n\n")
+
+ self.assertEqual(parsed[4][0], "api-json")
+ p_test = parsed[4][1]
+
+ expected = {'line_number': 32,
+ 'name': 'append',
+ 'params': [{'props':[{'line_number': 37,
+ 'required': False,
+ 'datatype': 'uri',
+ 'name': 'icon',
+ 'description': 'The HREF of an icon to show as the \
+method of accessing your features slideBar'},
+ {'line_number': 38,
+ 'required': False,
+ 'datatype': 'string/xml',
+ 'name': 'html',
+ 'description': 'The content of the feature, either \
+as an HTML string,\nor an E4X document fragment.'},
+ {'line_number': 41,
+ 'required': False,
+ 'datatype': 'uri',
+ 'name': 'url',
+ 'description': 'The url to load into the content area \
+of the feature'},
+ {'line_number': 42,
+ 'required': False,
+ 'datatype': 'int',
+ 'name': 'width',
+ 'description': 'Width of the content area and the \
+selected slide size'},
+ {'line_number': 43,
+ 'required': False,
+ 'datatype': 'bool',
+ 'name': 'persist',
+ 'description': 'Default slide behavior when being \
+selected as follows:\nIf true: blah; If false: double blah.'},
+ {'line_number': 46,
+ 'required': False,
+ 'datatype': 'bool',
+ 'name': 'autoReload',
+ 'description': 'Automatically reload content on \
+select'},
+ {'line_number': 47,
+ 'required': False,
+ 'datatype': 'function',
+ 'name': 'onClick',
+ 'description': 'Callback when the icon is \
+clicked'},
+ {'line_number': 48,
+ 'required': False,
+ 'datatype': 'function',
+ 'name': 'onSelect',
+ 'description': 'Callback when the feature is selected'},
+ {'line_number': 49,
+ 'required': False,
+ 'datatype': 'function',
+ 'name': 'onReady',
+ 'description':
+ 'Callback when featured is loaded'}],
+ 'line_number': 35,
+ 'required': True,
+ 'name': 'options',
+ 'description': 'Pass in all of your options here.'}],
+ 'signature': 'append(options)',
+ 'type': 'function',
+ 'description': 'This is a list of options to specify modifications to your \
+slideBar instance.'}
+ self.assertEqual(p_test, expected)
+
+ self.assertEqual(parsed[6][0], "api-json")
+ p_test = parsed[6][1]
+ self.assertEqual(p_test["name"], "cool-func.dot")
+ self.assertEqual(p_test["signature"], "cool-func.dot(howMuch, double, \
+options, onemore, options2)")
+ self.assertEqual(p_test["returns"]["description"],
+ """\
+A value telling you just how cool you are.
+A boa-constructor!
+This description can go on for a while, and can even contain
+some **realy** fancy things. Like `code`, or even
+~~~~{.javascript}
+// Some code!
+~~~~""")
+ self.assertEqual(p_test["params"][2]["props"][0],
+ {"name": "callback",
+ "required": True,
+ "datatype": "function",
+ "line_number": 67,
+ "description": "The callback",
+ })
+ self.assertEqual(p_test["params"][2]["props"][1],
+ {"name": "random",
+ "required": False,
+ "datatype": "bool",
+ "line_number": 68,
+ "description": "Do something random?",
+ })
+
+ p_test = parsed[8][1]
+ self.assertEqual(p_test["signature"],"random()")
+
+ # tests for classes
+ #1) empty class
+ p_test = parsed[10][1]
+ self.assertEqual(len(p_test), 4)
+ self.assertEqual(p_test["name"], "empty-class")
+ self.assertEqual(p_test["description"], "This class contains nothing.")
+ self.assertEqual(p_test["type"], "class")
+ # 2) class with just one ctor
+ p_test = parsed[12][1]
+ self.assertEqual(len(p_test), 5)
+ self.assertEqual(p_test["name"], "only-one-ctor")
+ self.assertEqual(p_test["description"], "This class contains only \
+one constructor.")
+ self.assertEqual(p_test["type"], "class")
+ constructors = p_test["constructors"]
+ self.assertEqual(len(constructors), 1)
+ self._test_class_constructor(constructors[0], "one-constructor")
+ # 3) class with 2 ctors
+ p_test = parsed[14][1]
+ self.assertEqual(len(p_test), 5)
+ self.assertEqual(p_test["name"], "two-ctors")
+ self.assertEqual(p_test["description"], "This class contains two \
+constructors.")
+ self.assertEqual(p_test["type"], "class")
+ constructors = p_test["constructors"]
+ self.assertEqual(len(constructors), 2)
+ self._test_class_constructor(constructors[0], "one-constructor")
+ self._test_class_constructor(constructors[1], "another-constructor")
+ # 4) class with ctor + method
+ p_test = parsed[16][1]
+ self.assertEqual(len(p_test), 6)
+ self.assertEqual(p_test["name"], "ctor-and-method")
+ self.assertEqual(p_test["description"], "This class contains one \
+constructor and one method.")
+ self.assertEqual(p_test["type"], "class")
+ constructors = p_test["constructors"]
+ self.assertEqual(len(constructors), 1)
+ self._test_class_constructor(constructors[0], "one-constructor")
+ methods = p_test["methods"]
+ self.assertEqual(len(methods), 1)
+ self._test_class_method(methods[0])
+ # 5) class with ctor + method + property
+ p_test = parsed[18][1]
+ self.assertEqual(len(p_test), 8)
+ self.assertEqual(p_test["name"], "ctor-method-prop-event")
+ self.assertEqual(p_test["description"], "This class contains one \
+constructor, one method, one property and an event.")
+ self.assertEqual(p_test["type"], "class")
+ constructors = p_test["constructors"]
+ self.assertEqual(len(constructors), 1)
+ self._test_class_constructor(constructors[0], "one-constructor")
+ methods = p_test["methods"]
+ self.assertEqual(len(methods), 1)
+ self._test_class_method(methods[0])
+ properties = p_test["properties"]
+ self.assertEqual(len(properties), 1)
+ self._test_class_property(properties[0])
+ events = p_test["events"]
+ self.assertEqual(len(events), 1)
+ self._test_class_event(events[0])
+
+ self.assertEqual(parsed[-1][0], "markdown")
+ self.assertEqual(parsed[-1][1], "\n\nSome more text here, \
+at the end of the file.\n\n")
+
+ def _test_class_constructor(self, constructor, name):
+ self.assertEqual(constructor["type"], "constructor")
+ self.assertEqual(constructor["name"], name)
+ params = constructor["params"]
+ self.assertEqual(len(params), 1)
+ self.assertEqual(params[0]["name"], "options")
+ self.assertEqual(params[0]["description"], "An object-bag of goodies.")
+
+ def _test_class_method(self, method):
+ self.assertEqual(method["type"], "method")
+ self.assertEqual(method["name"], "a-method")
+ self.assertEqual(method["description"], "Does things.")
+ params = method["params"]
+ self.assertEqual(len(params), 1)
+ self.assertEqual(params[0]["name"], "options")
+ self.assertEqual(params[0]["description"], "An argument.")
+
+ def _test_class_property(self, prop):
+ self.assertEqual(prop["type"], "property")
+ self.assertEqual(prop["name"], "a-property")
+ self.assertEqual(prop["description"], "Represents stuff.")
+ self.assertEqual(prop["datatype"], "bool")
+
+ def _test_class_event(self, event):
+ self.assertEqual(event["type"], "event")
+ self.assertEqual(event["name"], "message")
+ self.assertEqual(event["description"], "Event emitted when the \
+content script sends a message to the add-on.")
+ arguments = event["arguments"]
+ self.assertEqual(len(arguments), 1)
+ argument = arguments[0]
+ self.assertEqual(argument["datatype"], "JSON")
+ self.assertEqual(argument["description"], "The message itself as a \
+JSON-serialized object.")
+
+ def test_missing_return_propname(self):
+ md = '''\
+<api name="test">
+@method
+This is a function which does nothing in particular.
+@returns {object}
+ @prop {string} First string, but the property name is missing
+ @prop {url} First URL, same problem
+@param argOne {string} This is the first argument.
+</api>
+'''
+ self.assertRaises(ParseError, self.parse_text, md)
+
+ def test_missing_return_proptype(self):
+ md = '''\
+<api name="test">
+@method
+This is a function which does nothing in particular.
+@returns {object}
+ @prop untyped It is an error to omit the type of a return property.
+@param argOne {string} This is the first argument.
+@param [argTwo=True] {bool} This is the second argument.
+</api>
+'''
+ self.assertRaises(ParseError, self.parse_text, md)
+
+ def test_return_propnames(self):
+ md = '''\
+<api name="test">
+@method
+This is a function which does nothing in particular.
+@returns {object}
+ @prop firststring {string} First string.
+ @prop [firsturl] {url} First URL, not always provided.
+@param argOne {string} This is the first argument.
+@param [argTwo=True] {bool} This is the second argument.
+</api>
+'''
+ parsed = self.parse_text(md)
+ r = parsed[1][1]["returns"]
+ self.assertEqual(r["props"][0]["name"], "firststring")
+ self.assertEqual(r["props"][0],
+ {"name": "firststring",
+ "datatype": "string",
+ "description": "First string.",
+ "required": True,
+ "line_number": 5, # 1-indexed
+ })
+ self.assertEqual(r["props"][1],
+ {"name": "firsturl",
+ "datatype": "url",
+ "description": "First URL, not always provided.",
+ "required": False,
+ "line_number": 6,
+ })
+
+ def test_return_description_1(self):
+ md = '''\
+<api name="test">
+@method
+This is a function which does nothing in particular.
+@returns {object} A one-line description.
+ @prop firststring {string} First string.
+ @prop [firsturl] {url} First URL, not always provided.
+@param argOne {string} This is the first argument.
+@param [argTwo=True] {bool} This is the second argument.
+</api>
+'''
+ parsed = self.parse_text(md)
+ r = parsed[1][1]["returns"]
+ self.assertEqual(r["description"], "A one-line description.")
+
+ def test_return_description_2(self):
+ md = '''\
+<api name="test">
+@method
+This is a function which does nothing in particular.
+@returns {object} A six-line description
+ which is consistently indented by two spaces
+ except for this line
+ and preserves the following empty line
+
+ from which a two-space indentation will be removed.
+ @prop firststring {string} First string.
+ @prop [firsturl] {url} First URL, not always provided.
+@param argOne {string} This is the first argument.
+@param [argTwo=True] {bool} This is the second argument.
+</api>
+'''
+ parsed = self.parse_text(md)
+ r = parsed[1][1]["returns"]
+ self.assertEqual(r["description"],
+ "A six-line description\n"
+ "which is consistently indented by two spaces\n"
+ " except for this line\n"
+ "and preserves the following empty line\n"
+ "\n"
+ "from which a two-space indentation will be removed.")
+
+ def test_return_description_3(self):
+ md = '''\
+<api name="test">
+@method
+This is a function which does nothing in particular.
+@returns A one-line untyped description.
+@param argOne {string} This is the first argument.
+@param [argTwo=True] {bool} This is the second argument.
+</api>
+'''
+ parsed = self.parse_text(md)
+ r = parsed[1][1]["returns"]
+ self.assertEqual(r["description"], "A one-line untyped description.")
+
+ # if the return value was supposed to be an array, the correct syntax
+ # would not have any @prop tags:
+ # @returns {array}
+ # Array consists of two elements, a string and a url...
+
+ def test_return_array(self):
+ md = '''\
+<api name="test">
+@method
+This is a function which returns an array.
+@returns {array}
+ Array consists of two elements, a string and a url.
+@param argOne {string} This is the first argument.
+@param [argTwo=True] {bool} This is the second argument.
+</api>
+'''
+ parsed = self.parse_text(md)
+ r = parsed[1][1]["returns"]
+ self.assertEqual(r["description"],
+ "Array consists of two elements, a string and a url.")
+
+ def test_bad_default_on_required_parameter(self):
+ md = '''\
+<api name="test">
+@method
+This is a function which does nothing in particular.
+@returns something
+@param argOne=ILLEGAL {string} Mandatory parameters do not take defaults.
+@param [argTwo=Chicago] {string} This is the second argument.
+</api>
+'''
+ self.assertRaises(ParseError, self.parse_text, md)
+
+ def test_missing_apitype(self):
+ md = '''\
+<api name="test">
+Sorry, you must have a @method or something before the description.
+Putting it after the description is not good enough
+@method
+@returns something
+</api>
+'''
+ self.assertRaises(ParseError, self.parse_text, md)
+
+ def test_missing_param_propname(self):
+ md = '''\
+<api name="test">
+@method
+This is a function which does nothing in particular.
+@param p1 {object} This is a parameter.
+ @prop {string} Oops, props must have a name.
+</api>
+'''
+ self.assertRaises(ParseError, self.parse_text, md)
+
+ def test_missing_param_proptype(self):
+ md = '''\
+<api name="test">
+@method
+This is a function which does nothing in particular.
+@param p1 {object} This is a parameter.
+ @prop name Oops, props must have a type.
+</api>
+'''
+ self.assertRaises(ParseError, self.parse_text, md)
+
+ def test_property(self):
+ md = '''\
+<api name="test">
+@property {foo}
+An object property named test of type foo.
+</api>
+'''
+ parsed = self.parse_text(md)
+ self.assertEqual(parsed[1][0], 'api-json')
+ actual_api_json_obj = parsed[1][1]
+ expected_api_json_obj = {
+ 'line_number': 1,
+ 'datatype': 'foo',
+ 'type': 'property',
+ 'name': 'test',
+ 'description': "An object property named test of type foo."
+ }
+ self.assertEqual(actual_api_json_obj, expected_api_json_obj)
+
+ def test_property_no_type(self):
+ md = '''\
+<api name="test">
+@property
+This property needs to specify a type!
+</api>
+'''
+ self.assertRaises(ParseError, self.parse_text, md)
+
+ def test_missing_api_closing_tag(self):
+ md = '''\
+<api name="test">
+@class
+This is a class with a missing closing tag.
+<api name="doStuff"
+@method
+This method does stuff.
+</api>
+'''
+ self.assertRaises(ParseError, self.parse_text, md)
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_apirenderer.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_apirenderer.py
new file mode 100644
index 0000000..24a1c7c
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_apirenderer.py
@@ -0,0 +1,31 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+import os
+import unittest
+from cuddlefish.docs.apirenderer import md_to_html
+
+tests_path = os.path.abspath(os.path.dirname(__file__))
+static_files_path = os.path.join(tests_path, "static-files")
+
+class ParserTests(unittest.TestCase):
+ def pathname(self, filename):
+ return os.path.join(static_files_path, "docs", filename)
+
+ def render_markdown(self, pathname):
+ return md_to_html(pathname)
+
+ def test_renderer(self):
+ test = self.render_markdown(self.pathname("APIsample.md"))
+ reference = open(self.pathname("APIreference.html")).read()
+ test_lines = test.splitlines(True)
+ reference_lines = reference.splitlines(True)
+ for x in range(len(test_lines)):
+ self.assertEqual(test_lines[x], reference_lines[x],
+ "line %d: expected '%s', got '%s'"
+ % (x+1, reference_lines[x], test_lines[x]))
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_generate.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_generate.py
new file mode 100644
index 0000000..ce5665e
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_generate.py
@@ -0,0 +1,173 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import shutil
+import unittest
+import StringIO
+import tarfile
+import HTMLParser
+import urlparse
+import urllib
+
+from cuddlefish.docs import generate
+from cuddlefish.tests import env_root
+
+INITIAL_FILESET = [ ["static-files", "base.html"], \
+ ["dev-guide", "index.html"], \
+ ["packages", "aardvark", "index.html"] ]
+
+EXTENDED_FILESET = [ ["static-files", "base.html"], \
+ ["dev-guide", "extra.html"], \
+ ["dev-guide", "index.html"], \
+ ["packages", "aardvark", "index.html"] ]
+
+EXTRAFILE = ["dev-guide", "extra.html"]
+
+def get_test_root():
+ return os.path.join(env_root, "python-lib", "cuddlefish", "tests", "static-files")
+
+def get_sdk_docs_root():
+ return os.path.join(get_test_root(), "sdk-docs")
+
+def get_base_url_path():
+ return os.path.join(get_sdk_docs_root(), "doc")
+
+def url_from_path(path):
+ path = path.lstrip("/")
+ return "file://"+"/"+"/".join(path.split(os.sep))+"/"
+
+def get_base_url():
+ return url_from_path(get_base_url_path())
+
+class Link_Checker(HTMLParser.HTMLParser):
+ def __init__(self, tester, filename, base_url):
+ HTMLParser.HTMLParser.__init__(self)
+ self.tester = tester
+ self.filename = filename
+ self.base_url = base_url
+ self.errors = []
+
+ def handle_starttag(self, tag, attrs):
+ link = self.find_link(attrs)
+ if link:
+ self.validate_link(link)
+
+ def handle_startendtag(self, tag, attrs):
+ link = self.find_link(attrs)
+ if link:
+ self.validate_link(link)
+
+ def find_link(self, attrs):
+ attrs = dict(attrs)
+ href = attrs.get('href', '')
+ if href:
+ parsed = urlparse.urlparse(href)
+ if not parsed.scheme:
+ return href
+ src = attrs.get('src', '')
+ if src:
+ parsed = urlparse.urlparse(src)
+ if not parsed.scheme:
+ return src
+
+ def validate_link(self, link):
+ parsed = urlparse.urlparse(link)
+ # there should not be any file:// URLs
+ self.tester.assertNotEqual(parsed.scheme, "file")
+ # any other absolute URLs will not be checked
+ if parsed.scheme:
+ return
+ current_path_as_url = url_from_path(os.path.dirname(self.filename))
+ # otherwise try to open the file at: baseurl + path
+ absolute_url = current_path_as_url + parsed.path
+ try:
+ urllib.urlopen(absolute_url)
+ except IOError:
+ self.errors.append(self.filename + "\n " + absolute_url)
+
+class Generate_Docs_Tests(unittest.TestCase):
+
+ def test_generate_static_docs(self):
+ # make sure we start clean
+ if os.path.exists(get_base_url_path()):
+ shutil.rmtree(get_base_url_path())
+ # generate a doc tarball, and extract it
+ base_url = get_base_url()
+ tar_filename = generate.generate_static_docs(env_root)
+ tgz = tarfile.open(tar_filename)
+ tgz.extractall(get_sdk_docs_root())
+ broken_links = []
+ # get each HTML file...
+ for root, subFolders, filenames in os.walk(get_sdk_docs_root()):
+ for filename in filenames:
+ if not filename.endswith(".html"):
+ continue
+ if root.endswith("static-files"):
+ continue
+ filename = os.path.join(root, filename)
+ # ...and feed it to the link checker
+ linkChecker = Link_Checker(self, filename, base_url)
+ linkChecker.feed(open(filename, "r").read())
+ broken_links.extend(linkChecker.errors)
+ if broken_links:
+ print
+ print "The following links are broken:"
+ for broken_link in sorted(broken_links):
+ print " "+ broken_link
+ self.fail("%d links are broken" % len(broken_links))
+ # clean up
+ shutil.rmtree(get_base_url_path())
+ tgz.close()
+ os.remove(tar_filename)
+ generate.clean_generated_docs(os.path.join(env_root, "doc"))
+
+ def test_generate_docs(self):
+ test_root = get_test_root()
+ docs_root = os.path.join(test_root, "doc")
+ generate.clean_generated_docs(docs_root)
+ new_digest = self.check_generate_regenerate_cycle(test_root, INITIAL_FILESET)
+ # touching an MD file under packages **does** cause a regenerate
+ os.utime(os.path.join(test_root, "packages", "aardvark", "doc", "main.md"), None)
+ new_digest = self.check_generate_regenerate_cycle(test_root, INITIAL_FILESET, new_digest)
+ # touching a non MD file under packages **does not** cause a regenerate
+ os.utime(os.path.join(test_root, "packages", "aardvark", "lib", "main.js"), None)
+ self.check_generate_is_skipped(test_root, INITIAL_FILESET, new_digest)
+ # touching a non MD file under static-files **does not** cause a regenerate
+ os.utime(os.path.join(docs_root, "static-files", "another.html"), None)
+ new_digest = self.check_generate_is_skipped(test_root, INITIAL_FILESET, new_digest)
+ # touching an MD file under dev-guide **does** cause a regenerate
+ os.utime(os.path.join(docs_root, "dev-guide-source", "index.md"), None)
+ new_digest = self.check_generate_regenerate_cycle(test_root, INITIAL_FILESET, new_digest)
+ # adding a file **does** cause a regenerate
+ open(os.path.join(docs_root, "dev-guide-source", "extra.md"), "w").write("some content")
+ new_digest = self.check_generate_regenerate_cycle(test_root, EXTENDED_FILESET, new_digest)
+ # deleting a file **does** cause a regenerate
+ os.remove(os.path.join(docs_root, "dev-guide-source", "extra.md"))
+ new_digest = self.check_generate_regenerate_cycle(test_root, INITIAL_FILESET, new_digest)
+ # remove the files
+ generate.clean_generated_docs(docs_root)
+
+ def check_generate_is_skipped(self, test_root, files_to_expect, initial_digest):
+ generate.generate_docs(test_root, stdout=StringIO.StringIO())
+ docs_root = os.path.join(test_root, "doc")
+ for file_to_expect in files_to_expect:
+ self.assertTrue(os.path.exists(os.path.join(docs_root, *file_to_expect)))
+ self.assertTrue(initial_digest == open(os.path.join(docs_root, "status.md5"), "r").read())
+
+ def check_generate_regenerate_cycle(self, test_root, files_to_expect, initial_digest = None):
+ # test that if we generate, files are getting generated
+ generate.generate_docs(test_root, stdout=StringIO.StringIO())
+ docs_root = os.path.join(test_root, "doc")
+ for file_to_expect in files_to_expect:
+ self.assertTrue(os.path.exists(os.path.join(docs_root, *file_to_expect)), os.path.join(docs_root, *file_to_expect) + "not found")
+ if initial_digest:
+ self.assertTrue(initial_digest != open(os.path.join(docs_root, "status.md5"), "r").read())
+ # and that if we regenerate, nothing changes...
+ new_digest = open(os.path.join(docs_root, "status.md5"), "r").read()
+ self.check_generate_is_skipped(test_root, files_to_expect, new_digest)
+ return new_digest
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_init.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_init.py
new file mode 100644
index 0000000..33c0059
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_init.py
@@ -0,0 +1,148 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os, unittest, shutil
+from StringIO import StringIO
+from cuddlefish import initializer
+from cuddlefish.templates import MAIN_JS, TEST_MAIN_JS, PACKAGE_JSON
+
+tests_path = os.path.abspath(os.path.dirname(__file__))
+
+class TestInit(unittest.TestCase):
+
+ def run_init_in_subdir(self, dirname, f, *args, **kwargs):
+ top = os.path.abspath(os.getcwd())
+ basedir = os.path.abspath(os.path.join(".test_tmp",self.id(),dirname))
+ if os.path.isdir(basedir):
+ assert basedir.startswith(top)
+ shutil.rmtree(basedir)
+ os.makedirs(basedir)
+ try:
+ os.chdir(basedir)
+ return f(basedir, *args, **kwargs)
+ finally:
+ os.chdir(top)
+
+ def do_test_init(self,basedir):
+ # Let's init the addon, no error admited
+ f = open(".ignoreme","w")
+ f.write("stuff")
+ f.close()
+
+ out, err = StringIO(), StringIO()
+ init_run = initializer(None, ["init"], out, err)
+ out, err = out.getvalue(), err.getvalue()
+ self.assertEqual(init_run, 0)
+ self.assertTrue("* lib directory created" in out)
+ self.assertTrue("* data directory created" in out)
+ self.assertTrue("Have fun!" in out)
+ self.assertEqual(err,"")
+ self.assertTrue(len(os.listdir(basedir))>0)
+ main_js = os.path.join(basedir,"lib","main.js")
+ package_json = os.path.join(basedir,"package.json")
+ test_main_js = os.path.join(basedir,"test","test-main.js")
+ self.assertTrue(os.path.exists(main_js))
+ self.assertTrue(os.path.exists(package_json))
+ self.assertTrue(os.path.exists(test_main_js))
+ self.assertEqual(open(main_js,"r").read(),MAIN_JS)
+ self.assertEqual(open(package_json,"r").read(),
+ PACKAGE_JSON % {"name":"tmp_addon_sample",
+ "fullName": "tmp_addon_SAMPLE" })
+ self.assertEqual(open(test_main_js,"r").read(),TEST_MAIN_JS)
+
+ # Let's check that the addon is initialized
+ out, err = StringIO(), StringIO()
+ init_run = initializer(None, ["init"], out, err)
+ out, err = out.getvalue(), err.getvalue()
+ self.failIfEqual(init_run,0)
+ self.assertTrue("This command must be run in an empty directory." in err)
+
+ def test_initializer(self):
+ self.run_init_in_subdir("tmp_addon_SAMPLE",self.do_test_init)
+
+ def do_test_args(self, basedir):
+ # check that running it with spurious arguments will fail
+ out,err = StringIO(), StringIO()
+ init_run = initializer(None, ["init", "ignored-dirname"], out, err)
+ out, err = out.getvalue(), err.getvalue()
+ self.failIfEqual(init_run, 0)
+ self.assertTrue("Too many arguments" in err)
+
+ def test_args(self):
+ self.run_init_in_subdir("tmp_addon_sample", self.do_test_args)
+
+ def _test_existing_files(self, basedir):
+ f = open("pay_attention_to_me","w")
+ f.write("stuff")
+ f.close()
+ out,err = StringIO(), StringIO()
+ rc = initializer(None, ["init"], out, err)
+ out, err = out.getvalue(), err.getvalue()
+ self.assertEqual(rc, 1)
+ self.failUnless("This command must be run in an empty directory" in err,
+ err)
+ self.failIf(os.path.exists("lib"))
+
+ def test_existing_files(self):
+ self.run_init_in_subdir("existing_files", self._test_existing_files)
+
+
+
+class TestCfxQuits(unittest.TestCase):
+
+ def run_cfx(self, addon_name, command):
+ old_cwd = os.getcwd()
+ addon_path = os.path.join(tests_path,
+ "addons", addon_name)
+ os.chdir(addon_path)
+ import sys
+ old_stdout = sys.stdout
+ old_stderr = sys.stderr
+ sys.stdout = out = StringIO()
+ sys.stderr = err = StringIO()
+ try:
+ import cuddlefish
+ args = list(command)
+ # Pass arguments given to cfx so that cfx can find firefox path
+ # if --binary option is given:
+ args.extend(sys.argv[1:])
+ cuddlefish.run(arguments=args)
+ except SystemExit, e:
+ if "code" in e:
+ rc = e.code
+ elif "args" in e and len(e.args)>0:
+ rc = e.args[0]
+ else:
+ rc = 0
+ finally:
+ sys.stdout = old_stdout
+ sys.stderr = old_stderr
+ os.chdir(old_cwd)
+ out.flush()
+ err.flush()
+ return rc, out.getvalue(), err.getvalue()
+
+ # this method doesn't exists in python 2.5,
+ # implements our own
+ def assertIn(self, member, container):
+ """Just like self.assertTrue(a in b), but with a nicer default message."""
+ if member not in container:
+ standardMsg = '"%s" not found in "%s"' % (member,
+ container)
+ self.fail(standardMsg)
+
+ def test_run(self):
+ rc, out, err = self.run_cfx("simplest-test", ["run"])
+ self.assertEqual(rc, 0)
+ self.assertIn("Program terminated successfully.", err)
+
+ def test_test(self):
+ rc, out, err = self.run_cfx("simplest-test", ["test"])
+ self.assertEqual(rc, 0)
+ self.assertIn("1 of 1 tests passed.", err)
+ self.assertIn("Program terminated successfully.", err)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_licenses.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_licenses.py
new file mode 100644
index 0000000..60b5957
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_licenses.py
@@ -0,0 +1,88 @@
+
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import unittest
+import os.path
+
+parent = os.path.dirname
+test_dir = parent(os.path.abspath(__file__))
+sdk_root = parent(parent(parent(test_dir)))
+
+def from_sdk_top(fn):
+ return os.path.abspath(os.path.join(sdk_root, fn))
+
+MPL2_URL = "http://mozilla.org/MPL/2.0/"
+
+# These files all come with their own license headers
+skip = [
+ "python-lib/cuddlefish/_version.py", # generated, public domain
+ "doc/static-files/js/jquery.js", # MIT/GPL dual
+ "examples/annotator/data/jquery-1.4.2.min.js", # MIT/GPL dual
+ "examples/reddit-panel/data/jquery-1.4.4.min.js", # MIT/GPL dual
+ "examples/library-detector/data/library-detector.js", # MIT
+ "python-lib/mozrunner/killableprocess.py", # MIT? BSDish?
+ "python-lib/mozrunner/winprocess.py", # MIT
+ "packages/api-utils/tests/test-querystring.js", # MIT
+ "packages/api-utils/lib/promise.js", # MIT
+ "packages/api-utils/tests/test-promise.js", # MIT
+ ]
+absskip = [from_sdk_top(os.path.join(*fn.split("/"))) for fn in skip]
+
+class Licenses(unittest.TestCase):
+ def test(self):
+ # Examine most SDK files to check if they've got an MPL2 license
+ # header. We exclude some files that are known to include different
+ # licenses.
+ self.missing = []
+ self.scan_file(from_sdk_top(os.path.join("python-lib", "jetpack_sdk_env.py")))
+ self.scan(os.path.join("python-lib", "cuddlefish"), [".js", ".py"],
+ skipdirs=["sdk-docs"], # test_generate.py makes this
+ )
+ self.scan(os.path.join("python-lib", "mozrunner"), [".py"])
+
+ for sdk_package in ["addon-kit", "api-utils", "test-harness"]:
+ self.scan(os.path.join("packages", sdk_package),
+ [".js", ".py", ".md"])
+ self.scan("examples", [".js", ".css", ".html", ".md"])
+ self.scan("bin", [".bat", ".ps1"])
+ for fn in [os.path.join("bin", "activate"),
+ os.path.join("bin", "cfx"),
+ os.path.join("bin", "integration-scripts", "buildbot-run-cfx-helper"),
+ os.path.join("bin", "integration-scripts", "integration-check"),
+ ]:
+ self.scan_file(from_sdk_top(fn))
+ self.scan("doc", [".js", ".css", ".md"], skipdirs=["syntaxhighlighter"])
+
+ if self.missing:
+ print
+ print "The following files are missing an MPL2 header:"
+ for fn in sorted(self.missing):
+ print " "+fn
+ self.fail("%d files are missing an MPL2 header" % len(self.missing))
+
+ def scan(self, start, extensions=[], skipdirs=[]):
+ # scan a whole subdirectory
+ start = from_sdk_top(start)
+ for root, dirs, files in os.walk(start):
+ for d in skipdirs:
+ if d in dirs:
+ dirs.remove(d)
+ for fn in files:
+ ext = os.path.splitext(fn)[1]
+ if extensions and ext not in extensions:
+ continue
+ absfn = os.path.join(root, fn)
+ if absfn in absskip:
+ continue
+ self.scan_file(absfn)
+
+ def scan_file(self, fn):
+ # scan a single file
+ if not MPL2_URL in open(fn, "r").read():
+ relfile = fn[len(sdk_root)+1:]
+ self.missing.append(relfile)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_linker.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_linker.py
new file mode 100755
index 0000000..84f6a09
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_linker.py
@@ -0,0 +1,234 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os.path
+import shutil
+import zipfile
+from StringIO import StringIO
+import simplejson as json
+import unittest
+import cuddlefish
+from cuddlefish import packaging, manifest
+
+def up(path, generations=1):
+ for i in range(generations):
+ path = os.path.dirname(path)
+ return path
+
+ROOT = up(os.path.abspath(__file__), 4)
+def get_linker_files_dir(name):
+ return os.path.join(up(os.path.abspath(__file__)), "linker-files", name)
+
+class Basic(unittest.TestCase):
+ def get_pkg(self, name):
+ d = get_linker_files_dir(name)
+ return packaging.get_config_in_dir(d)
+
+ def test_deps(self):
+ target_cfg = self.get_pkg("one")
+ pkg_cfg = packaging.build_config(ROOT, target_cfg)
+ deps = packaging.get_deps_for_targets(pkg_cfg, ["one"])
+ self.failUnlessEqual(deps, ["one"])
+ deps = packaging.get_deps_for_targets(pkg_cfg,
+ [target_cfg.name, "addon-kit"])
+ self.failUnlessEqual(deps, ["addon-kit", "api-utils", "one"])
+
+ def test_manifest(self):
+ target_cfg = self.get_pkg("one")
+ pkg_cfg = packaging.build_config(ROOT, target_cfg)
+ deps = packaging.get_deps_for_targets(pkg_cfg,
+ [target_cfg.name, "addon-kit"])
+ self.failUnlessEqual(deps, ["addon-kit", "api-utils", "one"])
+ # target_cfg.dependencies is not provided, so we'll search through
+ # all known packages (everything in 'deps').
+ m = manifest.build_manifest(target_cfg, pkg_cfg, deps, scan_tests=False)
+ m = m.get_harness_options_manifest()
+
+ def assertReqIs(modname, reqname, path):
+ reqs = m["one/lib/%s.js" % modname]["requirements"]
+ self.failUnlessEqual(reqs[reqname]["path"], path)
+ assertReqIs("main", "panel", "addon-kit/lib/panel.js")
+ assertReqIs("main", "two.js", "one/lib/two.js")
+ assertReqIs("main", "./two", "one/lib/two.js")
+ assertReqIs("main", "addon-kit/tabs.js", "addon-kit/lib/tabs.js")
+ assertReqIs("main", "./subdir/three", "one/lib/subdir/three.js")
+ assertReqIs("two", "main", "one/lib/main.js")
+ assertReqIs("subdir/three", "../main", "one/lib/main.js")
+
+ target_cfg.dependencies = []
+ # now, because .dependencies *is* provided, we won't search 'deps',
+ # so we'll get a link error
+ self.assertRaises(manifest.ModuleNotFoundError,
+ manifest.build_manifest,
+ target_cfg, pkg_cfg, deps, scan_tests=False)
+
+ def test_main_in_deps(self):
+ target_cfg = self.get_pkg("three")
+ package_path = [get_linker_files_dir("three-deps")]
+ pkg_cfg = packaging.build_config(ROOT, target_cfg,
+ packagepath=package_path)
+ deps = packaging.get_deps_for_targets(pkg_cfg,
+ [target_cfg.name, "addon-kit"])
+ self.failUnlessEqual(deps, ["addon-kit", "api-utils", "three"])
+ m = manifest.build_manifest(target_cfg, pkg_cfg, deps, scan_tests=False)
+ m = m.get_harness_options_manifest()
+ def assertReqIs(modname, reqname, path):
+ reqs = m["three/lib/%s.js" % modname]["requirements"]
+ self.failUnlessEqual(reqs[reqname]["path"], path)
+ assertReqIs("main", "three-a", "three-a/lib/main.js")
+ assertReqIs("main", "three-b", "three-b/lib/main.js")
+ assertReqIs("main", "three-c", "three-c/lib/main.js")
+
+ def test_relative_main_in_top(self):
+ target_cfg = self.get_pkg("five")
+ package_path = []
+ pkg_cfg = packaging.build_config(ROOT, target_cfg,
+ packagepath=package_path)
+ deps = packaging.get_deps_for_targets(pkg_cfg,
+ [target_cfg.name, "addon-kit"])
+ self.failUnlessEqual(deps, ["addon-kit", "api-utils", "five"])
+ # all we care about is that this next call doesn't raise an exception
+ m = manifest.build_manifest(target_cfg, pkg_cfg, deps, scan_tests=False)
+ m = m.get_harness_options_manifest()
+ reqs = m["five/lib/main.js"]["requirements"]
+ self.failUnlessEqual(reqs, {});
+
+ def test_unreachable_relative_main_in_top(self):
+ target_cfg = self.get_pkg("six")
+ package_path = []
+ pkg_cfg = packaging.build_config(ROOT, target_cfg,
+ packagepath=package_path)
+ deps = packaging.get_deps_for_targets(pkg_cfg,
+ [target_cfg.name, "addon-kit"])
+ self.failUnlessEqual(deps, ["addon-kit", "api-utils", "six"])
+ self.assertRaises(manifest.UnreachablePrefixError,
+ manifest.build_manifest,
+ target_cfg, pkg_cfg, deps, scan_tests=False)
+
+ def test_unreachable_in_deps(self):
+ target_cfg = self.get_pkg("four")
+ package_path = [get_linker_files_dir("four-deps")]
+ pkg_cfg = packaging.build_config(ROOT, target_cfg,
+ packagepath=package_path)
+ deps = packaging.get_deps_for_targets(pkg_cfg,
+ [target_cfg.name, "addon-kit"])
+ self.failUnlessEqual(deps, ["addon-kit", "api-utils", "four"])
+ self.assertRaises(manifest.UnreachablePrefixError,
+ manifest.build_manifest,
+ target_cfg, pkg_cfg, deps, scan_tests=False)
+
+class Contents(unittest.TestCase):
+
+ def run_in_subdir(self, dirname, f, *args, **kwargs):
+ top = os.path.abspath(os.getcwd())
+ basedir = os.path.abspath(os.path.join(".test_tmp",self.id(),dirname))
+ if os.path.isdir(basedir):
+ assert basedir.startswith(top)
+ shutil.rmtree(basedir)
+ os.makedirs(basedir)
+ try:
+ os.chdir(basedir)
+ return f(basedir, *args, **kwargs)
+ finally:
+ os.chdir(top)
+
+ def assertIn(self, what, inside_what):
+ self.failUnless(what in inside_what, inside_what)
+
+ def test_jetpackID(self):
+ # this uses "id": "jid7", to which a @jetpack should be appended
+ seven = get_linker_files_dir("seven")
+ def _test(basedir):
+ stdout = StringIO()
+ shutil.copytree(seven, "seven")
+ os.chdir("seven")
+ try:
+ # regrettably, run() always finishes with sys.exit()
+ cuddlefish.run(["xpi", "--no-strip-xpi"],
+ stdout=stdout)
+ except SystemExit, e:
+ self.failUnlessEqual(e.args[0], 0)
+ zf = zipfile.ZipFile("seven.xpi", "r")
+ hopts = json.loads(zf.read("harness-options.json"))
+ self.failUnlessEqual(hopts["jetpackID"], "jid7@jetpack")
+ self.run_in_subdir("x", _test)
+
+ def test_jetpackID_suffix(self):
+ # this uses "id": "jid1@jetpack", so no suffix should be appended
+ one = get_linker_files_dir("one")
+ def _test(basedir):
+ stdout = StringIO()
+ shutil.copytree(one, "one")
+ os.chdir("one")
+ try:
+ # regrettably, run() always finishes with sys.exit()
+ cuddlefish.run(["xpi", "--no-strip-xpi"],
+ stdout=stdout)
+ except SystemExit, e:
+ self.failUnlessEqual(e.args[0], 0)
+ zf = zipfile.ZipFile("one.xpi", "r")
+ hopts = json.loads(zf.read("harness-options.json"))
+ self.failUnlessEqual(hopts["jetpackID"], "jid1@jetpack")
+ self.run_in_subdir("x", _test)
+
+ def test_strip_default(self):
+ seven = get_linker_files_dir("seven")
+ # now run 'cfx xpi' in that directory, except put the generated .xpi
+ # elsewhere
+ def _test(basedir):
+ stdout = StringIO()
+ shutil.copytree(seven, "seven")
+ os.chdir("seven")
+ try:
+ # regrettably, run() always finishes with sys.exit()
+ cuddlefish.run(["xpi"], # --strip-xpi is now the default
+ stdout=stdout)
+ except SystemExit, e:
+ self.failUnlessEqual(e.args[0], 0)
+ zf = zipfile.ZipFile("seven.xpi", "r")
+ names = zf.namelist()
+ # the first problem found in bug 664840 was that cuddlefish.js
+ # (the loader) was stripped out on windows, due to a /-vs-\ bug
+ self.assertIn("resources/api-utils/lib/cuddlefish.js", names)
+ # the second problem found in bug 664840 was that an addon
+ # without an explicit tests/ directory would copy all files from
+ # the package into a bogus JID-PKGNAME-tests/ directory, so check
+ # for that
+ testfiles = [fn for fn in names if "seven/tests" in fn]
+ self.failUnlessEqual([], testfiles)
+ # the third problem was that data files were being stripped from
+ # the XPI. Note that data/ is only supposed to be included if a
+ # module that actually gets used does a require("self") .
+ self.assertIn("resources/seven/data/text.data",
+ names)
+ self.failIf("seven/lib/unused.js"
+ in names, names)
+ self.run_in_subdir("x", _test)
+
+ def test_no_strip(self):
+ seven = get_linker_files_dir("seven")
+ def _test(basedir):
+ stdout = StringIO()
+ shutil.copytree(seven, "seven")
+ os.chdir("seven")
+ try:
+ # regrettably, run() always finishes with sys.exit()
+ cuddlefish.run(["xpi", "--no-strip-xpi"],
+ stdout=stdout)
+ except SystemExit, e:
+ self.failUnlessEqual(e.args[0], 0)
+ zf = zipfile.ZipFile("seven.xpi", "r")
+ names = zf.namelist()
+ self.assertIn("resources/api-utils/lib/cuddlefish.js", names)
+ testfiles = [fn for fn in names if "seven/tests" in fn]
+ self.failUnlessEqual([], testfiles)
+ self.assertIn("resources/seven/data/text.data",
+ names)
+ self.failUnless("resources/seven/lib/unused.js"
+ in names, names)
+ self.run_in_subdir("x", _test)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_manifest.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_manifest.py
new file mode 100644
index 0000000..77ee86f
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_manifest.py
@@ -0,0 +1,254 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+import unittest
+from StringIO import StringIO
+from cuddlefish.manifest import scan_module
+
+class Extra:
+ def failUnlessKeysAre(self, d, keys):
+ self.failUnlessEqual(sorted(d.keys()), sorted(keys))
+
+class Require(unittest.TestCase, Extra):
+ def scan(self, text):
+ lines = StringIO(text).readlines()
+ requires, problems, locations = scan_module("fake.js", lines)
+ self.failUnlessEqual(problems, False)
+ return requires
+
+ def scan_locations(self, text):
+ lines = StringIO(text).readlines()
+ requires, problems, locations = scan_module("fake.js", lines)
+ self.failUnlessEqual(problems, False)
+ return requires, locations
+
+ def test_modules(self):
+ mod = """var foo = require('one');"""
+ requires = self.scan(mod)
+ self.failUnlessKeysAre(requires, ["one"])
+
+ mod = """var foo = require(\"one\");"""
+ requires = self.scan(mod)
+ self.failUnlessKeysAre(requires, ["one"])
+
+ mod = """var foo=require( 'one' ) ; """
+ requires = self.scan(mod)
+ self.failUnlessKeysAre(requires, ["one"])
+
+ mod = """var foo = require('o'+'ne'); // tricky, denied"""
+ requires = self.scan(mod)
+ self.failUnlessKeysAre(requires, [])
+
+ mod = """require('one').immediately.do().stuff();"""
+ requires, locations = self.scan_locations(mod)
+ self.failUnlessKeysAre(requires, ["one"])
+ self.failUnlessEqual(locations, {"one": 1})
+
+ # these forms are commented out, and thus ignored
+
+ mod = """// var foo = require('one');"""
+ requires = self.scan(mod)
+ self.failUnlessKeysAre(requires, [])
+
+ mod = """/* var foo = require('one');"""
+ requires = self.scan(mod)
+ self.failUnlessKeysAre(requires, [])
+
+ mod = """ * var foo = require('one');"""
+ requires = self.scan(mod)
+ self.failUnlessKeysAre(requires, [])
+
+ mod = """ ' var foo = require('one');"""
+ requires = self.scan(mod)
+ self.failUnlessKeysAre(requires, ["one"])
+
+ mod = """ \" var foo = require('one');"""
+ requires = self.scan(mod)
+ self.failUnlessKeysAre(requires, ["one"])
+
+ # multiple requires
+
+ mod = """const foo = require('one');
+ const foo = require('two');"""
+ requires, locations = self.scan_locations(mod)
+ self.failUnlessKeysAre(requires, ["one", "two"])
+ self.failUnlessEqual(locations["one"], 1)
+ self.failUnlessEqual(locations["two"], 2)
+
+ mod = """const foo = require('repeated');
+ const bar = require('repeated');
+ const baz = require('repeated');"""
+ requires, locations = self.scan_locations(mod)
+ self.failUnlessKeysAre(requires, ["repeated"])
+ self.failUnlessEqual(locations["repeated"], 1) # first occurrence
+
+ mod = """const foo = require('one'); const foo = require('two');"""
+ requires = self.scan(mod)
+ self.failUnlessKeysAre(requires, ["one", "two"])
+
+ # define calls
+
+ mod = """define('one', ['two', 'numbers/three'], function(t, th) {});"""
+ requires = self.scan(mod)
+ self.failUnlessKeysAre(requires, ["two", "numbers/three"])
+
+ mod = """define(
+ ['odd',
+ "numbers/four"], function() {});"""
+ requires = self.scan(mod)
+ self.failUnlessKeysAre(requires, ["odd", "numbers/four"])
+
+ mod = """define(function(require, exports, module) {
+ var a = require("some/module/a"),
+ b = require('b/v1');
+ exports.a = a;
+ //This is a fakeout: require('bad');
+ /* And another var bad = require('bad2'); */
+ require('foo').goFoo();
+ });"""
+ requires = self.scan(mod)
+ self.failUnlessKeysAre(requires, ["some/module/a", "b/v1", "foo"])
+
+ mod = """define (
+ "foo",
+ ["bar"], function (bar) {
+ var me = require("me");
+ }
+ )"""
+ requires = self.scan(mod)
+ self.failUnlessKeysAre(requires, ["bar", "me"])
+
+ mod = """define(['se' + 'ven', 'eight', nine], function () {});"""
+ requires = self.scan(mod)
+ self.failUnlessKeysAre(requires, ["eight"])
+
+ # async require calls
+
+ mod = """require(['one'], function(one) {var o = require("one");});"""
+ requires = self.scan(mod)
+ self.failUnlessKeysAre(requires, ["one"])
+
+ mod = """require([ 'one' ], function(one) {var t = require("two");});"""
+ requires = self.scan(mod)
+ self.failUnlessKeysAre(requires, ["one", "two"])
+
+ mod = """require ( ['two', 'numbers/three'], function(t, th) {});"""
+ requires = self.scan(mod)
+ self.failUnlessKeysAre(requires, ["two", "numbers/three"])
+
+ mod = """require (
+ ["bar", "fa" + 'ke' ], function (bar) {
+ var me = require("me");
+ // require("bad").doBad();
+ }
+ )"""
+ requires = self.scan(mod)
+ self.failUnlessKeysAre(requires, ["bar", "me"])
+
+def scan2(text, fn="fake.js"):
+ stderr = StringIO()
+ lines = StringIO(text).readlines()
+ requires, problems, locations = scan_module(fn, lines, stderr)
+ stderr.seek(0)
+ return requires, problems, stderr.readlines()
+
+class Chrome(unittest.TestCase, Extra):
+
+ def test_ignore_loader(self):
+ # we specifically ignore the loader itself
+ mod = """let {Cc,Ci} = require('chrome');"""
+ requires, problems, err = scan2(mod, "blah/cuddlefish.js")
+ self.failUnlessKeysAre(requires, ["chrome"])
+ self.failUnlessEqual(problems, False)
+ self.failUnlessEqual(err, [])
+
+ def test_chrome(self):
+ mod = """let {Cc,Ci} = require('chrome');"""
+ requires, problems, err = scan2(mod)
+ self.failUnlessKeysAre(requires, ["chrome"])
+ self.failUnlessEqual(problems, False)
+ self.failUnlessEqual(err, [])
+
+ mod = """var foo = require('foo');
+ let {Cc,Ci} = require('chrome');"""
+ requires, problems, err = scan2(mod)
+ self.failUnlessKeysAre(requires, ["foo", "chrome"])
+ self.failUnlessEqual(problems, False)
+ self.failUnlessEqual(err, [])
+
+ mod = """let c = require('chrome');"""
+ requires, problems, err = scan2(mod)
+ self.failUnlessKeysAre(requires, ["chrome"])
+ self.failUnlessEqual(problems, False)
+ self.failUnlessEqual(err, [])
+
+ mod = """var foo = require('foo');
+ let c = require('chrome');"""
+ requires, problems, err = scan2(mod)
+ self.failUnlessKeysAre(requires, ["foo", "chrome"])
+ self.failUnlessEqual(problems, False)
+ self.failUnlessEqual(err, [])
+
+ def test_chrome_components(self):
+ # Bug 663541: tolerate "Components" if you're marked with
+ # require("chrome"), to avoid requiring module authors to rewrite a
+ # lot of code. Once bug 636145 is fixed, such code will break. To fix
+ # it, add {Components}=require("chrome"), but that won't work until
+ # after 636145 is fixed.
+ mod = """require("chrome");
+ var ios = Components.classes['@mozilla.org/network/io-service;1'];"""
+ requires, problems, err = scan2(mod)
+ self.failUnlessKeysAre(requires, ["chrome"])
+ self.failUnlessEqual((problems, err), (False, []))
+
+ def test_not_chrome(self):
+ # from bug 596595
+ mod = r'soughtLines: new RegExp("^\\s*(\\[[0-9 .]*\\])?\\s*\\(\\((EE|WW)\\)|.* [Cc]hipsets?: \\)|\\s*Backtrace")'
+ requires, problems, err = scan2(mod)
+ self.failUnlessKeysAre(requires, [])
+ self.failUnlessEqual((problems,err), (False, []))
+
+ def test_not_chrome2(self):
+ # from bug 655788
+ mod = r"var foo = 'some stuff Cr';"
+ requires, problems, err = scan2(mod)
+ self.failUnlessKeysAre(requires, [])
+ self.failUnlessEqual((problems,err), (False, []))
+
+class BadChrome(unittest.TestCase, Extra):
+ def test_bad_alias(self):
+ # using Components.* gets you an error, with a message that teaches
+ # you the correct approach.
+ mod = """let Cc = Components.classes;
+ let Cu = Components.utils;
+ """
+ requires, problems, err = scan2(mod)
+ self.failUnlessKeysAre(requires, [])
+ self.failUnlessEqual(problems, True)
+ self.failUnlessEqual(err[1], "The following lines from file fake.js:\n")
+ self.failUnlessEqual(err[2], " 1: let Cc = Components.classes;\n")
+ self.failUnlessEqual(err[3], " 2: let Cu = Components.utils;\n")
+ self.failUnlessEqual(err[4], "use 'Components' to access chrome authority. To do so, you need to add a\n")
+ self.failUnlessEqual(err[5], "line somewhat like the following:\n")
+ self.failUnlessEqual(err[7], ' const {Cc,Cu} = require("chrome");\n')
+ self.failUnlessEqual(err[9], "Then you can use 'Components' as well as any shortcuts to its properties\n")
+
+ def test_bad_misc(self):
+ # If it looks like you're using something that doesn't have an alias,
+ # the warning also suggests a better way.
+ mod = """if (Components.isSuccessCode(foo))
+ """
+ requires, problems, err = scan2(mod)
+ self.failUnlessKeysAre(requires, [])
+ self.failUnlessEqual(problems, True)
+ self.failUnlessEqual(err[1], "The following lines from file fake.js:\n")
+ self.failUnlessEqual(err[2], " 1: if (Components.isSuccessCode(foo))\n")
+ self.failUnlessEqual(err[3], "use 'Components' to access chrome authority. To do so, you need to add a\n")
+ self.failUnlessEqual(err[4], "line somewhat like the following:\n")
+ self.failUnlessEqual(err[6], ' const {components} = require("chrome");\n')
+ self.failUnlessEqual(err[8], "Then you can use 'Components' as well as any shortcuts to its properties\n")
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_packaging.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_packaging.py
new file mode 100644
index 0000000..ff3d851
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_packaging.py
@@ -0,0 +1,116 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import unittest
+
+from cuddlefish import packaging
+from cuddlefish.bunch import Bunch
+
+tests_path = os.path.abspath(os.path.dirname(__file__))
+static_files_path = os.path.join(tests_path, 'static-files')
+
+def get_configs(pkg_name, dirname='static-files'):
+ root_path = os.path.join(tests_path, dirname)
+ pkg_path = os.path.join(root_path, 'packages', pkg_name)
+ if not (os.path.exists(pkg_path) and os.path.isdir(pkg_path)):
+ raise Exception('path does not exist: %s' % pkg_path)
+ target_cfg = packaging.get_config_in_dir(pkg_path)
+ pkg_cfg = packaging.build_config(root_path, target_cfg)
+ deps = packaging.get_deps_for_targets(pkg_cfg, [pkg_name])
+ build = packaging.generate_build_for_target(
+ pkg_cfg=pkg_cfg,
+ target=pkg_name,
+ deps=deps
+ )
+ return Bunch(target_cfg=target_cfg, pkg_cfg=pkg_cfg, build=build)
+
+class PackagingTests(unittest.TestCase):
+ def test_bug_588661(self):
+ configs = get_configs('foo', 'bug-588661-files')
+ self.assertEqual(configs.build.loader,
+ 'foo/lib/foo-loader.js')
+
+ def test_bug_614712(self):
+ configs = get_configs('commonjs-naming', 'bug-614712-files')
+ packages = configs.pkg_cfg.packages
+ base = os.path.join(tests_path, 'bug-614712-files', 'packages')
+ self.assertEqual(packages['original-naming'].tests,
+ [os.path.join(base, 'original-naming', 'tests')])
+ self.assertEqual(packages['commonjs-naming'].tests,
+ [os.path.join(base, 'commonjs-naming', 'test')])
+
+ def test_basic(self):
+ configs = get_configs('aardvark')
+ packages = configs.pkg_cfg.packages
+
+ self.assertTrue('api-utils' in packages)
+ self.assertTrue('aardvark' in packages)
+ self.assertTrue('api-utils' in packages.aardvark.dependencies)
+ self.assertEqual(packages['api-utils'].loader, 'lib/loader.js')
+ self.assertTrue(packages.aardvark.main == 'main')
+ self.assertTrue(packages.aardvark.version == "1.0")
+
+class PackagePath(unittest.TestCase):
+ def test_packagepath(self):
+ root_path = os.path.join(tests_path, 'static-files')
+ pkg_path = os.path.join(root_path, 'packages', 'minimal')
+ target_cfg = packaging.get_config_in_dir(pkg_path)
+ pkg_cfg = packaging.build_config(root_path, target_cfg)
+ base_packages = set(pkg_cfg.packages.keys())
+ ppath = [os.path.join(tests_path, 'bug-611495-files')]
+ pkg_cfg2 = packaging.build_config(root_path, target_cfg, packagepath=ppath)
+ all_packages = set(pkg_cfg2.packages.keys())
+ self.assertEqual(sorted(["jspath-one"]),
+ sorted(all_packages - base_packages))
+
+class Directories(unittest.TestCase):
+ # for bug 652227
+ packages_path = os.path.join(tests_path, "bug-652227-files", "packages")
+ def get_config(self, pkg_name):
+ pkg_path = os.path.join(tests_path, "bug-652227-files", "packages",
+ pkg_name)
+ return packaging.get_config_in_dir(pkg_path)
+
+ def test_explicit_lib(self):
+ # package.json provides .lib
+ p = self.get_config('explicit-lib')
+ self.assertEqual(os.path.abspath(p.lib[0]),
+ os.path.abspath(os.path.join(self.packages_path,
+ "explicit-lib",
+ "alt2-lib")))
+
+ def test_directories_lib(self):
+ # package.json provides .directories.lib
+ p = self.get_config('explicit-dir-lib')
+ self.assertEqual(os.path.abspath(p.lib[0]),
+ os.path.abspath(os.path.join(self.packages_path,
+ "explicit-dir-lib",
+ "alt-lib")))
+
+ def test_lib(self):
+ # package.json is empty, but lib/ exists
+ p = self.get_config("default-lib")
+ self.assertEqual(os.path.abspath(p.lib[0]),
+ os.path.abspath(os.path.join(self.packages_path,
+ "default-lib",
+ "lib")))
+
+ def test_root(self):
+ # package.json is empty, no lib/, so files are in root
+ p = self.get_config('default-root')
+ self.assertEqual(os.path.abspath(p.lib[0]),
+ os.path.abspath(os.path.join(self.packages_path,
+ "default-root")))
+
+ def test_locale(self):
+ # package.json is empty, but locale/ exists and should be used
+ p = self.get_config("default-locale")
+ self.assertEqual(os.path.abspath(p.locale),
+ os.path.abspath(os.path.join(self.packages_path,
+ "default-locale",
+ "locale")))
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_preflight.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_preflight.py
new file mode 100644
index 0000000..571b791
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_preflight.py
@@ -0,0 +1,147 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+import os, shutil
+import simplejson as json
+import unittest
+import hashlib
+import base64
+from cuddlefish import preflight
+from StringIO import StringIO
+
+class Util(unittest.TestCase):
+ def get_basedir(self):
+ return os.path.join(".test_tmp", self.id())
+ def make_basedir(self):
+ basedir = self.get_basedir()
+ if os.path.isdir(basedir):
+ here = os.path.abspath(os.getcwd())
+ assert os.path.abspath(basedir).startswith(here) # safety
+ shutil.rmtree(basedir)
+ os.makedirs(basedir)
+ return basedir
+
+ def test_base62(self):
+ for i in range(1000):
+ h = hashlib.sha1(str(i)).digest()
+ s1 = base64.b64encode(h, "AB").strip("=")
+ s2 = base64.b64encode(h).strip("=").replace("+","A").replace("/","B")
+ self.failUnlessEqual(s1, s2)
+
+ def write(self, config):
+ basedir = self.get_basedir()
+ fn = os.path.join(basedir, "package.json")
+ open(fn,"w").write(config)
+ def read(self):
+ basedir = self.get_basedir()
+ fn = os.path.join(basedir, "package.json")
+ return open(fn,"r").read()
+
+ def get_cfg(self):
+ cfg = json.loads(self.read())
+ if "name" not in cfg:
+ # the cfx parser always provides a name, even if package.json
+ # doesn't contain one
+ cfg["name"] = "pretend name"
+ return cfg
+
+ def parse(self, keydata):
+ fields = {}
+ fieldnames = []
+ for line in keydata.split("\n"):
+ if line.strip():
+ k,v = line.split(":", 1)
+ k = k.strip() ; v = v.strip()
+ fields[k] = v
+ fieldnames.append(k)
+ return fields, fieldnames
+
+ def test_preflight(self):
+ basedir = self.make_basedir()
+ fn = os.path.join(basedir, "package.json")
+
+ # empty config is not ok: need id (name is automatically supplied)
+ config_orig = "{}"
+ self.write(config_orig)
+ out = StringIO()
+ cfg = self.get_cfg()
+ config_was_ok, modified = preflight.preflight_config(cfg, fn,
+ stderr=out)
+ self.failUnlessEqual(config_was_ok, False)
+ self.failUnlessEqual(modified, True)
+ backup_fn = os.path.join(basedir, "package.json.backup")
+ config_backup = open(backup_fn,"r").read()
+ self.failUnlessEqual(config_backup, config_orig)
+ config = json.loads(self.read())
+ self.failIf("name" in config)
+ self.failUnless("id" in config)
+ self.failUnless(config["id"].startswith("jid1-"), config["id"])
+ self.failUnlessEqual(out.getvalue().strip(),
+ "No 'id' in package.json: creating a new ID for you.")
+ os.unlink(backup_fn)
+
+ # just a name? we add the id
+ config_orig = '{"name": "my-awesome-package"}'
+ self.write(config_orig)
+ out = StringIO()
+ cfg = self.get_cfg()
+ config_was_ok, modified = preflight.preflight_config(cfg, fn,
+ stderr=out)
+ self.failUnlessEqual(config_was_ok, False)
+ self.failUnlessEqual(modified, True)
+ backup_fn = os.path.join(basedir, "package.json.backup")
+ config_backup = open(backup_fn,"r").read()
+ self.failUnlessEqual(config_backup, config_orig)
+ config = json.loads(self.read())
+ self.failUnlessEqual(config["name"], "my-awesome-package")
+ self.failUnless("id" in config)
+ self.failUnless(config["id"].startswith("jid1-"), config["id"])
+ jid = str(config["id"])
+ self.failUnlessEqual(out.getvalue().strip(),
+ "No 'id' in package.json: creating a new ID for you.")
+ os.unlink(backup_fn)
+
+ # name and valid id? great! ship it!
+ config2 = '{"name": "my-awesome-package", "id": "%s"}' % jid
+ self.write(config2)
+ out = StringIO()
+ cfg = self.get_cfg()
+ config_was_ok, modified = preflight.preflight_config(cfg, fn,
+ stderr=out)
+ self.failUnlessEqual(config_was_ok, True)
+ self.failUnlessEqual(modified, False)
+ config2a = self.read()
+ self.failUnlessEqual(config2a, config2)
+ self.failUnlessEqual(out.getvalue().strip(), "")
+
+ # name and anonymous ID? without asking to see its papers, ship it
+ config3 = '{"name": "my-old-skool-package", "id": "anonid0-deadbeef"}'
+ self.write(config3)
+ out = StringIO()
+ cfg = self.get_cfg()
+ config_was_ok, modified = preflight.preflight_config(cfg, fn,
+ stderr=out)
+ self.failUnlessEqual(config_was_ok, True)
+ self.failUnlessEqual(modified, False)
+ config3a = self.read()
+ self.failUnlessEqual(config3a, config3)
+ self.failUnlessEqual(out.getvalue().strip(), "")
+
+ # name and old-style ID? with nostalgic trepidation, ship it
+ config4 = '{"name": "my-old-skool-package", "id": "foo@bar.baz"}'
+ self.write(config4)
+ out = StringIO()
+ cfg = self.get_cfg()
+ config_was_ok, modified = preflight.preflight_config(cfg, fn,
+ stderr=out)
+ self.failUnlessEqual(config_was_ok, True)
+ self.failUnlessEqual(modified, False)
+ config4a = self.read()
+ self.failUnlessEqual(config4a, config4)
+ self.failUnlessEqual(out.getvalue().strip(), "")
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_property_parser.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_property_parser.py
new file mode 100644
index 0000000..f037f07
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_property_parser.py
@@ -0,0 +1,75 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import unittest
+
+from cuddlefish.property_parser import parse, MalformedLocaleFileError
+
+class TestParser(unittest.TestCase):
+
+ def test_parse(self):
+ lines = [
+ # Comments are striped only if `#` is the first non-space character
+ "sharp=#can be in value",
+ "# comment",
+ "#key=value",
+ " # comment2",
+
+ "keyWithNoValue=",
+ "valueWithSpaces= ",
+ "valueWithMultilineSpaces= \\",
+ " \\",
+ " ",
+
+ # All spaces before/after are striped
+ " key = value ",
+ "key2=value2",
+ # Keys can contain '%'
+ "%s key=%s value",
+
+ # Accept empty lines
+ "",
+ " ",
+
+ # Multiline string must use backslash at end of lines
+ "multi=line\\", "value",
+ # With multiline string, left spaces are stripped ...
+ "some= spaces\\", " are\\ ", " stripped ",
+ # ... but not right spaces, except the last line!
+ "but=not \\", "all of \\", " them "
+ ]
+ # Ensure that lines end with a `\n`
+ lines = [l + "\n" for l in lines]
+ pairs = parse(lines)
+ expected = {
+ "sharp": "#can be in value",
+
+ "key": "value",
+ "key2": "value2",
+ "%s key": "%s value",
+
+ "keyWithNoValue": "",
+ "valueWithSpaces": "",
+ "valueWithMultilineSpaces": "",
+
+ "multi": "linevalue",
+ "some": "spacesarestripped",
+ "but": "not all of them"
+ }
+ self.assertEqual(pairs, expected)
+
+ def test_exceptions(self):
+ self.failUnlessRaises(MalformedLocaleFileError, parse,
+ ["invalid line with no key value"])
+ self.failUnlessRaises(MalformedLocaleFileError, parse,
+ ["plural[one]=plural with no generic value"])
+ self.failUnlessRaises(MalformedLocaleFileError, parse,
+ ["multiline with no last empty line=\\"])
+ self.failUnlessRaises(MalformedLocaleFileError, parse,
+ ["=no key"])
+ self.failUnlessRaises(MalformedLocaleFileError, parse,
+ [" =only spaces in key"])
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_rdf.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_rdf.py
new file mode 100644
index 0000000..128289f
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_rdf.py
@@ -0,0 +1,45 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import unittest
+import xml.dom.minidom
+import os.path
+
+from cuddlefish import rdf, packaging
+
+parent = os.path.dirname
+test_dir = parent(os.path.abspath(__file__))
+template_dir = os.path.join(parent(test_dir), "app-extension")
+
+class RDFTests(unittest.TestCase):
+ def testBug567660(self):
+ obj = rdf.RDF()
+ data = u'\u2026'.encode('utf-8')
+ x = '<?xml version="1.0" encoding="utf-8"?><blah>%s</blah>' % data
+ obj.dom = xml.dom.minidom.parseString(x)
+ self.assertEqual(obj.dom.documentElement.firstChild.nodeValue,
+ u'\u2026')
+ self.assertEqual(str(obj).replace("\n",""), x.replace("\n",""))
+
+ def failUnlessIn(self, substring, s, msg=""):
+ if substring not in s:
+ self.fail("(%s) substring '%s' not in string '%s'"
+ % (msg, substring, s))
+
+ def testUnpack(self):
+ basedir = os.path.join(test_dir, "bug-715340-files")
+ for n in ["pkg-1-pack", "pkg-2-unpack", "pkg-3-pack"]:
+ cfg = packaging.get_config_in_dir(os.path.join(basedir, n))
+ m = rdf.gen_manifest(template_dir, cfg, jid="JID")
+ if n.endswith("-pack"):
+ # these ones should remain packed
+ self.failUnlessEqual(m.get("em:unpack"), "false")
+ self.failUnlessIn("<em:unpack>false</em:unpack>", str(m), n)
+ else:
+ # and these should be unpacked
+ self.failUnlessEqual(m.get("em:unpack"), "true")
+ self.failUnlessIn("<em:unpack>true</em:unpack>", str(m), n)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_runner.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_runner.py
new file mode 100644
index 0000000..26583ab
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_runner.py
@@ -0,0 +1,27 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+def xulrunner_app_runner_doctests():
+ """
+ >>> import sys
+ >>> from cuddlefish import runner
+ >>> runner.XulrunnerAppRunner(binary='foo')
+ Traceback (most recent call last):
+ ...
+ Exception: Binary path does not exist foo
+
+ >>> runner.XulrunnerAppRunner(binary=sys.executable)
+ Traceback (most recent call last):
+ ...
+ ValueError: application.ini not found in cmdargs
+
+ >>> runner.XulrunnerAppRunner(binary=sys.executable,
+ ... cmdargs=['application.ini'])
+ Traceback (most recent call last):
+ ...
+ ValueError: file does not exist: 'application.ini'
+ """
+
+ pass
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_util.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_util.py
new file mode 100644
index 0000000..aa636a4
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_util.py
@@ -0,0 +1,22 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+import unittest
+from cuddlefish.manifest import filter_filenames, filter_dirnames
+
+class Filter(unittest.TestCase):
+ def test_filter_filenames(self):
+ names = ["foo", "bar.js", "image.png",
+ ".hidden", "foo~", ".foo.swp", "bar.js.swp"]
+ self.failUnlessEqual(sorted(filter_filenames(names)),
+ sorted(["foo", "bar.js", "image.png"]))
+
+ def test_filter_dirnames(self):
+ names = ["subdir", "data", ".git", ".hg", ".svn", "defaults"]
+ self.failUnlessEqual(sorted(filter_dirnames(names)),
+ sorted(["subdir", "data", "defaults"]))
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_version.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_version.py
new file mode 100644
index 0000000..814c57c
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_version.py
@@ -0,0 +1,28 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import unittest
+import shutil
+
+from cuddlefish._version import get_versions
+
+class Version(unittest.TestCase):
+ def get_basedir(self):
+ return os.path.join(".test_tmp", self.id())
+ def make_basedir(self):
+ basedir = self.get_basedir()
+ if os.path.isdir(basedir):
+ here = os.path.abspath(os.getcwd())
+ assert os.path.abspath(basedir).startswith(here) # safety
+ shutil.rmtree(basedir)
+ os.makedirs(basedir)
+ return basedir
+
+ def test_current_version(self):
+ # the SDK should be able to determine its own version. We don't care
+ # what it is, merely that it can be computed.
+ version = get_versions()["version"]
+ self.failUnless(isinstance(version, str), (version, type(version)))
+ self.failUnless(len(version) > 0, version)
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_webdocs.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_webdocs.py
new file mode 100644
index 0000000..d9d4eab
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_webdocs.py
@@ -0,0 +1,97 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import unittest
+
+from cuddlefish.docs import webdocs
+
+class WebDocTests(unittest.TestCase):
+ def test_create_package_doc(self):
+ root = os.path.join(os.getcwd() + \
+ '/python-lib/cuddlefish/tests/static-files')
+ web_docs = webdocs.WebDocs(root)
+ aarvark_package = web_docs.create_package_page('aardvark')
+ self._test_common_contents(aarvark_package)
+ self.assertTrue('<h1>aardvark</h1>'\
+ in aarvark_package)
+ self.assertTrue(\
+ '<span class="meta-header">Author</span>'\
+ in aarvark_package)
+ self.assertTrue(\
+ '<span class="author">Jon Smith</span>'\
+ in aarvark_package)
+ self.assertTrue(\
+ '<title>aardvark - Add-on SDK Documentation</title>'\
+ in aarvark_package)
+
+ def test_create_guide1_doc(self):
+ root = os.path.join(os.getcwd() + \
+ '/python-lib/cuddlefish/tests/static-files')
+ web_docs = webdocs.WebDocs(root)
+ guide = web_docs.create_guide_page(os.path.join(\
+ root + '/doc/dev-guide-source/index.blah'))
+ self._test_common_contents(guide)
+ self.assertTrue(\
+ '<title>An Imposing Title - Add-on SDK Documentation</title>'\
+ in guide)
+ self.assertTrue('<p><em>Some words!</em></p>'\
+ in guide)
+ self.assertTrue('<div id="version">Version '\
+ in guide)
+
+ def test_create_guide2_doc(self):
+ root = os.path.join(os.getcwd() + \
+ '/python-lib/cuddlefish/tests/static-files')
+ web_docs = webdocs.WebDocs(root)
+ guide = web_docs.create_guide_page(os.path.join(\
+ root + '/doc/dev-guide-source/no_h1.blah'))
+ self._test_common_contents(guide)
+ self.assertTrue('<title>Add-on SDK Documentation</title>'\
+ in guide)
+ self.assertTrue('<h2>A heading</h2>'\
+ in guide)
+
+ def test_create_module_doc(self):
+ root = os.path.join(os.getcwd() + \
+ '/python-lib/cuddlefish/tests/static-files')
+ web_docs = webdocs.WebDocs(root)
+ module = web_docs.create_module_page(os.path.join(\
+ root + '/packages/aardvark/doc/aardvark-feeder.blah'))
+ self._test_common_contents(module)
+ self.assertTrue(\
+ '<title>aardvark-feeder - Add-on SDK Documentation</title>'\
+ in module)
+ self.assertTrue(\
+ '<h1>aardvark-feeder</h1>'\
+ in module)
+ self.assertTrue(\
+ '<div class="module_description">'\
+ in module)
+ self.assertTrue(\
+ '<p>The <code>aardvark-feeder</code> module simplifies feeding aardvarks.</p>'\
+ in module)
+ self.assertTrue(\
+ '<h2 class="api_header">API Reference</h2>'\
+ in module)
+ self.assertTrue(\
+ '<h3 class="api_header">Functions</h3>'\
+ in module)
+ self.assertTrue(\
+ '<h4 class="api_name">feed(food)</h4>'\
+ in module)
+ self.assertTrue(
+ '<p>Feed the aardvark.</p>'\
+ in module)
+
+ def _test_common_contents(self, doc):
+ self.assertTrue(\
+ '<a href="packages/aardvark/index.html"' in doc)
+ self.assertTrue(\
+ '<a href="packages/anteater_files/index.html"' in doc)
+ self.assertTrue(\
+ '<a href="packages/aardvark/main.html">main</a>' in doc)
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_xpi.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_xpi.py
new file mode 100644
index 0000000..7d638bb
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/tests/test_xpi.py
@@ -0,0 +1,412 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import unittest
+import zipfile
+import pprint
+import shutil
+
+import simplejson as json
+from cuddlefish import xpi, packaging, manifest, buildJID
+from cuddlefish.tests import test_packaging
+from test_linker import up
+
+xpi_template_path = os.path.join(test_packaging.static_files_path,
+ 'xpi-template')
+
+fake_manifest = '<RDF><!-- Extension metadata is here. --></RDF>'
+
+class PrefsTests(unittest.TestCase):
+ def makexpi(self, pkg_name):
+ self.xpiname = "%s.xpi" % pkg_name
+ create_xpi(self.xpiname, pkg_name, 'preferences-files')
+ self.xpi = zipfile.ZipFile(self.xpiname, 'r')
+ options = self.xpi.read('harness-options.json')
+ self.xpi_harness_options = json.loads(options)
+
+ def setUp(self):
+ self.xpiname = None
+ self.xpi = None
+
+ def tearDown(self):
+ if self.xpi:
+ self.xpi.close()
+ if self.xpiname and os.path.exists(self.xpiname):
+ os.remove(self.xpiname)
+
+ def testPackageWithSimplePrefs(self):
+ self.makexpi('simple-prefs')
+ self.failUnless('options.xul' in self.xpi.namelist())
+ optsxul = self.xpi.read('options.xul').decode("utf-8")
+ self.failUnless('pref="extensions.jid1-fZHqN9JfrDBa8A@jetpack.test"'
+ in optsxul, optsxul)
+ self.failUnless('type="bool"' in optsxul, optsxul)
+ self.failUnless(u'title="t\u00EBst"' in optsxul, repr(optsxul))
+ self.failUnlessEqual(self.xpi_harness_options["jetpackID"],
+ "jid1-fZHqN9JfrDBa8A@jetpack")
+ prefsjs = self.xpi.read('defaults/preferences/prefs.js').decode("utf-8")
+ exp = [u'pref("extensions.jid1-fZHqN9JfrDBa8A@jetpack.test", false);',
+ u'pref("extensions.jid1-fZHqN9JfrDBa8A@jetpack.test2", "\u00FCnic\u00F8d\u00E9");',
+ ]
+ self.failUnlessEqual(prefsjs, "\n".join(exp)+"\n")
+
+ def testPackageWithNoPrefs(self):
+ self.makexpi('no-prefs')
+ self.failIf('options.xul' in self.xpi.namelist())
+ self.failUnlessEqual(self.xpi_harness_options["jetpackID"],
+ "jid1-fZHqN9JfrDBa8A@jetpack")
+ prefsjs = self.xpi.read('defaults/preferences/prefs.js').decode("utf-8")
+ self.failUnlessEqual(prefsjs, "")
+
+
+class Bug588119Tests(unittest.TestCase):
+ def makexpi(self, pkg_name):
+ self.xpiname = "%s.xpi" % pkg_name
+ create_xpi(self.xpiname, pkg_name, 'bug-588119-files')
+ self.xpi = zipfile.ZipFile(self.xpiname, 'r')
+ options = self.xpi.read('harness-options.json')
+ self.xpi_harness_options = json.loads(options)
+
+ def setUp(self):
+ self.xpiname = None
+ self.xpi = None
+
+ def tearDown(self):
+ if self.xpi:
+ self.xpi.close()
+ if self.xpiname and os.path.exists(self.xpiname):
+ os.remove(self.xpiname)
+
+ def testPackageWithImplicitIcon(self):
+ self.makexpi('implicit-icon')
+ assert 'icon.png' in self.xpi.namelist()
+
+ def testPackageWithImplicitIcon64(self):
+ self.makexpi('implicit-icon')
+ assert 'icon64.png' in self.xpi.namelist()
+
+ def testPackageWithExplicitIcon(self):
+ self.makexpi('explicit-icon')
+ assert 'icon.png' in self.xpi.namelist()
+
+ def testPackageWithExplicitIcon64(self):
+ self.makexpi('explicit-icon')
+ assert 'icon64.png' in self.xpi.namelist()
+
+ def testPackageWithNoIcon(self):
+ self.makexpi('no-icon')
+ assert 'icon.png' not in self.xpi.namelist()
+
+ def testIconPathNotInHarnessOptions(self):
+ self.makexpi('implicit-icon')
+ assert 'icon' not in self.xpi_harness_options
+
+ def testIcon64PathNotInHarnessOptions(self):
+ self.makexpi('implicit-icon')
+ assert 'icon64' not in self.xpi_harness_options
+
+class ExtraHarnessOptions(unittest.TestCase):
+ def setUp(self):
+ self.xpiname = None
+ self.xpi = None
+
+ def tearDown(self):
+ if self.xpi:
+ self.xpi.close()
+ if self.xpiname and os.path.exists(self.xpiname):
+ os.remove(self.xpiname)
+
+ def testOptions(self):
+ pkg_name = "extra-options"
+ self.xpiname = "%s.xpi" % pkg_name
+ create_xpi(self.xpiname, pkg_name, "bug-669274-files",
+ extra_harness_options={"builderVersion": "futuristic"})
+ self.xpi = zipfile.ZipFile(self.xpiname, 'r')
+ options = self.xpi.read('harness-options.json')
+ hopts = json.loads(options)
+ self.failUnless("builderVersion" in hopts)
+ self.failUnlessEqual(hopts["builderVersion"], "futuristic")
+
+ def testBadOptionName(self):
+ pkg_name = "extra-options"
+ self.xpiname = "%s.xpi" % pkg_name
+ self.failUnlessRaises(xpi.HarnessOptionAlreadyDefinedError,
+ create_xpi,
+ self.xpiname, pkg_name, "bug-669274-files",
+ extra_harness_options={"main": "already in use"})
+
+class SmallXPI(unittest.TestCase):
+ def setUp(self):
+ self.root = up(os.path.abspath(__file__), 4)
+ def get_linker_files_dir(self, name):
+ return os.path.join(up(os.path.abspath(__file__)), "linker-files", name)
+ def get_pkg(self, name):
+ d = self.get_linker_files_dir(name)
+ return packaging.get_config_in_dir(d)
+
+ def get_basedir(self):
+ return os.path.join(".test_tmp", self.id())
+ def make_basedir(self):
+ basedir = self.get_basedir()
+ if os.path.isdir(basedir):
+ here = os.path.abspath(os.getcwd())
+ assert os.path.abspath(basedir).startswith(here) # safety
+ shutil.rmtree(basedir)
+ os.makedirs(basedir)
+ return basedir
+
+ def test_contents(self):
+ target_cfg = self.get_pkg("three")
+ package_path = [self.get_linker_files_dir("three-deps")]
+ pkg_cfg = packaging.build_config(self.root, target_cfg,
+ packagepath=package_path)
+ deps = packaging.get_deps_for_targets(pkg_cfg,
+ [target_cfg.name, "addon-kit"])
+ m = manifest.build_manifest(target_cfg, pkg_cfg, deps, scan_tests=False)
+ used_files = list(m.get_used_files())
+ here = up(os.path.abspath(__file__))
+ def absify(*parts):
+ fn = os.path.join(here, "linker-files", *parts)
+ return os.path.abspath(fn)
+ expected = [absify(*parts) for parts in
+ [("three", "lib", "main.js"),
+ ("three-deps", "three-a", "lib", "main.js"),
+ ("three-deps", "three-a", "lib", "subdir", "subfile.js"),
+ ("three-deps", "three-a", "data", "msg.txt"),
+ ("three-deps", "three-a", "data", "subdir", "submsg.txt"),
+ ("three-deps", "three-b", "lib", "main.js"),
+ ("three-deps", "three-c", "lib", "main.js"),
+ ("three-deps", "three-c", "lib", "sub", "foo.js"),
+ ]]
+ missing = set(expected) - set(used_files)
+ extra = set(used_files) - set(expected)
+ self.failUnlessEqual((list(missing), list(extra)), ([], []))
+ used_deps = m.get_used_packages()
+
+ build = packaging.generate_build_for_target(pkg_cfg, target_cfg.name,
+ used_deps,
+ include_tests=False)
+ options = {'main': target_cfg.main}
+ options.update(build)
+ basedir = self.make_basedir()
+ xpi_name = os.path.join(basedir, "contents.xpi")
+ xpi.build_xpi(template_root_dir=xpi_template_path,
+ manifest=fake_manifest,
+ xpi_path=xpi_name,
+ harness_options=options,
+ limit_to=used_files)
+ x = zipfile.ZipFile(xpi_name, "r")
+ names = x.namelist()
+ expected = ["components/",
+ "components/harness.js",
+ # the real template also has 'bootstrap.js', but the fake
+ # one in tests/static-files/xpi-template doesn't
+ "harness-options.json",
+ "install.rdf",
+ "defaults/preferences/prefs.js",
+ "resources/",
+ "resources/api-utils/",
+ "resources/api-utils/data/",
+ "resources/api-utils/lib/",
+ "resources/three/",
+ "resources/three/lib/",
+ "resources/three/lib/main.js",
+ "resources/three-a/",
+ "resources/three-a/data/",
+ "resources/three-a/data/msg.txt",
+ "resources/three-a/data/subdir/",
+ "resources/three-a/data/subdir/submsg.txt",
+ "resources/three-a/lib/",
+ "resources/three-a/lib/main.js",
+ "resources/three-a/lib/subdir/",
+ "resources/three-a/lib/subdir/subfile.js",
+ "resources/three-b/",
+ "resources/three-b/lib/",
+ "resources/three-b/lib/main.js",
+ "resources/three-c/",
+ "resources/three-c/lib/",
+ "resources/three-c/lib/main.js",
+ "resources/three-c/lib/sub/",
+ "resources/three-c/lib/sub/foo.js",
+ # notably absent: three-a/lib/unused.js
+ "locale/",
+ "locale/fr-FR.json",
+ "locales.json",
+ ]
+ # showing deltas makes failures easier to investigate
+ missing = set(expected) - set(names)
+ extra = set(names) - set(expected)
+ self.failUnlessEqual((list(missing), list(extra)), ([], []))
+ self.failUnlessEqual(sorted(names), sorted(expected))
+
+ # check locale files
+ localedata = json.loads(x.read("locales.json"))
+ self.failUnlessEqual(sorted(localedata["locales"]), sorted(["fr-FR"]))
+ content = x.read("locale/fr-FR.json")
+ locales = json.loads(content)
+ # Locale files are merged into one.
+ # Conflicts are silently resolved by taking last package translation,
+ # so that we get "No" translation from three-c instead of three-b one.
+ self.failUnlessEqual(locales, json.loads(u'''
+ {
+ "No": "Nein",
+ "one": "un",
+ "What?": "Quoi?",
+ "Yes": "Oui",
+ "plural": {
+ "other": "other",
+ "one": "one"
+ },
+ "uft8_value": "\u00e9"
+ }'''))
+
+ def test_scantests(self):
+ target_cfg = self.get_pkg("three")
+ package_path = [self.get_linker_files_dir("three-deps")]
+ pkg_cfg = packaging.build_config(self.root, target_cfg,
+ packagepath=package_path)
+ deps = packaging.get_deps_for_targets(pkg_cfg,
+ [target_cfg.name, "addon-kit"])
+ m = manifest.build_manifest(target_cfg, pkg_cfg, deps, scan_tests=True)
+ self.failUnlessEqual(sorted(m.get_all_test_modules()),
+ sorted(["test-one", "test-two"]))
+ # the current __init__.py code omits limit_to=used_files for 'cfx
+ # test', so all test files are included in the XPI. But the test
+ # runner will only execute the tests that m.get_all_test_modules()
+ # tells us about (which are put into the .allTestModules property of
+ # harness-options.json).
+ used_deps = m.get_used_packages()
+
+ build = packaging.generate_build_for_target(pkg_cfg, target_cfg.name,
+ used_deps,
+ include_tests=True)
+ options = {'main': target_cfg.main}
+ options.update(build)
+ basedir = self.make_basedir()
+ xpi_name = os.path.join(basedir, "contents.xpi")
+ xpi.build_xpi(template_root_dir=xpi_template_path,
+ manifest=fake_manifest,
+ xpi_path=xpi_name,
+ harness_options=options,
+ limit_to=None)
+ x = zipfile.ZipFile(xpi_name, "r")
+ names = x.namelist()
+ self.failUnless("resources/api-utils/lib/unit-test.js" in names, names)
+ self.failUnless("resources/api-utils/lib/unit-test-finder.js" in names, names)
+ self.failUnless("resources/test-harness/lib/harness.js" in names, names)
+ self.failUnless("resources/test-harness/lib/run-tests.js" in names, names)
+ # all files are copied into the XPI, even the things that don't look
+ # like tests.
+ self.failUnless("resources/three/tests/test-one.js" in names, names)
+ self.failUnless("resources/three/tests/test-two.js" in names, names)
+ self.failUnless("resources/three/tests/nontest.js" in names, names)
+
+ def test_scantests_filter(self):
+ target_cfg = self.get_pkg("three")
+ package_path = [self.get_linker_files_dir("three-deps")]
+ pkg_cfg = packaging.build_config(self.root, target_cfg,
+ packagepath=package_path)
+ deps = packaging.get_deps_for_targets(pkg_cfg,
+ [target_cfg.name, "addon-kit"])
+ FILTER = ".*one.*"
+ m = manifest.build_manifest(target_cfg, pkg_cfg, deps, scan_tests=True,
+ test_filter_re=FILTER)
+ self.failUnlessEqual(sorted(m.get_all_test_modules()),
+ sorted(["test-one"]))
+ # the current __init__.py code omits limit_to=used_files for 'cfx
+ # test', so all test files are included in the XPI. But the test
+ # runner will only execute the tests that m.get_all_test_modules()
+ # tells us about (which are put into the .allTestModules property of
+ # harness-options.json).
+ used_deps = m.get_used_packages()
+
+ build = packaging.generate_build_for_target(pkg_cfg, target_cfg.name,
+ used_deps,
+ include_tests=True)
+ options = {'main': target_cfg.main}
+ options.update(build)
+ basedir = self.make_basedir()
+ xpi_name = os.path.join(basedir, "contents.xpi")
+ xpi.build_xpi(template_root_dir=xpi_template_path,
+ manifest=fake_manifest,
+ xpi_path=xpi_name,
+ harness_options=options,
+ limit_to=None)
+ x = zipfile.ZipFile(xpi_name, "r")
+ names = x.namelist()
+ self.failUnless("resources/api-utils/lib/unit-test.js" in names, names)
+ self.failUnless("resources/api-utils/lib/unit-test-finder.js" in names, names)
+ self.failUnless("resources/test-harness/lib/harness.js" in names, names)
+ self.failUnless("resources/test-harness/lib/run-tests.js" in names, names)
+ # get_all_test_modules() respects the filter. But all files are still
+ # copied into the XPI.
+ self.failUnless("resources/three/tests/test-one.js" in names, names)
+ self.failUnless("resources/three/tests/test-two.js" in names, names)
+ self.failUnless("resources/three/tests/nontest.js" in names, names)
+
+
+def document_dir(name):
+ if name in ['packages', 'xpi-template']:
+ dirname = os.path.join(test_packaging.static_files_path, name)
+ document_dir_files(dirname)
+ elif name == 'xpi-output':
+ create_xpi('test-xpi.xpi')
+ document_zip_file('test-xpi.xpi')
+ os.remove('test-xpi.xpi')
+ else:
+ raise Exception('unknown dir: %s' % name)
+
+def normpath(path):
+ """
+ Make a platform-specific relative path use '/' as a separator.
+ """
+
+ return path.replace(os.path.sep, '/')
+
+def document_zip_file(path):
+ zip = zipfile.ZipFile(path, 'r')
+ for name in sorted(zip.namelist()):
+ contents = zip.read(name)
+ lines = contents.splitlines()
+ if len(lines) == 1 and name.endswith('.json') and len(lines[0]) > 75:
+ # Ideally we would json-decode this, but it results
+ # in an annoying 'u' before every string literal,
+ # since json decoding makes all strings unicode.
+ contents = eval(contents)
+ contents = pprint.pformat(contents)
+ lines = contents.splitlines()
+ contents = "\n ".join(lines)
+ print "%s:\n %s" % (normpath(name), contents)
+ zip.close()
+
+def document_dir_files(path):
+ filename_contents_tuples = []
+ for dirpath, dirnames, filenames in os.walk(path):
+ relpath = dirpath[len(path)+1:]
+ for filename in filenames:
+ abspath = os.path.join(dirpath, filename)
+ contents = open(abspath, 'r').read()
+ contents = "\n ".join(contents.splitlines())
+ relfilename = os.path.join(relpath, filename)
+ filename_contents_tuples.append((normpath(relfilename), contents))
+ filename_contents_tuples.sort()
+ for filename, contents in filename_contents_tuples:
+ print "%s:" % filename
+ print " %s" % contents
+
+def create_xpi(xpiname, pkg_name='aardvark', dirname='static-files',
+ extra_harness_options={}):
+ configs = test_packaging.get_configs(pkg_name, dirname)
+ options = {'main': configs.target_cfg.main,
+ 'jetpackID': buildJID(configs.target_cfg), }
+ options.update(configs.build)
+ xpi.build_xpi(template_root_dir=xpi_template_path,
+ manifest=fake_manifest,
+ xpi_path=xpiname,
+ harness_options=options,
+ extra_harness_options=extra_harness_options)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/util.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/util.py
new file mode 100644
index 0000000..513495a
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/util.py
@@ -0,0 +1,23 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+IGNORED_FILE_PREFIXES = ["."]
+IGNORED_FILE_SUFFIXES = ["~", ".swp"]
+IGNORED_DIRS = [".git", ".svn", ".hg"]
+
+def filter_filenames(filenames, ignored_files=[".hgignore"]):
+ for filename in filenames:
+ if filename in ignored_files:
+ continue
+ if any([filename.startswith(suffix)
+ for suffix in IGNORED_FILE_PREFIXES]):
+ continue
+ if any([filename.endswith(suffix)
+ for suffix in IGNORED_FILE_SUFFIXES]):
+ continue
+ yield filename
+
+def filter_dirnames(dirnames):
+ return [dirname for dirname in dirnames if dirname not in IGNORED_DIRS]
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/version_comparator.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/version_comparator.py
new file mode 100644
index 0000000..3999e71
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/version_comparator.py
@@ -0,0 +1,206 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+'''
+ This is a really crummy, slow Python implementation of the Mozilla
+ platform's nsIVersionComparator interface:
+
+ https://developer.mozilla.org/En/NsIVersionComparator
+
+ For more information, also see:
+
+ http://mxr.mozilla.org/mozilla/source/xpcom/glue/nsVersionComparator.cpp
+'''
+
+import re
+import sys
+
+class VersionPart(object):
+ '''
+ Examples:
+
+ >>> VersionPart('1')
+ (1, None, 0, None)
+
+ >>> VersionPart('1pre')
+ (1, 'pre', 0, None)
+
+ >>> VersionPart('1pre10')
+ (1, 'pre', 10, None)
+
+ >>> VersionPart('1pre10a')
+ (1, 'pre', 10, 'a')
+
+ >>> VersionPart('1+')
+ (2, 'pre', 0, None)
+
+ >>> VersionPart('*').numA == sys.maxint
+ True
+
+ >>> VersionPart('1') < VersionPart('2')
+ True
+
+ >>> VersionPart('2') > VersionPart('1')
+ True
+
+ >>> VersionPart('1') == VersionPart('1')
+ True
+
+ >>> VersionPart('1pre') > VersionPart('1')
+ False
+
+ >>> VersionPart('1') < VersionPart('1pre')
+ False
+
+ >>> VersionPart('1pre1') < VersionPart('1pre2')
+ True
+
+ >>> VersionPart('1pre10b') > VersionPart('1pre10a')
+ True
+
+ >>> VersionPart('1pre10b') == VersionPart('1pre10b')
+ True
+
+ >>> VersionPart('1pre10a') < VersionPart('1pre10b')
+ True
+
+ >>> VersionPart('1') > VersionPart('')
+ True
+ '''
+
+ _int_part = re.compile('[+-]?(\d*)(.*)')
+ _num_chars = '0123456789+-'
+
+ def __init__(self, part):
+ self.numA = 0
+ self.strB = None
+ self.numC = 0
+ self.extraD = None
+
+ if not part:
+ return
+
+ if part == '*':
+ self.numA = sys.maxint
+ else:
+ match = self._int_part.match(part)
+ self.numA = int(match.group(1))
+ self.strB = match.group(2) or None
+ if self.strB == '+':
+ self.strB = 'pre'
+ self.numA += 1
+ elif self.strB:
+ i = 0
+ num_found = -1
+ for char in self.strB:
+ if char in self._num_chars:
+ num_found = i
+ break
+ i += 1
+ if num_found != -1:
+ match = self._int_part.match(self.strB[num_found:])
+ self.numC = int(match.group(1))
+ self.extraD = match.group(2) or None
+ self.strB = self.strB[:num_found]
+
+ def _strcmp(self, str1, str2):
+ # Any string is *before* no string.
+ if str1 is None:
+ if str2 is None:
+ return 0
+ else:
+ return 1
+
+ if str2 is None:
+ return -1
+
+ return cmp(str1, str2)
+
+ def __cmp__(self, other):
+ r = cmp(self.numA, other.numA)
+ if r:
+ return r
+
+ r = self._strcmp(self.strB, other.strB)
+ if r:
+ return r
+
+ r = cmp(self.numC, other.numC)
+ if r:
+ return r
+
+ return self._strcmp(self.extraD, other.extraD)
+
+ def __repr__(self):
+ return repr((self.numA, self.strB, self.numC, self.extraD))
+
+def compare(a, b):
+ '''
+ Examples:
+
+ >>> compare('1', '2')
+ -1
+
+ >>> compare('1', '1')
+ 0
+
+ >>> compare('2', '1')
+ 1
+
+ >>> compare('1.0pre1', '1.0pre2')
+ -1
+
+ >>> compare('1.0pre2', '1.0')
+ -1
+
+ >>> compare('1.0', '1.0.0')
+ 0
+
+ >>> compare('1.0.0', '1.0.0.0')
+ 0
+
+ >>> compare('1.0.0.0', '1.1pre')
+ -1
+
+ >>> compare('1.1pre', '1.1pre0')
+ 0
+
+ >>> compare('1.1pre0', '1.0+')
+ 0
+
+ >>> compare('1.0+', '1.1pre1a')
+ -1
+
+ >>> compare('1.1pre1a', '1.1pre1')
+ -1
+
+ >>> compare('1.1pre1', '1.1pre10a')
+ -1
+
+ >>> compare('1.1pre10a', '1.1pre10')
+ -1
+
+ >>> compare('1.1pre10a', '1.*')
+ -1
+ '''
+
+ a_parts = a.split('.')
+ b_parts = b.split('.')
+
+ if len(a_parts) < len(b_parts):
+ a_parts.extend([''] * (len(b_parts) - len(a_parts)))
+ else:
+ b_parts.extend([''] * (len(a_parts) - len(b_parts)))
+
+ for a_part, b_part in zip(a_parts, b_parts):
+ r = cmp(VersionPart(a_part), VersionPart(b_part))
+ if r:
+ return r
+
+ return 0
+
+if __name__ == '__main__':
+ import doctest
+
+ doctest.testmod(verbose=True)
diff --git a/tools/addon-sdk-1.7/python-lib/cuddlefish/xpi.py b/tools/addon-sdk-1.7/python-lib/cuddlefish/xpi.py
new file mode 100644
index 0000000..72b8477
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/cuddlefish/xpi.py
@@ -0,0 +1,155 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import zipfile
+import simplejson as json
+from cuddlefish.util import filter_filenames, filter_dirnames
+
+class HarnessOptionAlreadyDefinedError(Exception):
+ """You cannot use --harness-option on keys that already exist in
+ harness-options.json"""
+
+ZIPSEP = "/" # always use "/" in zipfiles
+
+def make_zipfile_path(localroot, localpath):
+ return ZIPSEP.join(localpath[len(localroot)+1:].split(os.sep))
+
+def mkzipdir(zf, path):
+ dirinfo = zipfile.ZipInfo(path)
+ dirinfo.external_attr = int("040755", 8) << 16L
+ zf.writestr(dirinfo, "")
+
+def build_xpi(template_root_dir, manifest, xpi_path,
+ harness_options, limit_to=None, extra_harness_options={}):
+ zf = zipfile.ZipFile(xpi_path, "w", zipfile.ZIP_DEFLATED)
+
+ open('.install.rdf', 'w').write(str(manifest))
+ zf.write('.install.rdf', 'install.rdf')
+ os.remove('.install.rdf')
+
+ if 'icon' in harness_options:
+ zf.write(str(harness_options['icon']), 'icon.png')
+ del harness_options['icon']
+
+ if 'icon64' in harness_options:
+ zf.write(str(harness_options['icon64']), 'icon64.png')
+ del harness_options['icon64']
+
+ if 'preferences' in harness_options:
+ from options_xul import parse_options, validate_prefs
+
+ validate_prefs(harness_options["preferences"])
+
+ opts_xul = parse_options(harness_options["preferences"],
+ harness_options["jetpackID"])
+ open('.options.xul', 'wb').write(opts_xul.encode("utf-8"))
+ zf.write('.options.xul', 'options.xul')
+ os.remove('.options.xul')
+
+ from options_defaults import parse_options_defaults
+ prefs_js = parse_options_defaults(harness_options["preferences"],
+ harness_options["jetpackID"])
+ open('.prefs.js', 'wb').write(prefs_js.encode("utf-8"))
+
+ else:
+ open('.prefs.js', 'wb').write("")
+
+ zf.write('.prefs.js', 'defaults/preferences/prefs.js')
+ os.remove('.prefs.js')
+
+
+ IGNORED_FILES = [".hgignore", ".DS_Store", "install.rdf",
+ "application.ini", xpi_path]
+
+ files_to_copy = {} # maps zipfile path to local-disk abspath
+ dirs_to_create = set() # zipfile paths, no trailing slash
+
+ for dirpath, dirnames, filenames in os.walk(template_root_dir):
+ filenames = list(filter_filenames(filenames, IGNORED_FILES))
+ dirnames[:] = filter_dirnames(dirnames)
+ for dirname in dirnames:
+ arcpath = make_zipfile_path(template_root_dir,
+ os.path.join(dirpath, dirname))
+ dirs_to_create.add(arcpath)
+ for filename in filenames:
+ abspath = os.path.join(dirpath, filename)
+ arcpath = make_zipfile_path(template_root_dir, abspath)
+ files_to_copy[arcpath] = abspath
+
+ # `packages` attribute contains a dictionnary of dictionnary
+ # of all packages sections directories
+ for packageName in harness_options['packages']:
+ base_arcpath = ZIPSEP.join(['resources', packageName])
+ # Always write the top directory, even if it contains no files, since
+ # the harness will try to access it.
+ dirs_to_create.add(base_arcpath)
+ for sectionName in harness_options['packages'][packageName]:
+ abs_dirname = harness_options['packages'][packageName][sectionName]
+ base_arcpath = ZIPSEP.join(['resources', packageName, sectionName])
+ # Always write the top directory, even if it contains no files, since
+ # the harness will try to access it.
+ dirs_to_create.add(base_arcpath)
+ # cp -r stuff from abs_dirname/ into ZIP/resources/RESOURCEBASE/
+ for dirpath, dirnames, filenames in os.walk(abs_dirname):
+ goodfiles = list(filter_filenames(filenames, IGNORED_FILES))
+ dirnames[:] = filter_dirnames(dirnames)
+ for filename in goodfiles:
+ abspath = os.path.join(dirpath, filename)
+ if limit_to is not None and abspath not in limit_to:
+ continue # strip unused files
+ arcpath = ZIPSEP.join(
+ ['resources',
+ packageName,
+ sectionName,
+ make_zipfile_path(abs_dirname,
+ os.path.join(dirpath, filename)),
+ ])
+ files_to_copy[str(arcpath)] = str(abspath)
+ del harness_options['packages']
+
+ locales_json_data = {"locales": []}
+ mkzipdir(zf, "locale/")
+ for language in sorted(harness_options['locale']):
+ locales_json_data["locales"].append(language)
+ locale = harness_options['locale'][language]
+ # Be carefull about strings, we need to always ensure working with UTF-8
+ jsonStr = json.dumps(locale, indent=1, sort_keys=True, ensure_ascii=False)
+ info = zipfile.ZipInfo('locale/' + language + '.json')
+ info.external_attr = 0444 << 16L
+ zf.writestr(info, jsonStr.encode( "utf-8" ))
+ del harness_options['locale']
+
+ jsonStr = json.dumps(locales_json_data, ensure_ascii=True) +"\n"
+ info = zipfile.ZipInfo('locales.json')
+ info.external_attr = 0444 << 16L
+ zf.writestr(info, jsonStr.encode("utf-8"))
+
+ # now figure out which directories we need: all retained files parents
+ for arcpath in files_to_copy:
+ bits = arcpath.split("/")
+ for i in range(1,len(bits)):
+ parentpath = ZIPSEP.join(bits[0:i])
+ dirs_to_create.add(parentpath)
+
+ # create zipfile in alphabetical order, with each directory before its
+ # files
+ for name in sorted(dirs_to_create.union(set(files_to_copy))):
+ if name in dirs_to_create:
+ mkzipdir(zf, name+"/")
+ if name in files_to_copy:
+ zf.write(files_to_copy[name], name)
+
+ harness_options = harness_options.copy()
+ for key,value in extra_harness_options.items():
+ if key in harness_options:
+ msg = "Can't use --harness-option for existing key '%s'" % key
+ raise HarnessOptionAlreadyDefinedError(msg)
+ harness_options[key] = value
+ open('.options.json', 'w').write(json.dumps(harness_options, indent=1,
+ sort_keys=True))
+ zf.write('.options.json', 'harness-options.json')
+ os.remove('.options.json')
+
+ zf.close()
diff --git a/tools/addon-sdk-1.7/python-lib/jetpack_sdk_env.py b/tools/addon-sdk-1.7/python-lib/jetpack_sdk_env.py
new file mode 100644
index 0000000..79fdd61
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/jetpack_sdk_env.py
@@ -0,0 +1,66 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import sys
+import os
+
+def welcome():
+ """
+ Perform a bunch of sanity tests to make sure the Add-on SDK
+ environment is sane, and then display a welcome message.
+ """
+
+ try:
+ if sys.version_info[0] > 2:
+ print ("Error: You appear to be using Python %d, but "
+ "the Add-on SDK only supports the Python 2.x line." %
+ (sys.version_info[0]))
+ return
+
+ import mozrunner
+
+ if 'CUDDLEFISH_ROOT' not in os.environ:
+ print ("Error: CUDDLEFISH_ROOT environment variable does "
+ "not exist! It should point to the root of the "
+ "Add-on SDK repository.")
+ return
+
+ env_root = os.environ['CUDDLEFISH_ROOT']
+
+ bin_dir = os.path.join(env_root, 'bin')
+ python_lib_dir = os.path.join(env_root, 'python-lib')
+ path = os.environ['PATH'].split(os.path.pathsep)
+
+ if bin_dir not in path:
+ print ("Warning: the Add-on SDK binary directory %s "
+ "does not appear to be in your PATH. You may "
+ "not be able to run 'cfx' or other SDK tools." %
+ bin_dir)
+
+ if python_lib_dir not in sys.path:
+ print ("Warning: the Add-on SDK python-lib directory %s "
+ "does not appear to be in your sys.path, which "
+ "is odd because I'm running from it." % python_lib_dir)
+
+ if not mozrunner.__path__[0].startswith(env_root):
+ print ("Warning: your mozrunner package is installed at %s, "
+ "which does not seem to be located inside the Jetpack "
+ "SDK. This may cause problems, and you may want to "
+ "uninstall the other version. See bug 556562 for "
+ "more information." % mozrunner.__path__[0])
+ except Exception:
+ # Apparently we can't get the actual exception object in the
+ # 'except' clause in a way that's syntax-compatible for both
+ # Python 2.x and 3.x, so we'll have to use the traceback module.
+
+ import traceback
+ _, e, _ = sys.exc_info()
+ print ("Verification of Add-on SDK environment failed (%s)." % e)
+ print ("Your SDK may not work properly.")
+ return
+
+ print ("Welcome to the Add-on SDK. Run 'cfx docs' for assistance.")
+
+if __name__ == '__main__':
+ welcome()
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/AUTHORS b/tools/addon-sdk-1.7/python-lib/markdown/AUTHORS
new file mode 100644
index 0000000..cfe2b34
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/AUTHORS
@@ -0,0 +1,43 @@
+Primary Authors
+===============
+
+Yuri Takteyev <http://freewisdom.org/>, who has written much of the current code
+while procrastingating his Ph.D.
+
+Waylan Limberg <http://achinghead.com/>, who has written most of the available
+extensions and later was asked to join Yuri, fixing nummrious bugs, adding
+documentation and making general improvements to the existing codebase,
+included a complete refactor of the core.
+
+Artem Yunusov, who as part of a 2008 GSoC project, has refactored inline
+patterns, replaced the NanoDOM with ElementTree support and made various other
+improvements.
+
+Manfed Stienstra <http://www.dwerg.net/>, who wrote the original version of
+the script and is responsible for various parts of the existing codebase.
+
+David Wolever, who refactored the extension API and made other improvements
+as he helped to integrate Markdown into Dr.Project.
+
+Other Contributors
+==================
+
+The incomplete list of individuals below have provided patches or otherwise
+contributed to the project in various ways. We would like to thank everyone
+who has contributed to the progect in any way.
+
+Eric Abrahamsen
+Jeff Balogh
+Sergej Chodarev
+Chris Clark
+Tiago Cogumbreiro
+Kjell Magne Fauske
+G. Clark Haynes
+Daniel Krech
+Steward Midwinter
+Jack Miller
+Neale Pickett
+John Szakmeister
+Malcolm Tredinnick
+Ben Wilson
+and many others who helped by reporting bugs
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/LICENSE b/tools/addon-sdk-1.7/python-lib/markdown/LICENSE
new file mode 100644
index 0000000..4cd8b14
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/LICENSE
@@ -0,0 +1,30 @@
+Copyright 2007, 2008 The Python Markdown Project (v. 1.7 and later)
+Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b)
+Copyright 2004 Manfred Stienstra (the original version)
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+* Neither the name of the <organization> nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE PYTHON MARKDOWN PROJECT ''AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL ANY CONTRIBUTORS TO THE PYTHON MARKDOWN PROJECT
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/__init__.py b/tools/addon-sdk-1.7/python-lib/markdown/__init__.py
new file mode 100644
index 0000000..0d1c504
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/__init__.py
@@ -0,0 +1,603 @@
+"""
+Python Markdown
+===============
+
+Python Markdown converts Markdown to HTML and can be used as a library or
+called from the command line.
+
+## Basic usage as a module:
+
+ import markdown
+ md = Markdown()
+ html = md.convert(your_text_string)
+
+## Basic use from the command line:
+
+ python markdown.py source.txt > destination.html
+
+Run "python markdown.py --help" to see more options.
+
+## Extensions
+
+See <http://www.freewisdom.org/projects/python-markdown/> for more
+information and instructions on how to extend the functionality of
+Python Markdown. Read that before you try modifying this file.
+
+## Authors and License
+
+Started by [Manfred Stienstra](http://www.dwerg.net/). Continued and
+maintained by [Yuri Takhteyev](http://www.freewisdom.org), [Waylan
+Limberg](http://achinghead.com/) and [Artem Yunusov](http://blog.splyer.com).
+
+Contact: markdown@freewisdom.org
+
+Copyright 2007, 2008 The Python Markdown Project (v. 1.7 and later)
+Copyright 200? Django Software Foundation (OrderedDict implementation)
+Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b)
+Copyright 2004 Manfred Stienstra (the original version)
+
+License: BSD (see docs/LICENSE for details).
+"""
+
+version = "2.0"
+version_info = (2,0,0, "Final")
+
+import re
+import codecs
+import sys
+import warnings
+import logging
+from logging import DEBUG, INFO, WARN, ERROR, CRITICAL
+
+
+"""
+CONSTANTS
+=============================================================================
+"""
+
+"""
+Constants you might want to modify
+-----------------------------------------------------------------------------
+"""
+
+# default logging level for command-line use
+COMMAND_LINE_LOGGING_LEVEL = CRITICAL
+TAB_LENGTH = 4 # expand tabs to this many spaces
+ENABLE_ATTRIBUTES = True # @id = xyz -> <... id="xyz">
+SMART_EMPHASIS = True # this_or_that does not become this<i>or</i>that
+DEFAULT_OUTPUT_FORMAT = 'xhtml1' # xhtml or html4 output
+HTML_REMOVED_TEXT = "[HTML_REMOVED]" # text used instead of HTML in safe mode
+BLOCK_LEVEL_ELEMENTS = re.compile("p|div|h[1-6]|blockquote|pre|table|dl|ol|ul"
+ "|script|noscript|form|fieldset|iframe|math"
+ "|ins|del|hr|hr/|style|li|dt|dd|thead|tbody"
+ "|tr|th|td")
+DOC_TAG = "div" # Element used to wrap document - later removed
+
+# Placeholders
+STX = u'\u0002' # Use STX ("Start of text") for start-of-placeholder
+ETX = u'\u0003' # Use ETX ("End of text") for end-of-placeholder
+INLINE_PLACEHOLDER_PREFIX = STX+"klzzwxh:"
+INLINE_PLACEHOLDER = INLINE_PLACEHOLDER_PREFIX + "%s" + ETX
+AMP_SUBSTITUTE = STX+"amp"+ETX
+
+
+"""
+Constants you probably do not need to change
+-----------------------------------------------------------------------------
+"""
+
+RTL_BIDI_RANGES = ( (u'\u0590', u'\u07FF'),
+ # Hebrew (0590-05FF), Arabic (0600-06FF),
+ # Syriac (0700-074F), Arabic supplement (0750-077F),
+ # Thaana (0780-07BF), Nko (07C0-07FF).
+ (u'\u2D30', u'\u2D7F'), # Tifinagh
+ )
+
+
+"""
+AUXILIARY GLOBAL FUNCTIONS
+=============================================================================
+"""
+
+
+def message(level, text):
+ """ A wrapper method for logging debug messages. """
+ logger = logging.getLogger('MARKDOWN')
+ if logger.handlers:
+ # The logger is configured
+ logger.log(level, text)
+ if level > WARN:
+ sys.exit(0)
+ elif level > WARN:
+ raise MarkdownException, text
+ else:
+ warnings.warn(text, MarkdownWarning)
+
+
+def isBlockLevel(tag):
+ """Check if the tag is a block level HTML tag."""
+ return BLOCK_LEVEL_ELEMENTS.match(tag)
+
+"""
+MISC AUXILIARY CLASSES
+=============================================================================
+"""
+
+class AtomicString(unicode):
+ """A string which should not be further processed."""
+ pass
+
+
+class MarkdownException(Exception):
+ """ A Markdown Exception. """
+ pass
+
+
+class MarkdownWarning(Warning):
+ """ A Markdown Warning. """
+ pass
+
+
+"""
+OVERALL DESIGN
+=============================================================================
+
+Markdown processing takes place in four steps:
+
+1. A bunch of "preprocessors" munge the input text.
+2. BlockParser() parses the high-level structural elements of the
+ pre-processed text into an ElementTree.
+3. A bunch of "treeprocessors" are run against the ElementTree. One such
+ treeprocessor runs InlinePatterns against the ElementTree, detecting inline
+ markup.
+4. Some post-processors are run against the text after the ElementTree has
+ been serialized into text.
+5. The output is written to a string.
+
+Those steps are put together by the Markdown() class.
+
+"""
+
+import preprocessors
+import blockprocessors
+import treeprocessors
+import inlinepatterns
+import postprocessors
+import blockparser
+import etree_loader
+import odict
+
+# Extensions should use "markdown.etree" instead of "etree" (or do `from
+# markdown import etree`). Do not import it by yourself.
+
+etree = etree_loader.importETree()
+
+# Adds the ability to output html4
+import html4
+
+
+class Markdown:
+ """Convert Markdown to HTML."""
+
+ def __init__(self,
+ extensions=[],
+ extension_configs={},
+ safe_mode = False,
+ output_format=DEFAULT_OUTPUT_FORMAT):
+ """
+ Creates a new Markdown instance.
+
+ Keyword arguments:
+
+ * extensions: A list of extensions.
+ If they are of type string, the module mdx_name.py will be loaded.
+ If they are a subclass of markdown.Extension, they will be used
+ as-is.
+ * extension-configs: Configuration setting for extensions.
+ * safe_mode: Disallow raw html. One of "remove", "replace" or "escape".
+ * output_format: Format of output. Supported formats are:
+ * "xhtml1": Outputs XHTML 1.x. Default.
+ * "xhtml": Outputs latest supported version of XHTML (currently XHTML 1.1).
+ * "html4": Outputs HTML 4
+ * "html": Outputs latest supported version of HTML (currently HTML 4).
+ Note that it is suggested that the more specific formats ("xhtml1"
+ and "html4") be used as "xhtml" or "html" may change in the future
+ if it makes sense at that time.
+
+ """
+
+ self.safeMode = safe_mode
+ self.registeredExtensions = []
+ self.docType = ""
+ self.stripTopLevelTags = True
+
+ # Preprocessors
+ self.preprocessors = odict.OrderedDict()
+ self.preprocessors["html_block"] = \
+ preprocessors.HtmlBlockPreprocessor(self)
+ self.preprocessors["reference"] = \
+ preprocessors.ReferencePreprocessor(self)
+ # footnote preprocessor will be inserted with "<reference"
+
+ # Block processors - ran by the parser
+ self.parser = blockparser.BlockParser()
+ self.parser.blockprocessors['empty'] = \
+ blockprocessors.EmptyBlockProcessor(self.parser)
+ self.parser.blockprocessors['indent'] = \
+ blockprocessors.ListIndentProcessor(self.parser)
+ self.parser.blockprocessors['code'] = \
+ blockprocessors.CodeBlockProcessor(self.parser)
+ self.parser.blockprocessors['hashheader'] = \
+ blockprocessors.HashHeaderProcessor(self.parser)
+ self.parser.blockprocessors['setextheader'] = \
+ blockprocessors.SetextHeaderProcessor(self.parser)
+ self.parser.blockprocessors['hr'] = \
+ blockprocessors.HRProcessor(self.parser)
+ self.parser.blockprocessors['olist'] = \
+ blockprocessors.OListProcessor(self.parser)
+ self.parser.blockprocessors['ulist'] = \
+ blockprocessors.UListProcessor(self.parser)
+ self.parser.blockprocessors['quote'] = \
+ blockprocessors.BlockQuoteProcessor(self.parser)
+ self.parser.blockprocessors['paragraph'] = \
+ blockprocessors.ParagraphProcessor(self.parser)
+
+
+ #self.prePatterns = []
+
+ # Inline patterns - Run on the tree
+ self.inlinePatterns = odict.OrderedDict()
+ self.inlinePatterns["backtick"] = \
+ inlinepatterns.BacktickPattern(inlinepatterns.BACKTICK_RE)
+ self.inlinePatterns["escape"] = \
+ inlinepatterns.SimpleTextPattern(inlinepatterns.ESCAPE_RE)
+ self.inlinePatterns["reference"] = \
+ inlinepatterns.ReferencePattern(inlinepatterns.REFERENCE_RE, self)
+ self.inlinePatterns["link"] = \
+ inlinepatterns.LinkPattern(inlinepatterns.LINK_RE, self)
+ self.inlinePatterns["image_link"] = \
+ inlinepatterns.ImagePattern(inlinepatterns.IMAGE_LINK_RE, self)
+ self.inlinePatterns["image_reference"] = \
+ inlinepatterns.ImageReferencePattern(inlinepatterns.IMAGE_REFERENCE_RE, self)
+ self.inlinePatterns["autolink"] = \
+ inlinepatterns.AutolinkPattern(inlinepatterns.AUTOLINK_RE, self)
+ self.inlinePatterns["automail"] = \
+ inlinepatterns.AutomailPattern(inlinepatterns.AUTOMAIL_RE, self)
+ self.inlinePatterns["linebreak2"] = \
+ inlinepatterns.SubstituteTagPattern(inlinepatterns.LINE_BREAK_2_RE, 'br')
+ self.inlinePatterns["linebreak"] = \
+ inlinepatterns.SubstituteTagPattern(inlinepatterns.LINE_BREAK_RE, 'br')
+ self.inlinePatterns["html"] = \
+ inlinepatterns.HtmlPattern(inlinepatterns.HTML_RE, self)
+ self.inlinePatterns["entity"] = \
+ inlinepatterns.HtmlPattern(inlinepatterns.ENTITY_RE, self)
+ self.inlinePatterns["not_strong"] = \
+ inlinepatterns.SimpleTextPattern(inlinepatterns.NOT_STRONG_RE)
+ self.inlinePatterns["strong_em"] = \
+ inlinepatterns.DoubleTagPattern(inlinepatterns.STRONG_EM_RE, 'strong,em')
+ self.inlinePatterns["strong"] = \
+ inlinepatterns.SimpleTagPattern(inlinepatterns.STRONG_RE, 'strong')
+ self.inlinePatterns["emphasis"] = \
+ inlinepatterns.SimpleTagPattern(inlinepatterns.EMPHASIS_RE, 'em')
+ self.inlinePatterns["emphasis2"] = \
+ inlinepatterns.SimpleTagPattern(inlinepatterns.EMPHASIS_2_RE, 'em')
+ # The order of the handlers matters!!!
+
+
+ # Tree processors - run once we have a basic parse.
+ self.treeprocessors = odict.OrderedDict()
+ self.treeprocessors["inline"] = treeprocessors.InlineProcessor(self)
+ self.treeprocessors["prettify"] = \
+ treeprocessors.PrettifyTreeprocessor(self)
+
+ # Postprocessors - finishing touches.
+ self.postprocessors = odict.OrderedDict()
+ self.postprocessors["raw_html"] = \
+ postprocessors.RawHtmlPostprocessor(self)
+ self.postprocessors["amp_substitute"] = \
+ postprocessors.AndSubstitutePostprocessor()
+ # footnote postprocessor will be inserted with ">amp_substitute"
+
+ # Map format keys to serializers
+ self.output_formats = {
+ 'html' : html4.to_html_string,
+ 'html4' : html4.to_html_string,
+ 'xhtml' : etree.tostring,
+ 'xhtml1': etree.tostring,
+ }
+
+ self.references = {}
+ self.htmlStash = preprocessors.HtmlStash()
+ self.registerExtensions(extensions = extensions,
+ configs = extension_configs)
+ self.set_output_format(output_format)
+ self.reset()
+
+ def registerExtensions(self, extensions, configs):
+ """
+ Register extensions with this instance of Markdown.
+
+ Keyword aurguments:
+
+ * extensions: A list of extensions, which can either
+ be strings or objects. See the docstring on Markdown.
+ * configs: A dictionary mapping module names to config options.
+
+ """
+ for ext in extensions:
+ if isinstance(ext, basestring):
+ ext = load_extension(ext, configs.get(ext, []))
+ try:
+ ext.extendMarkdown(self, globals())
+ except AttributeError:
+ message(ERROR, "Incorrect type! Extension '%s' is "
+ "neither a string or an Extension." %(repr(ext)))
+
+
+ def registerExtension(self, extension):
+ """ This gets called by the extension """
+ self.registeredExtensions.append(extension)
+
+ def reset(self):
+ """
+ Resets all state variables so that we can start with a new text.
+ """
+ self.htmlStash.reset()
+ self.references.clear()
+
+ for extension in self.registeredExtensions:
+ extension.reset()
+
+ def set_output_format(self, format):
+ """ Set the output format for the class instance. """
+ try:
+ self.serializer = self.output_formats[format.lower()]
+ except KeyError:
+ message(CRITICAL, 'Invalid Output Format: "%s". Use one of %s.' \
+ % (format, self.output_formats.keys()))
+
+ def convert(self, source):
+ """
+ Convert markdown to serialized XHTML or HTML.
+
+ Keyword arguments:
+
+ * source: Source text as a Unicode string.
+
+ """
+
+ # Fixup the source text
+ if not source.strip():
+ return u"" # a blank unicode string
+ try:
+ source = unicode(source)
+ except UnicodeDecodeError:
+ message(CRITICAL, 'UnicodeDecodeError: Markdown only accepts unicode or ascii input.')
+ return u""
+
+ source = source.replace(STX, "").replace(ETX, "")
+ source = source.replace("\r\n", "\n").replace("\r", "\n") + "\n\n"
+ source = re.sub(r'\n\s+\n', '\n\n', source)
+ source = source.expandtabs(TAB_LENGTH)
+
+ # Split into lines and run the line preprocessors.
+ self.lines = source.split("\n")
+ for prep in self.preprocessors.values():
+ self.lines = prep.run(self.lines)
+
+ # Parse the high-level elements.
+ root = self.parser.parseDocument(self.lines).getroot()
+
+ # Run the tree-processors
+ for treeprocessor in self.treeprocessors.values():
+ newRoot = treeprocessor.run(root)
+ if newRoot:
+ root = newRoot
+
+ # Serialize _properly_. Strip top-level tags.
+ output, length = codecs.utf_8_decode(self.serializer(root, encoding="utf8"))
+ if self.stripTopLevelTags:
+ start = output.index('<%s>'%DOC_TAG)+len(DOC_TAG)+2
+ end = output.rindex('</%s>'%DOC_TAG)
+ output = output[start:end].strip()
+
+ # Run the text post-processors
+ for pp in self.postprocessors.values():
+ output = pp.run(output)
+
+ return output.strip()
+
+ def convertFile(self, input=None, output=None, encoding=None):
+ """Converts a markdown file and returns the HTML as a unicode string.
+
+ Decodes the file using the provided encoding (defaults to utf-8),
+ passes the file content to markdown, and outputs the html to either
+ the provided stream or the file with provided name, using the same
+ encoding as the source file.
+
+ **Note:** This is the only place that decoding and encoding of unicode
+ takes place in Python-Markdown. (All other code is unicode-in /
+ unicode-out.)
+
+ Keyword arguments:
+
+ * input: Name of source text file.
+ * output: Name of output file. Writes to stdout if `None`.
+ * encoding: Encoding of input and output files. Defaults to utf-8.
+
+ """
+
+ encoding = encoding or "utf-8"
+
+ # Read the source
+ input_file = codecs.open(input, mode="r", encoding=encoding)
+ text = input_file.read()
+ input_file.close()
+ text = text.lstrip(u'\ufeff') # remove the byte-order mark
+
+ # Convert
+ html = self.convert(text)
+
+ # Write to file or stdout
+ if isinstance(output, (str, unicode)):
+ output_file = codecs.open(output, "w", encoding=encoding)
+ output_file.write(html)
+ output_file.close()
+ else:
+ output.write(html.encode(encoding))
+
+
+"""
+Extensions
+-----------------------------------------------------------------------------
+"""
+
+class Extension:
+ """ Base class for extensions to subclass. """
+ def __init__(self, configs = {}):
+ """Create an instance of an Extention.
+
+ Keyword arguments:
+
+ * configs: A dict of configuration setting used by an Extension.
+ """
+ self.config = configs
+
+ def getConfig(self, key):
+ """ Return a setting for the given key or an empty string. """
+ if key in self.config:
+ return self.config[key][0]
+ else:
+ return ""
+
+ def getConfigInfo(self):
+ """ Return all config settings as a list of tuples. """
+ return [(key, self.config[key][1]) for key in self.config.keys()]
+
+ def setConfig(self, key, value):
+ """ Set a config setting for `key` with the given `value`. """
+ self.config[key][0] = value
+
+ def extendMarkdown(self, md, md_globals):
+ """
+ Add the various proccesors and patterns to the Markdown Instance.
+
+ This method must be overriden by every extension.
+
+ Keyword arguments:
+
+ * md: The Markdown instance.
+
+ * md_globals: Global variables in the markdown module namespace.
+
+ """
+ pass
+
+
+def load_extension(ext_name, configs = []):
+ """Load extension by name, then return the module.
+
+ The extension name may contain arguments as part of the string in the
+ following format: "extname(key1=value1,key2=value2)"
+
+ """
+
+ # Parse extensions config params (ignore the order)
+ configs = dict(configs)
+ pos = ext_name.find("(") # find the first "("
+ if pos > 0:
+ ext_args = ext_name[pos+1:-1]
+ ext_name = ext_name[:pos]
+ pairs = [x.split("=") for x in ext_args.split(",")]
+ configs.update([(x.strip(), y.strip()) for (x, y) in pairs])
+
+ # Setup the module names
+ ext_module = 'markdown.extensions'
+ module_name_new_style = '.'.join([ext_module, ext_name])
+ module_name_old_style = '_'.join(['mdx', ext_name])
+
+ # Try loading the extention first from one place, then another
+ try: # New style (markdown.extensons.<extension>)
+ module = __import__(module_name_new_style, {}, {}, [ext_module])
+ except ImportError:
+ try: # Old style (mdx.<extension>)
+ module = __import__(module_name_old_style)
+ except ImportError:
+ message(WARN, "Failed loading extension '%s' from '%s' or '%s'"
+ % (ext_name, module_name_new_style, module_name_old_style))
+ # Return None so we don't try to initiate none-existant extension
+ return None
+
+ # If the module is loaded successfully, we expect it to define a
+ # function called makeExtension()
+ try:
+ return module.makeExtension(configs.items())
+ except AttributeError:
+ message(CRITICAL, "Failed to initiate extension '%s'" % ext_name)
+
+
+def load_extensions(ext_names):
+ """Loads multiple extensions"""
+ extensions = []
+ for ext_name in ext_names:
+ extension = load_extension(ext_name)
+ if extension:
+ extensions.append(extension)
+ return extensions
+
+
+"""
+EXPORTED FUNCTIONS
+=============================================================================
+
+Those are the two functions we really mean to export: markdown() and
+markdownFromFile().
+"""
+
+def markdown(text,
+ extensions = [],
+ safe_mode = False,
+ output_format = DEFAULT_OUTPUT_FORMAT):
+ """Convert a markdown string to HTML and return HTML as a unicode string.
+
+ This is a shortcut function for `Markdown` class to cover the most
+ basic use case. It initializes an instance of Markdown, loads the
+ necessary extensions and runs the parser on the given text.
+
+ Keyword arguments:
+
+ * text: Markdown formatted text as Unicode or ASCII string.
+ * extensions: A list of extensions or extension names (may contain config args).
+ * safe_mode: Disallow raw html. One of "remove", "replace" or "escape".
+ * output_format: Format of output. Supported formats are:
+ * "xhtml1": Outputs XHTML 1.x. Default.
+ * "xhtml": Outputs latest supported version of XHTML (currently XHTML 1.1).
+ * "html4": Outputs HTML 4
+ * "html": Outputs latest supported version of HTML (currently HTML 4).
+ Note that it is suggested that the more specific formats ("xhtml1"
+ and "html4") be used as "xhtml" or "html" may change in the future
+ if it makes sense at that time.
+
+ Returns: An HTML document as a string.
+
+ """
+ md = Markdown(extensions=load_extensions(extensions),
+ safe_mode=safe_mode,
+ output_format=output_format)
+ return md.convert(text)
+
+
+def markdownFromFile(input = None,
+ output = None,
+ extensions = [],
+ encoding = None,
+ safe_mode = False,
+ output_format = DEFAULT_OUTPUT_FORMAT):
+ """Read markdown code from a file and write it to a file or a stream."""
+ md = Markdown(extensions=load_extensions(extensions),
+ safe_mode=safe_mode,
+ output_format=output_format)
+ md.convertFile(input, output, encoding)
+
+
+
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/blockparser.py b/tools/addon-sdk-1.7/python-lib/markdown/blockparser.py
new file mode 100644
index 0000000..e18b338
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/blockparser.py
@@ -0,0 +1,95 @@
+
+import markdown
+
+class State(list):
+ """ Track the current and nested state of the parser.
+
+ This utility class is used to track the state of the BlockParser and
+ support multiple levels if nesting. It's just a simple API wrapped around
+ a list. Each time a state is set, that state is appended to the end of the
+ list. Each time a state is reset, that state is removed from the end of
+ the list.
+
+ Therefore, each time a state is set for a nested block, that state must be
+ reset when we back out of that level of nesting or the state could be
+ corrupted.
+
+ While all the methods of a list object are available, only the three
+ defined below need be used.
+
+ """
+
+ def set(self, state):
+ """ Set a new state. """
+ self.append(state)
+
+ def reset(self):
+ """ Step back one step in nested state. """
+ self.pop()
+
+ def isstate(self, state):
+ """ Test that top (current) level is of given state. """
+ if len(self):
+ return self[-1] == state
+ else:
+ return False
+
+class BlockParser:
+ """ Parse Markdown blocks into an ElementTree object.
+
+ A wrapper class that stitches the various BlockProcessors together,
+ looping through them and creating an ElementTree object.
+ """
+
+ def __init__(self):
+ self.blockprocessors = markdown.odict.OrderedDict()
+ self.state = State()
+
+ def parseDocument(self, lines):
+ """ Parse a markdown document into an ElementTree.
+
+ Given a list of lines, an ElementTree object (not just a parent Element)
+ is created and the root element is passed to the parser as the parent.
+ The ElementTree object is returned.
+
+ This should only be called on an entire document, not pieces.
+
+ """
+ # Create a ElementTree from the lines
+ self.root = markdown.etree.Element(markdown.DOC_TAG)
+ self.parseChunk(self.root, '\n'.join(lines))
+ return markdown.etree.ElementTree(self.root)
+
+ def parseChunk(self, parent, text):
+ """ Parse a chunk of markdown text and attach to given etree node.
+
+ While the ``text`` argument is generally assumed to contain multiple
+ blocks which will be split on blank lines, it could contain only one
+ block. Generally, this method would be called by extensions when
+ block parsing is required.
+
+ The ``parent`` etree Element passed in is altered in place.
+ Nothing is returned.
+
+ """
+ self.parseBlocks(parent, text.split('\n\n'))
+
+ def parseBlocks(self, parent, blocks):
+ """ Process blocks of markdown text and attach to given etree node.
+
+ Given a list of ``blocks``, each blockprocessor is stepped through
+ until there are no blocks left. While an extension could potentially
+ call this method directly, it's generally expected to be used internally.
+
+ This is a public method as an extension may need to add/alter additional
+ BlockProcessors which call this method to recursively parse a nested
+ block.
+
+ """
+ while blocks:
+ for processor in self.blockprocessors.values():
+ if processor.test(parent, blocks[0]):
+ processor.run(parent, blocks)
+ break
+
+
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/blockprocessors.py b/tools/addon-sdk-1.7/python-lib/markdown/blockprocessors.py
new file mode 100644
index 0000000..79f4db9
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/blockprocessors.py
@@ -0,0 +1,460 @@
+"""
+CORE MARKDOWN BLOCKPARSER
+=============================================================================
+
+This parser handles basic parsing of Markdown blocks. It doesn't concern itself
+with inline elements such as **bold** or *italics*, but rather just catches
+blocks, lists, quotes, etc.
+
+The BlockParser is made up of a bunch of BlockProssors, each handling a
+different type of block. Extensions may add/replace/remove BlockProcessors
+as they need to alter how markdown blocks are parsed.
+
+"""
+
+import re
+import markdown
+
+class BlockProcessor:
+ """ Base class for block processors.
+
+ Each subclass will provide the methods below to work with the source and
+ tree. Each processor will need to define it's own ``test`` and ``run``
+ methods. The ``test`` method should return True or False, to indicate
+ whether the current block should be processed by this processor. If the
+ test passes, the parser will call the processors ``run`` method.
+
+ """
+
+ def __init__(self, parser=None):
+ self.parser = parser
+
+ def lastChild(self, parent):
+ """ Return the last child of an etree element. """
+ if len(parent):
+ return parent[-1]
+ else:
+ return None
+
+ def detab(self, text):
+ """ Remove a tab from the front of each line of the given text. """
+ newtext = []
+ lines = text.split('\n')
+ for line in lines:
+ if line.startswith(' '*markdown.TAB_LENGTH):
+ newtext.append(line[markdown.TAB_LENGTH:])
+ elif not line.strip():
+ newtext.append('')
+ else:
+ break
+ return '\n'.join(newtext), '\n'.join(lines[len(newtext):])
+
+ def looseDetab(self, text, level=1):
+ """ Remove a tab from front of lines but allowing dedented lines. """
+ lines = text.split('\n')
+ for i in range(len(lines)):
+ if lines[i].startswith(' '*markdown.TAB_LENGTH*level):
+ lines[i] = lines[i][markdown.TAB_LENGTH*level:]
+ return '\n'.join(lines)
+
+ def test(self, parent, block):
+ """ Test for block type. Must be overridden by subclasses.
+
+ As the parser loops through processors, it will call the ``test`` method
+ on each to determine if the given block of text is of that type. This
+ method must return a boolean ``True`` or ``False``. The actual method of
+ testing is left to the needs of that particular block type. It could
+ be as simple as ``block.startswith(some_string)`` or a complex regular
+ expression. As the block type may be different depending on the parent
+ of the block (i.e. inside a list), the parent etree element is also
+ provided and may be used as part of the test.
+
+ Keywords:
+
+ * ``parent``: A etree element which will be the parent of the block.
+ * ``block``: A block of text from the source which has been split at
+ blank lines.
+ """
+ pass
+
+ def run(self, parent, blocks):
+ """ Run processor. Must be overridden by subclasses.
+
+ When the parser determines the appropriate type of a block, the parser
+ will call the corresponding processor's ``run`` method. This method
+ should parse the individual lines of the block and append them to
+ the etree.
+
+ Note that both the ``parent`` and ``etree`` keywords are pointers
+ to instances of the objects which should be edited in place. Each
+ processor must make changes to the existing objects as there is no
+ mechanism to return new/different objects to replace them.
+
+ This means that this method should be adding SubElements or adding text
+ to the parent, and should remove (``pop``) or add (``insert``) items to
+ the list of blocks.
+
+ Keywords:
+
+ * ``parent``: A etree element which is the parent of the current block.
+ * ``blocks``: A list of all remaining blocks of the document.
+ """
+ pass
+
+
+class ListIndentProcessor(BlockProcessor):
+ """ Process children of list items.
+
+ Example:
+ * a list item
+ process this part
+
+ or this part
+
+ """
+
+ INDENT_RE = re.compile(r'^(([ ]{%s})+)'% markdown.TAB_LENGTH)
+ ITEM_TYPES = ['li']
+ LIST_TYPES = ['ul', 'ol']
+
+ def test(self, parent, block):
+ return block.startswith(' '*markdown.TAB_LENGTH) and \
+ not self.parser.state.isstate('detabbed') and \
+ (parent.tag in self.ITEM_TYPES or \
+ (len(parent) and parent[-1] and \
+ (parent[-1].tag in self.LIST_TYPES)
+ )
+ )
+
+ def run(self, parent, blocks):
+ block = blocks.pop(0)
+ level, sibling = self.get_level(parent, block)
+ block = self.looseDetab(block, level)
+
+ self.parser.state.set('detabbed')
+ if parent.tag in self.ITEM_TYPES:
+ # The parent is already a li. Just parse the child block.
+ self.parser.parseBlocks(parent, [block])
+ elif sibling.tag in self.ITEM_TYPES:
+ # The sibling is a li. Use it as parent.
+ self.parser.parseBlocks(sibling, [block])
+ elif len(sibling) and sibling[-1].tag in self.ITEM_TYPES:
+ # The parent is a list (``ol`` or ``ul``) which has children.
+ # Assume the last child li is the parent of this block.
+ if sibling[-1].text:
+ # If the parent li has text, that text needs to be moved to a p
+ block = '%s\n\n%s' % (sibling[-1].text, block)
+ sibling[-1].text = ''
+ self.parser.parseChunk(sibling[-1], block)
+ else:
+ self.create_item(sibling, block)
+ self.parser.state.reset()
+
+ def create_item(self, parent, block):
+ """ Create a new li and parse the block with it as the parent. """
+ li = markdown.etree.SubElement(parent, 'li')
+ self.parser.parseBlocks(li, [block])
+
+ def get_level(self, parent, block):
+ """ Get level of indent based on list level. """
+ # Get indent level
+ m = self.INDENT_RE.match(block)
+ if m:
+ indent_level = len(m.group(1))/markdown.TAB_LENGTH
+ else:
+ indent_level = 0
+ if self.parser.state.isstate('list'):
+ # We're in a tightlist - so we already are at correct parent.
+ level = 1
+ else:
+ # We're in a looselist - so we need to find parent.
+ level = 0
+ # Step through children of tree to find matching indent level.
+ while indent_level > level:
+ child = self.lastChild(parent)
+ if child and (child.tag in self.LIST_TYPES or child.tag in self.ITEM_TYPES):
+ if child.tag in self.LIST_TYPES:
+ level += 1
+ parent = child
+ else:
+ # No more child levels. If we're short of indent_level,
+ # we have a code block. So we stop here.
+ break
+ return level, parent
+
+
+class CodeBlockProcessor(BlockProcessor):
+ """ Process code blocks. """
+
+ def test(self, parent, block):
+ return block.startswith(' '*markdown.TAB_LENGTH)
+
+ def run(self, parent, blocks):
+ sibling = self.lastChild(parent)
+ block = blocks.pop(0)
+ theRest = ''
+ if sibling and sibling.tag == "pre" and len(sibling) \
+ and sibling[0].tag == "code":
+ # The previous block was a code block. As blank lines do not start
+ # new code blocks, append this block to the previous, adding back
+ # linebreaks removed from the split into a list.
+ code = sibling[0]
+ block, theRest = self.detab(block)
+ code.text = markdown.AtomicString('%s\n%s\n' % (code.text, block.rstrip()))
+ else:
+ # This is a new codeblock. Create the elements and insert text.
+ pre = markdown.etree.SubElement(parent, 'pre')
+ code = markdown.etree.SubElement(pre, 'code')
+ block, theRest = self.detab(block)
+ code.text = markdown.AtomicString('%s\n' % block.rstrip())
+ if theRest:
+ # This block contained unindented line(s) after the first indented
+ # line. Insert these lines as the first block of the master blocks
+ # list for future processing.
+ blocks.insert(0, theRest)
+
+
+class BlockQuoteProcessor(BlockProcessor):
+
+ RE = re.compile(r'(^|\n)[ ]{0,3}>[ ]?(.*)')
+
+ def test(self, parent, block):
+ return bool(self.RE.search(block))
+
+ def run(self, parent, blocks):
+ block = blocks.pop(0)
+ m = self.RE.search(block)
+ if m:
+ before = block[:m.start()] # Lines before blockquote
+ # Pass lines before blockquote in recursively for parsing forst.
+ self.parser.parseBlocks(parent, [before])
+ # Remove ``> `` from begining of each line.
+ block = '\n'.join([self.clean(line) for line in
+ block[m.start():].split('\n')])
+ sibling = self.lastChild(parent)
+ if sibling and sibling.tag == "blockquote":
+ # Previous block was a blockquote so set that as this blocks parent
+ quote = sibling
+ else:
+ # This is a new blockquote. Create a new parent element.
+ quote = markdown.etree.SubElement(parent, 'blockquote')
+ # Recursively parse block with blockquote as parent.
+ self.parser.parseChunk(quote, block)
+
+ def clean(self, line):
+ """ Remove ``>`` from beginning of a line. """
+ m = self.RE.match(line)
+ if line.strip() == ">":
+ return ""
+ elif m:
+ return m.group(2)
+ else:
+ return line
+
+class OListProcessor(BlockProcessor):
+ """ Process ordered list blocks. """
+
+ TAG = 'ol'
+ # Detect an item (``1. item``). ``group(1)`` contains contents of item.
+ RE = re.compile(r'^[ ]{0,3}\d+\.[ ](.*)')
+ # Detect items on secondary lines. they can be of either list type.
+ CHILD_RE = re.compile(r'^[ ]{0,3}((\d+\.)|[*+-])[ ](.*)')
+ # Detect indented (nested) items of either type
+ INDENT_RE = re.compile(r'^[ ]{4,7}((\d+\.)|[*+-])[ ].*')
+
+ def test(self, parent, block):
+ return bool(self.RE.match(block))
+
+ def run(self, parent, blocks):
+ # Check fr multiple items in one block.
+ items = self.get_items(blocks.pop(0))
+ sibling = self.lastChild(parent)
+ if sibling and sibling.tag in ['ol', 'ul']:
+ # Previous block was a list item, so set that as parent
+ lst = sibling
+ # make sure previous item is in a p.
+ if len(lst) and lst[-1].text and not len(lst[-1]):
+ p = markdown.etree.SubElement(lst[-1], 'p')
+ p.text = lst[-1].text
+ lst[-1].text = ''
+ # parse first block differently as it gets wrapped in a p.
+ li = markdown.etree.SubElement(lst, 'li')
+ self.parser.state.set('looselist')
+ firstitem = items.pop(0)
+ self.parser.parseBlocks(li, [firstitem])
+ self.parser.state.reset()
+ else:
+ # This is a new list so create parent with appropriate tag.
+ lst = markdown.etree.SubElement(parent, self.TAG)
+ self.parser.state.set('list')
+ # Loop through items in block, recursively parsing each with the
+ # appropriate parent.
+ for item in items:
+ if item.startswith(' '*markdown.TAB_LENGTH):
+ # Item is indented. Parse with last item as parent
+ self.parser.parseBlocks(lst[-1], [item])
+ else:
+ # New item. Create li and parse with it as parent
+ li = markdown.etree.SubElement(lst, 'li')
+ self.parser.parseBlocks(li, [item])
+ self.parser.state.reset()
+
+ def get_items(self, block):
+ """ Break a block into list items. """
+ items = []
+ for line in block.split('\n'):
+ m = self.CHILD_RE.match(line)
+ if m:
+ # This is a new item. Append
+ items.append(m.group(3))
+ elif self.INDENT_RE.match(line):
+ # This is an indented (possibly nested) item.
+ if items[-1].startswith(' '*markdown.TAB_LENGTH):
+ # Previous item was indented. Append to that item.
+ items[-1] = '%s\n%s' % (items[-1], line)
+ else:
+ items.append(line)
+ else:
+ # This is another line of previous item. Append to that item.
+ items[-1] = '%s\n%s' % (items[-1], line)
+ return items
+
+
+class UListProcessor(OListProcessor):
+ """ Process unordered list blocks. """
+
+ TAG = 'ul'
+ RE = re.compile(r'^[ ]{0,3}[*+-][ ](.*)')
+
+
+class HashHeaderProcessor(BlockProcessor):
+ """ Process Hash Headers. """
+
+ # Detect a header at start of any line in block
+ RE = re.compile(r'(^|\n)(?P<level>#{1,6})(?P<header>.*?)#*(\n|$)')
+
+ def test(self, parent, block):
+ return bool(self.RE.search(block))
+
+ def run(self, parent, blocks):
+ block = blocks.pop(0)
+ m = self.RE.search(block)
+ if m:
+ before = block[:m.start()] # All lines before header
+ after = block[m.end():] # All lines after header
+ if before:
+ # As the header was not the first line of the block and the
+ # lines before the header must be parsed first,
+ # recursively parse this lines as a block.
+ self.parser.parseBlocks(parent, [before])
+ # Create header using named groups from RE
+ h = markdown.etree.SubElement(parent, 'h%d' % len(m.group('level')))
+ h.text = m.group('header').strip()
+ if after:
+ # Insert remaining lines as first block for future parsing.
+ blocks.insert(0, after)
+ else:
+ # This should never happen, but just in case...
+ message(CRITICAL, "We've got a problem header!")
+
+
+class SetextHeaderProcessor(BlockProcessor):
+ """ Process Setext-style Headers. """
+
+ # Detect Setext-style header. Must be first 2 lines of block.
+ RE = re.compile(r'^.*?\n[=-]{3,}', re.MULTILINE)
+
+ def test(self, parent, block):
+ return bool(self.RE.match(block))
+
+ def run(self, parent, blocks):
+ lines = blocks.pop(0).split('\n')
+ # Determine level. ``=`` is 1 and ``-`` is 2.
+ if lines[1].startswith('='):
+ level = 1
+ else:
+ level = 2
+ h = markdown.etree.SubElement(parent, 'h%d' % level)
+ h.text = lines[0].strip()
+ if len(lines) > 2:
+ # Block contains additional lines. Add to master blocks for later.
+ blocks.insert(0, '\n'.join(lines[2:]))
+
+
+class HRProcessor(BlockProcessor):
+ """ Process Horizontal Rules. """
+
+ RE = r'[ ]{0,3}(?P<ch>[*_-])[ ]?((?P=ch)[ ]?){2,}[ ]*'
+ # Detect hr on any line of a block.
+ SEARCH_RE = re.compile(r'(^|\n)%s(\n|$)' % RE)
+ # Match a hr on a single line of text.
+ MATCH_RE = re.compile(r'^%s$' % RE)
+
+ def test(self, parent, block):
+ return bool(self.SEARCH_RE.search(block))
+
+ def run(self, parent, blocks):
+ lines = blocks.pop(0).split('\n')
+ prelines = []
+ # Check for lines in block before hr.
+ for line in lines:
+ m = self.MATCH_RE.match(line)
+ if m:
+ break
+ else:
+ prelines.append(line)
+ if len(prelines):
+ # Recursively parse lines before hr so they get parsed first.
+ self.parser.parseBlocks(parent, ['\n'.join(prelines)])
+ # create hr
+ hr = markdown.etree.SubElement(parent, 'hr')
+ # check for lines in block after hr.
+ lines = lines[len(prelines)+1:]
+ if len(lines):
+ # Add lines after hr to master blocks for later parsing.
+ blocks.insert(0, '\n'.join(lines))
+
+
+class EmptyBlockProcessor(BlockProcessor):
+ """ Process blocks and start with an empty line. """
+
+ # Detect a block that only contains whitespace
+ # or only whitespace on the first line.
+ RE = re.compile(r'^\s*\n')
+
+ def test(self, parent, block):
+ return bool(self.RE.match(block))
+
+ def run(self, parent, blocks):
+ block = blocks.pop(0)
+ m = self.RE.match(block)
+ if m:
+ # Add remaining line to master blocks for later.
+ blocks.insert(0, block[m.end():])
+ sibling = self.lastChild(parent)
+ if sibling and sibling.tag == 'pre' and sibling[0] and \
+ sibling[0].tag == 'code':
+ # Last block is a codeblock. Append to preserve whitespace.
+ sibling[0].text = markdown.AtomicString('%s/n/n/n' % sibling[0].text )
+
+
+class ParagraphProcessor(BlockProcessor):
+ """ Process Paragraph blocks. """
+
+ def test(self, parent, block):
+ return True
+
+ def run(self, parent, blocks):
+ block = blocks.pop(0)
+ if block.strip():
+ # Not a blank block. Add to parent, otherwise throw it away.
+ if self.parser.state.isstate('list'):
+ # The parent is a tight-list. Append to parent.text
+ if parent.text:
+ parent.text = '%s\n%s' % (parent.text, block)
+ else:
+ parent.text = block.lstrip()
+ else:
+ # Create a regular paragraph
+ p = markdown.etree.SubElement(parent, 'p')
+ p.text = block.lstrip()
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/commandline.py b/tools/addon-sdk-1.7/python-lib/markdown/commandline.py
new file mode 100644
index 0000000..1eedc6d
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/commandline.py
@@ -0,0 +1,96 @@
+"""
+COMMAND-LINE SPECIFIC STUFF
+=============================================================================
+
+The rest of the code is specifically for handling the case where Python
+Markdown is called from the command line.
+"""
+
+import markdown
+import sys
+import logging
+from logging import DEBUG, INFO, WARN, ERROR, CRITICAL
+
+EXECUTABLE_NAME_FOR_USAGE = "python markdown.py"
+""" The name used in the usage statement displayed for python versions < 2.3.
+(With python 2.3 and higher the usage statement is generated by optparse
+and uses the actual name of the executable called.) """
+
+OPTPARSE_WARNING = """
+Python 2.3 or higher required for advanced command line options.
+For lower versions of Python use:
+
+ %s INPUT_FILE > OUTPUT_FILE
+
+""" % EXECUTABLE_NAME_FOR_USAGE
+
+def parse_options():
+ """
+ Define and parse `optparse` options for command-line usage.
+ """
+
+ try:
+ optparse = __import__("optparse")
+ except:
+ if len(sys.argv) == 2:
+ return {'input': sys.argv[1],
+ 'output': None,
+ 'safe': False,
+ 'extensions': [],
+ 'encoding': None }, CRITICAL
+ else:
+ print OPTPARSE_WARNING
+ return None, None
+
+ parser = optparse.OptionParser(usage="%prog INPUTFILE [options]")
+ parser.add_option("-f", "--file", dest="filename", default=sys.stdout,
+ help="write output to OUTPUT_FILE",
+ metavar="OUTPUT_FILE")
+ parser.add_option("-e", "--encoding", dest="encoding",
+ help="encoding for input and output files",)
+ parser.add_option("-q", "--quiet", default = CRITICAL,
+ action="store_const", const=CRITICAL+10, dest="verbose",
+ help="suppress all messages")
+ parser.add_option("-v", "--verbose",
+ action="store_const", const=INFO, dest="verbose",
+ help="print info messages")
+ parser.add_option("-s", "--safe", dest="safe", default=False,
+ metavar="SAFE_MODE",
+ help="safe mode ('replace', 'remove' or 'escape' user's HTML tag)")
+ parser.add_option("-o", "--output_format", dest="output_format",
+ default='xhtml1', metavar="OUTPUT_FORMAT",
+ help="Format of output. One of 'xhtml1' (default) or 'html4'.")
+ parser.add_option("--noisy",
+ action="store_const", const=DEBUG, dest="verbose",
+ help="print debug messages")
+ parser.add_option("-x", "--extension", action="append", dest="extensions",
+ help = "load extension EXTENSION", metavar="EXTENSION")
+
+ (options, args) = parser.parse_args()
+
+ if not len(args) == 1:
+ parser.print_help()
+ return None, None
+ else:
+ input_file = args[0]
+
+ if not options.extensions:
+ options.extensions = []
+
+ return {'input': input_file,
+ 'output': options.filename,
+ 'safe_mode': options.safe,
+ 'extensions': options.extensions,
+ 'encoding': options.encoding,
+ 'output_format': options.output_format}, options.verbose
+
+def run():
+ """Run Markdown from the command line."""
+
+ # Parse options and adjust logging level if necessary
+ options, logging_level = parse_options()
+ if not options: sys.exit(0)
+ if logging_level: logging.getLogger('MARKDOWN').setLevel(logging_level)
+
+ # Run
+ markdown.markdownFromFile(**options)
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/etree_loader.py b/tools/addon-sdk-1.7/python-lib/markdown/etree_loader.py
new file mode 100644
index 0000000..e2599b2
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/etree_loader.py
@@ -0,0 +1,33 @@
+
+from markdown import message, CRITICAL
+import sys
+
+## Import
+def importETree():
+ """Import the best implementation of ElementTree, return a module object."""
+ etree_in_c = None
+ try: # Is it Python 2.5+ with C implemenation of ElementTree installed?
+ import xml.etree.cElementTree as etree_in_c
+ except ImportError:
+ try: # Is it Python 2.5+ with Python implementation of ElementTree?
+ import xml.etree.ElementTree as etree
+ except ImportError:
+ try: # An earlier version of Python with cElementTree installed?
+ import cElementTree as etree_in_c
+ except ImportError:
+ try: # An earlier version of Python with Python ElementTree?
+ import elementtree.ElementTree as etree
+ except ImportError:
+ message(CRITICAL, "Failed to import ElementTree")
+ sys.exit(1)
+ if etree_in_c and etree_in_c.VERSION < "1.0":
+ message(CRITICAL, "For cElementTree version 1.0 or higher is required.")
+ sys.exit(1)
+ elif etree_in_c :
+ return etree_in_c
+ elif etree.VERSION < "1.1":
+ message(CRITICAL, "For ElementTree version 1.1 or higher is required")
+ sys.exit(1)
+ else :
+ return etree
+
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/extensions/__init__.py b/tools/addon-sdk-1.7/python-lib/markdown/extensions/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/extensions/__init__.py
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/extensions/abbr.py b/tools/addon-sdk-1.7/python-lib/markdown/extensions/abbr.py
new file mode 100644
index 0000000..783220e
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/extensions/abbr.py
@@ -0,0 +1,95 @@
+'''
+Abbreviation Extension for Python-Markdown
+==========================================
+
+This extension adds abbreviation handling to Python-Markdown.
+
+Simple Usage:
+
+ >>> import markdown
+ >>> text = """
+ ... Some text with an ABBR and a REF. Ignore REFERENCE and ref.
+ ...
+ ... *[ABBR]: Abbreviation
+ ... *[REF]: Abbreviation Reference
+ ... """
+ >>> markdown.markdown(text, ['abbr'])
+ u'<p>Some text with an <abbr title="Abbreviation">ABBR</abbr> and a <abbr title="Abbreviation Reference">REF</abbr>. Ignore REFERENCE and ref.</p>'
+
+Copyright 2007-2008
+* [Waylan Limberg](http://achinghead.com/)
+* [Seemant Kulleen](http://www.kulleen.org/)
+
+
+'''
+
+import markdown, re
+from markdown import etree
+
+# Global Vars
+ABBR_REF_RE = re.compile(r'[*]\[(?P<abbr>[^\]]*)\][ ]?:\s*(?P<title>.*)')
+
+class AbbrExtension(markdown.Extension):
+ """ Abbreviation Extension for Python-Markdown. """
+
+ def extendMarkdown(self, md, md_globals):
+ """ Insert AbbrPreprocessor before ReferencePreprocessor. """
+ md.preprocessors.add('abbr', AbbrPreprocessor(md), '<reference')
+
+
+class AbbrPreprocessor(markdown.preprocessors.Preprocessor):
+ """ Abbreviation Preprocessor - parse text for abbr references. """
+
+ def run(self, lines):
+ '''
+ Find and remove all Abbreviation references from the text.
+ Each reference is set as a new AbbrPattern in the markdown instance.
+
+ '''
+ new_text = []
+ for line in lines:
+ m = ABBR_REF_RE.match(line)
+ if m:
+ abbr = m.group('abbr').strip()
+ title = m.group('title').strip()
+ self.markdown.inlinePatterns['abbr-%s'%abbr] = \
+ AbbrPattern(self._generate_pattern(abbr), title)
+ else:
+ new_text.append(line)
+ return new_text
+
+ def _generate_pattern(self, text):
+ '''
+ Given a string, returns an regex pattern to match that string.
+
+ 'HTML' -> r'(?P<abbr>[H][T][M][L])'
+
+ Note: we force each char as a literal match (in brackets) as we don't
+ know what they will be beforehand.
+
+ '''
+ chars = list(text)
+ for i in range(len(chars)):
+ chars[i] = r'[%s]' % chars[i]
+ return r'(?P<abbr>\b%s\b)' % (r''.join(chars))
+
+
+class AbbrPattern(markdown.inlinepatterns.Pattern):
+ """ Abbreviation inline pattern. """
+
+ def __init__(self, pattern, title):
+ markdown.inlinepatterns.Pattern.__init__(self, pattern)
+ self.title = title
+
+ def handleMatch(self, m):
+ abbr = etree.Element('abbr')
+ abbr.text = m.group('abbr')
+ abbr.set('title', self.title)
+ return abbr
+
+def makeExtension(configs=None):
+ return AbbrExtension(configs=configs)
+
+if __name__ == "__main__":
+ import doctest
+ doctest.testmod()
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/extensions/codehilite.py b/tools/addon-sdk-1.7/python-lib/markdown/extensions/codehilite.py
new file mode 100644
index 0000000..c5d496b
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/extensions/codehilite.py
@@ -0,0 +1,224 @@
+#!/usr/bin/python
+
+"""
+CodeHilite Extension for Python-Markdown
+========================================
+
+Adds code/syntax highlighting to standard Python-Markdown code blocks.
+
+Copyright 2006-2008 [Waylan Limberg](http://achinghead.com/).
+
+Project website: <http://www.freewisdom.org/project/python-markdown/CodeHilite>
+Contact: markdown@freewisdom.org
+
+License: BSD (see ../docs/LICENSE for details)
+
+Dependencies:
+* [Python 2.3+](http://python.org/)
+* [Markdown 2.0+](http://www.freewisdom.org/projects/python-markdown/)
+* [Pygments](http://pygments.org/)
+
+"""
+
+import markdown
+
+# --------------- CONSTANTS YOU MIGHT WANT TO MODIFY -----------------
+
+try:
+ TAB_LENGTH = markdown.TAB_LENGTH
+except AttributeError:
+ TAB_LENGTH = 4
+
+
+# ------------------ The Main CodeHilite Class ----------------------
+class CodeHilite:
+ """
+ Determine language of source code, and pass it into the pygments hilighter.
+
+ Basic Usage:
+ >>> code = CodeHilite(src = 'some text')
+ >>> html = code.hilite()
+
+ * src: Source string or any object with a .readline attribute.
+
+ * linenos: (Boolen) Turn line numbering 'on' or 'off' (off by default).
+
+ * css_class: Set class name of wrapper div ('codehilite' by default).
+
+ Low Level Usage:
+ >>> code = CodeHilite()
+ >>> code.src = 'some text' # String or anything with a .readline attr.
+ >>> code.linenos = True # True or False; Turns line numbering on or of.
+ >>> html = code.hilite()
+
+ """
+
+ def __init__(self, src=None, linenos=False, css_class="codehilite"):
+ self.src = src
+ self.lang = None
+ self.linenos = linenos
+ self.css_class = css_class
+
+ def hilite(self):
+ """
+ Pass code to the [Pygments](http://pygments.pocoo.org/) highliter with
+ optional line numbers. The output should then be styled with css to
+ your liking. No styles are applied by default - only styling hooks
+ (i.e.: <span class="k">).
+
+ returns : A string of html.
+
+ """
+
+ self.src = self.src.strip('\n')
+
+ self._getLang()
+
+ try:
+ from pygments import highlight
+ from pygments.lexers import get_lexer_by_name, guess_lexer, \
+ TextLexer
+ from pygments.formatters import HtmlFormatter
+ except ImportError:
+ # just escape and pass through
+ txt = self._escape(self.src)
+ if self.linenos:
+ txt = self._number(txt)
+ else :
+ txt = '<div class="%s"><pre>%s</pre></div>\n'% \
+ (self.css_class, txt)
+ return txt
+ else:
+ try:
+ lexer = get_lexer_by_name(self.lang)
+ except ValueError:
+ try:
+ lexer = guess_lexer(self.src)
+ except ValueError:
+ lexer = TextLexer()
+ formatter = HtmlFormatter(linenos=self.linenos,
+ cssclass=self.css_class)
+ return highlight(self.src, lexer, formatter)
+
+ def _escape(self, txt):
+ """ basic html escaping """
+ txt = txt.replace('&', '&amp;')
+ txt = txt.replace('<', '&lt;')
+ txt = txt.replace('>', '&gt;')
+ txt = txt.replace('"', '&quot;')
+ return txt
+
+ def _number(self, txt):
+ """ Use <ol> for line numbering """
+ # Fix Whitespace
+ txt = txt.replace('\t', ' '*TAB_LENGTH)
+ txt = txt.replace(" "*4, "&nbsp; &nbsp; ")
+ txt = txt.replace(" "*3, "&nbsp; &nbsp;")
+ txt = txt.replace(" "*2, "&nbsp; ")
+
+ # Add line numbers
+ lines = txt.splitlines()
+ txt = '<div class="codehilite"><pre><ol>\n'
+ for line in lines:
+ txt += '\t<li>%s</li>\n'% line
+ txt += '</ol></pre></div>\n'
+ return txt
+
+
+ def _getLang(self):
+ """
+ Determines language of a code block from shebang lines and whether said
+ line should be removed or left in place. If the sheband line contains a
+ path (even a single /) then it is assumed to be a real shebang lines and
+ left alone. However, if no path is given (e.i.: #!python or :::python)
+ then it is assumed to be a mock shebang for language identifitation of a
+ code fragment and removed from the code block prior to processing for
+ code highlighting. When a mock shebang (e.i: #!python) is found, line
+ numbering is turned on. When colons are found in place of a shebang
+ (e.i.: :::python), line numbering is left in the current state - off
+ by default.
+
+ """
+
+ import re
+
+ #split text into lines
+ lines = self.src.split("\n")
+ #pull first line to examine
+ fl = lines.pop(0)
+
+ c = re.compile(r'''
+ (?:(?:::+)|(?P<shebang>[#]!)) # Shebang or 2 or more colons.
+ (?P<path>(?:/\w+)*[/ ])? # Zero or 1 path
+ (?P<lang>[\w+-]*) # The language
+ ''', re.VERBOSE)
+ # search first line for shebang
+ m = c.search(fl)
+ if m:
+ # we have a match
+ try:
+ self.lang = m.group('lang').lower()
+ except IndexError:
+ self.lang = None
+ if m.group('path'):
+ # path exists - restore first line
+ lines.insert(0, fl)
+ if m.group('shebang'):
+ # shebang exists - use line numbers
+ self.linenos = True
+ else:
+ # No match
+ lines.insert(0, fl)
+
+ self.src = "\n".join(lines).strip("\n")
+
+
+
+# ------------------ The Markdown Extension -------------------------------
+class HiliteTreeprocessor(markdown.treeprocessors.Treeprocessor):
+ """ Hilight source code in code blocks. """
+
+ def run(self, root):
+ """ Find code blocks and store in htmlStash. """
+ blocks = root.getiterator('pre')
+ for block in blocks:
+ children = block.getchildren()
+ if len(children) == 1 and children[0].tag == 'code':
+ code = CodeHilite(children[0].text,
+ linenos=self.config['force_linenos'][0],
+ css_class=self.config['css_class'][0])
+ placeholder = self.markdown.htmlStash.store(code.hilite(),
+ safe=True)
+ # Clear codeblock in etree instance
+ block.clear()
+ # Change to p element which will later
+ # be removed when inserting raw html
+ block.tag = 'p'
+ block.text = placeholder
+
+
+class CodeHiliteExtension(markdown.Extension):
+ """ Add source code hilighting to markdown codeblocks. """
+
+ def __init__(self, configs):
+ # define default configs
+ self.config = {
+ 'force_linenos' : [False, "Force line numbers - Default: False"],
+ 'css_class' : ["codehilite",
+ "Set class name for wrapper <div> - Default: codehilite"],
+ }
+
+ # Override defaults with user settings
+ for key, value in configs:
+ self.setConfig(key, value)
+
+ def extendMarkdown(self, md, md_globals):
+ """ Add HilitePostprocessor to Markdown instance. """
+ hiliter = HiliteTreeprocessor(md)
+ hiliter.config = self.config
+ md.treeprocessors.add("hilite", hiliter, "_begin")
+
+
+def makeExtension(configs={}):
+ return CodeHiliteExtension(configs=configs)
+
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/extensions/def_list.py b/tools/addon-sdk-1.7/python-lib/markdown/extensions/def_list.py
new file mode 100644
index 0000000..73a1c85
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/extensions/def_list.py
@@ -0,0 +1,104 @@
+#!/usr/bin/env Python
+"""
+Definition List Extension for Python-Markdown
+=============================================
+
+Added parsing of Definition Lists to Python-Markdown.
+
+A simple example:
+
+ Apple
+ : Pomaceous fruit of plants of the genus Malus in
+ the family Rosaceae.
+ : An american computer company.
+
+ Orange
+ : The fruit of an evergreen tree of the genus Citrus.
+
+Copyright 2008 - [Waylan Limberg](http://achinghead.com)
+
+"""
+
+import markdown, re
+from markdown import etree
+
+
+class DefListProcessor(markdown.blockprocessors.BlockProcessor):
+ """ Process Definition Lists. """
+
+ RE = re.compile(r'(^|\n)[ ]{0,3}:[ ]{1,3}(.*?)(\n|$)')
+
+ def test(self, parent, block):
+ return bool(self.RE.search(block))
+
+ def run(self, parent, blocks):
+ block = blocks.pop(0)
+ m = self.RE.search(block)
+ terms = [l.strip() for l in block[:m.start()].split('\n') if l.strip()]
+ d, theRest = self.detab(block[m.end():])
+ if d:
+ d = '%s\n%s' % (m.group(2), d)
+ else:
+ d = m.group(2)
+ #import ipdb; ipdb.set_trace()
+ sibling = self.lastChild(parent)
+ if not terms and sibling.tag == 'p':
+ # The previous paragraph contains the terms
+ state = 'looselist'
+ terms = sibling.text.split('\n')
+ parent.remove(sibling)
+ # Aquire new sibling
+ sibling = self.lastChild(parent)
+ else:
+ state = 'list'
+
+ if sibling and sibling.tag == 'dl':
+ # This is another item on an existing list
+ dl = sibling
+ if len(dl) and dl[-1].tag == 'dd' and len(dl[-1]):
+ state = 'looselist'
+ else:
+ # This is a new list
+ dl = etree.SubElement(parent, 'dl')
+ # Add terms
+ for term in terms:
+ dt = etree.SubElement(dl, 'dt')
+ dt.text = term
+ # Add definition
+ self.parser.state.set(state)
+ dd = etree.SubElement(dl, 'dd')
+ self.parser.parseBlocks(dd, [d])
+ self.parser.state.reset()
+
+ if theRest:
+ blocks.insert(0, theRest)
+
+class DefListIndentProcessor(markdown.blockprocessors.ListIndentProcessor):
+ """ Process indented children of definition list items. """
+
+ ITEM_TYPES = ['dd']
+ LIST_TYPES = ['dl']
+
+ def create_item(parent, block):
+ """ Create a new dd and parse the block with it as the parent. """
+ dd = markdown.etree.SubElement(parent, 'dd')
+ self.parser.parseBlocks(dd, [block])
+
+
+
+class DefListExtension(markdown.Extension):
+ """ Add definition lists to Markdown. """
+
+ def extendMarkdown(self, md, md_globals):
+ """ Add an instance of DefListProcessor to BlockParser. """
+ md.parser.blockprocessors.add('defindent',
+ DefListIndentProcessor(md.parser),
+ '>indent')
+ md.parser.blockprocessors.add('deflist',
+ DefListProcessor(md.parser),
+ '>ulist')
+
+
+def makeExtension(configs={}):
+ return DefListExtension(configs=configs)
+
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/extensions/extra.py b/tools/addon-sdk-1.7/python-lib/markdown/extensions/extra.py
new file mode 100644
index 0000000..4a2ffbf
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/extensions/extra.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+"""
+Python-Markdown Extra Extension
+===============================
+
+A compilation of various Python-Markdown extensions that imitates
+[PHP Markdown Extra](http://michelf.com/projects/php-markdown/extra/).
+
+Note that each of the individual extensions still need to be available
+on your PYTHONPATH. This extension simply wraps them all up as a
+convenience so that only one extension needs to be listed when
+initiating Markdown. See the documentation for each individual
+extension for specifics about that extension.
+
+In the event that one or more of the supported extensions are not
+available for import, Markdown will issue a warning and simply continue
+without that extension.
+
+There may be additional extensions that are distributed with
+Python-Markdown that are not included here in Extra. Those extensions
+are not part of PHP Markdown Extra, and therefore, not part of
+Python-Markdown Extra. If you really would like Extra to include
+additional extensions, we suggest creating your own clone of Extra
+under a differant name. You could also edit the `extensions` global
+variable defined below, but be aware that such changes may be lost
+when you upgrade to any future version of Python-Markdown.
+
+"""
+
+import markdown
+
+extensions = ['fenced_code',
+ 'footnotes',
+ 'headerid',
+ 'def_list',
+ 'tables',
+ 'abbr',
+ ]
+
+
+class ExtraExtension(markdown.Extension):
+ """ Add various extensions to Markdown class."""
+
+ def extendMarkdown(self, md, md_globals):
+ """ Register extension instances. """
+ md.registerExtensions(extensions, self.config)
+
+def makeExtension(configs={}):
+ return ExtraExtension(configs=dict(configs))
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/extensions/fenced_code.py b/tools/addon-sdk-1.7/python-lib/markdown/extensions/fenced_code.py
new file mode 100644
index 0000000..307b1dc
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/extensions/fenced_code.py
@@ -0,0 +1,117 @@
+#!/usr/bin/env python
+
+"""
+Fenced Code Extension for Python Markdown
+=========================================
+
+This extension adds Fenced Code Blocks to Python-Markdown.
+
+ >>> import markdown
+ >>> text = '''
+ ... A paragraph before a fenced code block:
+ ...
+ ... ~~~
+ ... Fenced code block
+ ... ~~~
+ ... '''
+ >>> html = markdown.markdown(text, extensions=['fenced_code'])
+ >>> html
+ u'<p>A paragraph before a fenced code block:</p>\\n<pre><code>Fenced code block\\n</code></pre>'
+
+Works with safe_mode also (we check this because we are using the HtmlStash):
+
+ >>> markdown.markdown(text, extensions=['fenced_code'], safe_mode='replace')
+ u'<p>A paragraph before a fenced code block:</p>\\n<pre><code>Fenced code block\\n</code></pre>'
+
+Include tilde's in a code block and wrap with blank lines:
+
+ >>> text = '''
+ ... ~~~~~~~~
+ ...
+ ... ~~~~
+ ...
+ ... ~~~~~~~~'''
+ >>> markdown.markdown(text, extensions=['fenced_code'])
+ u'<pre><code>\\n~~~~\\n\\n</code></pre>'
+
+Multiple blocks and language tags:
+
+ >>> text = '''
+ ... ~~~~{.python}
+ ... block one
+ ... ~~~~
+ ...
+ ... ~~~~.html
+ ... <p>block two</p>
+ ... ~~~~'''
+ >>> markdown.markdown(text, extensions=['fenced_code'])
+ u'<pre><code class="python">block one\\n</code></pre>\\n\\n<pre><code class="html">&lt;p&gt;block two&lt;/p&gt;\\n</code></pre>'
+
+Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/).
+
+Project website: <http://www.freewisdom.org/project/python-markdown/Fenced__Code__Blocks>
+Contact: markdown@freewisdom.org
+
+License: BSD (see ../docs/LICENSE for details)
+
+Dependencies:
+* [Python 2.3+](http://python.org)
+* [Markdown 2.0+](http://www.freewisdom.org/projects/python-markdown/)
+
+"""
+
+import markdown, re
+
+# Global vars
+FENCED_BLOCK_RE = re.compile( \
+ r'(?P<fence>^~{3,})[ ]*(\{?\.(?P<lang>[a-zA-Z0-9_-]*)\}?)?[ ]*\n(?P<code>.*?)(?P=fence)[ ]*$',
+ re.MULTILINE|re.DOTALL
+ )
+CODE_WRAP = '<pre><code%s>%s</code></pre>'
+LANG_TAG = ' class="%s"'
+
+
+class FencedCodeExtension(markdown.Extension):
+
+ def extendMarkdown(self, md, md_globals):
+ """ Add FencedBlockPreprocessor to the Markdown instance. """
+
+ md.preprocessors.add('fenced_code_block',
+ FencedBlockPreprocessor(md),
+ "_begin")
+
+
+class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor):
+
+ def run(self, lines):
+ """ Match and store Fenced Code Blocks in the HtmlStash. """
+ text = "\n".join(lines)
+ while 1:
+ m = FENCED_BLOCK_RE.search(text)
+ if m:
+ lang = ''
+ if m.group('lang'):
+ lang = LANG_TAG % m.group('lang')
+ code = CODE_WRAP % (lang, self._escape(m.group('code')))
+ placeholder = self.markdown.htmlStash.store(code, safe=True)
+ text = '%s\n%s\n%s'% (text[:m.start()], placeholder, text[m.end():])
+ else:
+ break
+ return text.split("\n")
+
+ def _escape(self, txt):
+ """ basic html escaping """
+ txt = txt.replace('&', '&amp;')
+ txt = txt.replace('<', '&lt;')
+ txt = txt.replace('>', '&gt;')
+ txt = txt.replace('"', '&quot;')
+ return txt
+
+
+def makeExtension(configs=None):
+ return FencedCodeExtension()
+
+
+if __name__ == "__main__":
+ import doctest
+ doctest.testmod()
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/extensions/footnotes.py b/tools/addon-sdk-1.7/python-lib/markdown/extensions/footnotes.py
new file mode 100644
index 0000000..6dacab7
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/extensions/footnotes.py
@@ -0,0 +1,293 @@
+"""
+========================= FOOTNOTES =================================
+
+This section adds footnote handling to markdown. It can be used as
+an example for extending python-markdown with relatively complex
+functionality. While in this case the extension is included inside
+the module itself, it could just as easily be added from outside the
+module. Not that all markdown classes above are ignorant about
+footnotes. All footnote functionality is provided separately and
+then added to the markdown instance at the run time.
+
+Footnote functionality is attached by calling extendMarkdown()
+method of FootnoteExtension. The method also registers the
+extension to allow it's state to be reset by a call to reset()
+method.
+
+Example:
+ Footnotes[^1] have a label[^label] and a definition[^!DEF].
+
+ [^1]: This is a footnote
+ [^label]: A footnote on "label"
+ [^!DEF]: The footnote for definition
+
+"""
+
+import re, markdown
+from markdown import etree
+
+FN_BACKLINK_TEXT = "zz1337820767766393qq"
+NBSP_PLACEHOLDER = "qq3936677670287331zz"
+DEF_RE = re.compile(r'(\ ?\ ?\ ?)\[\^([^\]]*)\]:\s*(.*)')
+TABBED_RE = re.compile(r'((\t)|( ))(.*)')
+
+class FootnoteExtension(markdown.Extension):
+ """ Footnote Extension. """
+
+ def __init__ (self, configs):
+ """ Setup configs. """
+ self.config = {'PLACE_MARKER':
+ ["///Footnotes Go Here///",
+ "The text string that marks where the footnotes go"]}
+
+ for key, value in configs:
+ self.config[key][0] = value
+
+ self.reset()
+
+ def extendMarkdown(self, md, md_globals):
+ """ Add pieces to Markdown. """
+ md.registerExtension(self)
+ self.parser = md.parser
+ # Insert a preprocessor before ReferencePreprocessor
+ md.preprocessors.add("footnote", FootnotePreprocessor(self),
+ "<reference")
+ # Insert an inline pattern before ImageReferencePattern
+ FOOTNOTE_RE = r'\[\^([^\]]*)\]' # blah blah [^1] blah
+ md.inlinePatterns.add("footnote", FootnotePattern(FOOTNOTE_RE, self),
+ "<reference")
+ # Insert a tree-processor that would actually add the footnote div
+ # This must be before the inline treeprocessor so inline patterns
+ # run on the contents of the div.
+ md.treeprocessors.add("footnote", FootnoteTreeprocessor(self),
+ "<inline")
+ # Insert a postprocessor after amp_substitute oricessor
+ md.postprocessors.add("footnote", FootnotePostprocessor(self),
+ ">amp_substitute")
+
+ def reset(self):
+ """ Clear the footnotes on reset. """
+ self.footnotes = markdown.odict.OrderedDict()
+
+ def findFootnotesPlaceholder(self, root):
+ """ Return ElementTree Element that contains Footnote placeholder. """
+ def finder(element):
+ for child in element:
+ if child.text:
+ if child.text.find(self.getConfig("PLACE_MARKER")) > -1:
+ return child, True
+ if child.tail:
+ if child.tail.find(self.getConfig("PLACE_MARKER")) > -1:
+ return (child, element), False
+ finder(child)
+ return None
+
+ res = finder(root)
+ return res
+
+ def setFootnote(self, id, text):
+ """ Store a footnote for later retrieval. """
+ self.footnotes[id] = text
+
+ def makeFootnoteId(self, id):
+ """ Return footnote link id. """
+ return 'fn:%s' % id
+
+ def makeFootnoteRefId(self, id):
+ """ Return footnote back-link id. """
+ return 'fnref:%s' % id
+
+ def makeFootnotesDiv(self, root):
+ """ Return div of footnotes as et Element. """
+
+ if not self.footnotes.keys():
+ return None
+
+ div = etree.Element("div")
+ div.set('class', 'footnote')
+ hr = etree.SubElement(div, "hr")
+ ol = etree.SubElement(div, "ol")
+
+ for id in self.footnotes.keys():
+ li = etree.SubElement(ol, "li")
+ li.set("id", self.makeFootnoteId(id))
+ self.parser.parseChunk(li, self.footnotes[id])
+ backlink = etree.Element("a")
+ backlink.set("href", "#" + self.makeFootnoteRefId(id))
+ backlink.set("rev", "footnote")
+ backlink.set("title", "Jump back to footnote %d in the text" % \
+ (self.footnotes.index(id)+1))
+ backlink.text = FN_BACKLINK_TEXT
+
+ if li.getchildren():
+ node = li[-1]
+ if node.tag == "p":
+ node.text = node.text + NBSP_PLACEHOLDER
+ node.append(backlink)
+ else:
+ p = etree.SubElement(li, "p")
+ p.append(backlink)
+ return div
+
+
+class FootnotePreprocessor(markdown.preprocessors.Preprocessor):
+ """ Find all footnote references and store for later use. """
+
+ def __init__ (self, footnotes):
+ self.footnotes = footnotes
+
+ def run(self, lines):
+ lines = self._handleFootnoteDefinitions(lines)
+ text = "\n".join(lines)
+ return text.split("\n")
+
+ def _handleFootnoteDefinitions(self, lines):
+ """
+ Recursively find all footnote definitions in lines.
+
+ Keywords:
+
+ * lines: A list of lines of text
+
+ Return: A list of lines with footnote definitions removed.
+
+ """
+ i, id, footnote = self._findFootnoteDefinition(lines)
+
+ if id :
+ plain = lines[:i]
+ detabbed, theRest = self.detectTabbed(lines[i+1:])
+ self.footnotes.setFootnote(id,
+ footnote + "\n"
+ + "\n".join(detabbed))
+ more_plain = self._handleFootnoteDefinitions(theRest)
+ return plain + [""] + more_plain
+ else :
+ return lines
+
+ def _findFootnoteDefinition(self, lines):
+ """
+ Find the parts of a footnote definition.
+
+ Keywords:
+
+ * lines: A list of lines of text.
+
+ Return: A three item tuple containing the index of the first line of a
+ footnote definition, the id of the definition and the body of the
+ definition.
+
+ """
+ counter = 0
+ for line in lines:
+ m = DEF_RE.match(line)
+ if m:
+ return counter, m.group(2), m.group(3)
+ counter += 1
+ return counter, None, None
+
+ def detectTabbed(self, lines):
+ """ Find indented text and remove indent before further proccesing.
+
+ Keyword arguments:
+
+ * lines: an array of strings
+
+ Returns: a list of post processed items and the unused
+ remainder of the original list
+
+ """
+ items = []
+ item = -1
+ i = 0 # to keep track of where we are
+
+ def detab(line):
+ match = TABBED_RE.match(line)
+ if match:
+ return match.group(4)
+
+ for line in lines:
+ if line.strip(): # Non-blank line
+ line = detab(line)
+ if line:
+ items.append(line)
+ i += 1
+ continue
+ else:
+ return items, lines[i:]
+
+ else: # Blank line: _maybe_ we are done.
+ i += 1 # advance
+
+ # Find the next non-blank line
+ for j in range(i, len(lines)):
+ if lines[j].strip():
+ next_line = lines[j]; break
+ else:
+ break # There is no more text; we are done.
+
+ # Check if the next non-blank line is tabbed
+ if detab(next_line): # Yes, more work to do.
+ items.append("")
+ continue
+ else:
+ break # No, we are done.
+ else:
+ i += 1
+
+ return items, lines[i:]
+
+
+class FootnotePattern(markdown.inlinepatterns.Pattern):
+ """ InlinePattern for footnote markers in a document's body text. """
+
+ def __init__(self, pattern, footnotes):
+ markdown.inlinepatterns.Pattern.__init__(self, pattern)
+ self.footnotes = footnotes
+
+ def handleMatch(self, m):
+ sup = etree.Element("sup")
+ a = etree.SubElement(sup, "a")
+ id = m.group(2)
+ sup.set('id', self.footnotes.makeFootnoteRefId(id))
+ a.set('href', '#' + self.footnotes.makeFootnoteId(id))
+ a.set('rel', 'footnote')
+ a.text = str(self.footnotes.footnotes.index(id) + 1)
+ return sup
+
+
+class FootnoteTreeprocessor(markdown.treeprocessors.Treeprocessor):
+ """ Build and append footnote div to end of document. """
+
+ def __init__ (self, footnotes):
+ self.footnotes = footnotes
+
+ def run(self, root):
+ footnotesDiv = self.footnotes.makeFootnotesDiv(root)
+ if footnotesDiv:
+ result = self.footnotes.findFootnotesPlaceholder(root)
+ if result:
+ node, isText = result
+ if isText:
+ node.text = None
+ node.getchildren().insert(0, footnotesDiv)
+ else:
+ child, element = node
+ ind = element.getchildren().find(child)
+ element.getchildren().insert(ind + 1, footnotesDiv)
+ child.tail = None
+ fnPlaceholder.parent.replaceChild(fnPlaceholder, footnotesDiv)
+ else:
+ root.append(footnotesDiv)
+
+class FootnotePostprocessor(markdown.postprocessors.Postprocessor):
+ """ Replace placeholders with html entities. """
+
+ def run(self, text):
+ text = text.replace(FN_BACKLINK_TEXT, "&#8617;")
+ return text.replace(NBSP_PLACEHOLDER, "&#160;")
+
+def makeExtension(configs=[]):
+ """ Return an instance of the FootnoteExtension """
+ return FootnoteExtension(configs=configs)
+
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/extensions/headerid.py b/tools/addon-sdk-1.7/python-lib/markdown/extensions/headerid.py
new file mode 100644
index 0000000..f70a7a9
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/extensions/headerid.py
@@ -0,0 +1,195 @@
+#!/usr/bin/python
+
+"""
+HeaderID Extension for Python-Markdown
+======================================
+
+Adds ability to set HTML IDs for headers.
+
+Basic usage:
+
+ >>> import markdown
+ >>> text = "# Some Header # {#some_id}"
+ >>> md = markdown.markdown(text, ['headerid'])
+ >>> md
+ u'<h1 id="some_id">Some Header</h1>'
+
+All header IDs are unique:
+
+ >>> text = '''
+ ... #Header
+ ... #Another Header {#header}
+ ... #Third Header {#header}'''
+ >>> md = markdown.markdown(text, ['headerid'])
+ >>> md
+ u'<h1 id="header">Header</h1>\\n<h1 id="header_1">Another Header</h1>\\n<h1 id="header_2">Third Header</h1>'
+
+To fit within a html template's hierarchy, set the header base level:
+
+ >>> text = '''
+ ... #Some Header
+ ... ## Next Level'''
+ >>> md = markdown.markdown(text, ['headerid(level=3)'])
+ >>> md
+ u'<h3 id="some_header">Some Header</h3>\\n<h4 id="next_level">Next Level</h4>'
+
+Turn off auto generated IDs:
+
+ >>> text = '''
+ ... # Some Header
+ ... # Header with ID # { #foo }'''
+ >>> md = markdown.markdown(text, ['headerid(forceid=False)'])
+ >>> md
+ u'<h1>Some Header</h1>\\n<h1 id="foo">Header with ID</h1>'
+
+Use with MetaData extension:
+
+ >>> text = '''header_level: 2
+ ... header_forceid: Off
+ ...
+ ... # A Header'''
+ >>> md = markdown.markdown(text, ['headerid', 'meta'])
+ >>> md
+ u'<h2>A Header</h2>'
+
+Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/).
+
+Project website: <http://www.freewisdom.org/project/python-markdown/HeaderId>
+Contact: markdown@freewisdom.org
+
+License: BSD (see ../docs/LICENSE for details)
+
+Dependencies:
+* [Python 2.3+](http://python.org)
+* [Markdown 2.0+](http://www.freewisdom.org/projects/python-markdown/)
+
+"""
+
+import markdown
+from markdown import etree
+import re
+from string import ascii_lowercase, digits, punctuation
+
+ID_CHARS = ascii_lowercase + digits + '-_'
+IDCOUNT_RE = re.compile(r'^(.*)_([0-9]+)$')
+
+
+class HeaderIdProcessor(markdown.blockprocessors.BlockProcessor):
+ """ Replacement BlockProcessor for Header IDs. """
+
+ # Detect a header at start of any line in block
+ RE = re.compile(r"""(^|\n)
+ (?P<level>\#{1,6}) # group('level') = string of hashes
+ (?P<header>.*?) # group('header') = Header text
+ \#* # optional closing hashes
+ (?:[ \t]*\{[ \t]*\#(?P<id>[-_:a-zA-Z0-9]+)[ \t]*\})?
+ (\n|$) # ^^ group('id') = id attribute
+ """,
+ re.VERBOSE)
+
+ IDs = []
+
+ def test(self, parent, block):
+ return bool(self.RE.search(block))
+
+ def run(self, parent, blocks):
+ block = blocks.pop(0)
+ m = self.RE.search(block)
+ if m:
+ before = block[:m.start()] # All lines before header
+ after = block[m.end():] # All lines after header
+ if before:
+ # As the header was not the first line of the block and the
+ # lines before the header must be parsed first,
+ # recursively parse this lines as a block.
+ self.parser.parseBlocks(parent, [before])
+ # Create header using named groups from RE
+ start_level, force_id = self._get_meta()
+ level = len(m.group('level')) + start_level
+ if level > 6:
+ level = 6
+ h = markdown.etree.SubElement(parent, 'h%d' % level)
+ h.text = m.group('header').strip()
+ if m.group('id'):
+ h.set('id', self._unique_id(m.group('id')))
+ elif force_id:
+ h.set('id', self._create_id(m.group('header').strip()))
+ if after:
+ # Insert remaining lines as first block for future parsing.
+ blocks.insert(0, after)
+ else:
+ # This should never happen, but just in case...
+ message(CRITICAL, "We've got a problem header!")
+
+ def _get_meta(self):
+ """ Return meta data suported by this ext as a tuple """
+ level = int(self.config['level'][0]) - 1
+ force = self._str2bool(self.config['forceid'][0])
+ if hasattr(self.md, 'Meta'):
+ if self.md.Meta.has_key('header_level'):
+ level = int(self.md.Meta['header_level'][0]) - 1
+ if self.md.Meta.has_key('header_forceid'):
+ force = self._str2bool(self.md.Meta['header_forceid'][0])
+ return level, force
+
+ def _str2bool(self, s, default=False):
+ """ Convert a string to a booleen value. """
+ s = str(s)
+ if s.lower() in ['0', 'f', 'false', 'off', 'no', 'n']:
+ return False
+ elif s.lower() in ['1', 't', 'true', 'on', 'yes', 'y']:
+ return True
+ return default
+
+ def _unique_id(self, id):
+ """ Ensure ID is unique. Append '_1', '_2'... if not """
+ while id in self.IDs:
+ m = IDCOUNT_RE.match(id)
+ if m:
+ id = '%s_%d'% (m.group(1), int(m.group(2))+1)
+ else:
+ id = '%s_%d'% (id, 1)
+ self.IDs.append(id)
+ return id
+
+ def _create_id(self, header):
+ """ Return ID from Header text. """
+ h = ''
+ for c in header.lower().replace(' ', '_'):
+ if c in ID_CHARS:
+ h += c
+ elif c not in punctuation:
+ h += '+'
+ return self._unique_id(h)
+
+
+class HeaderIdExtension (markdown.Extension):
+ def __init__(self, configs):
+ # set defaults
+ self.config = {
+ 'level' : ['1', 'Base level for headers.'],
+ 'forceid' : ['True', 'Force all headers to have an id.']
+ }
+
+ for key, value in configs:
+ self.setConfig(key, value)
+
+ def extendMarkdown(self, md, md_globals):
+ md.registerExtension(self)
+ self.processor = HeaderIdProcessor(md.parser)
+ self.processor.md = md
+ self.processor.config = self.config
+ # Replace existing hasheader in place.
+ md.parser.blockprocessors['hashheader'] = self.processor
+
+ def reset(self):
+ self.processor.IDs = []
+
+
+def makeExtension(configs=None):
+ return HeaderIdExtension(configs=configs)
+
+if __name__ == "__main__":
+ import doctest
+ doctest.testmod()
+
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/extensions/html_tidy.py b/tools/addon-sdk-1.7/python-lib/markdown/extensions/html_tidy.py
new file mode 100644
index 0000000..5105e33
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/extensions/html_tidy.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+
+"""
+HTML Tidy Extension for Python-Markdown
+=======================================
+
+Runs [HTML Tidy][] on the output of Python-Markdown using the [uTidylib][]
+Python wrapper. Both libtidy and uTidylib must be installed on your system.
+
+Note than any Tidy [options][] can be passed in as extension configs. So,
+for example, to output HTML rather than XHTML, set ``output_xhtml=0``. To
+indent the output, set ``indent=auto`` and to have Tidy wrap the output in
+``<html>`` and ``<body>`` tags, set ``show_body_only=0``.
+
+[HTML Tidy]: http://tidy.sourceforge.net/
+[uTidylib]: http://utidylib.berlios.de/
+[options]: http://tidy.sourceforge.net/docs/quickref.html
+
+Copyright (c)2008 [Waylan Limberg](http://achinghead.com)
+
+License: [BSD](http://www.opensource.org/licenses/bsd-license.php)
+
+Dependencies:
+* [Python2.3+](http://python.org)
+* [Markdown 2.0+](http://www.freewisdom.org/projects/python-markdown/)
+* [HTML Tidy](http://utidylib.berlios.de/)
+* [uTidylib](http://utidylib.berlios.de/)
+
+"""
+
+import markdown
+import tidy
+
+class TidyExtension(markdown.Extension):
+
+ def __init__(self, configs):
+ # Set defaults to match typical markdown behavior.
+ self.config = dict(output_xhtml=1,
+ show_body_only=1,
+ )
+ # Merge in user defined configs overriding any present if nessecary.
+ for c in configs:
+ self.config[c[0]] = c[1]
+
+ def extendMarkdown(self, md, md_globals):
+ # Save options to markdown instance
+ md.tidy_options = self.config
+ # Add TidyProcessor to postprocessors
+ md.postprocessors['tidy'] = TidyProcessor(md)
+
+
+class TidyProcessor(markdown.postprocessors.Postprocessor):
+
+ def run(self, text):
+ # Pass text to Tidy. As Tidy does not accept unicode we need to encode
+ # it and decode its return value.
+ return unicode(tidy.parseString(text.encode('utf-8'),
+ **self.markdown.tidy_options))
+
+
+def makeExtension(configs=None):
+ return TidyExtension(configs=configs)
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/extensions/imagelinks.py b/tools/addon-sdk-1.7/python-lib/markdown/extensions/imagelinks.py
new file mode 100644
index 0000000..ee0b708
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/extensions/imagelinks.py
@@ -0,0 +1,119 @@
+"""
+========================= IMAGE LINKS =================================
+
+
+Turns paragraphs like
+
+<~~~~~~~~~~~~~~~~~~~~~~~~
+dir/subdir
+dir/subdir
+dir/subdir
+~~~~~~~~~~~~~~
+dir/subdir
+dir/subdir
+dir/subdir
+~~~~~~~~~~~~~~~~~~~>
+
+Into mini-photo galleries.
+
+"""
+
+import re, markdown
+import url_manager
+
+
+IMAGE_LINK = """<a href="%s"><img src="%s" title="%s"/></a>"""
+SLIDESHOW_LINK = """<a href="%s" target="_blank">[slideshow]</a>"""
+ALBUM_LINK = """&nbsp;<a href="%s">[%s]</a>"""
+
+
+class ImageLinksExtension(markdown.Extension):
+
+ def extendMarkdown(self, md, md_globals):
+
+ md.preprocessors.add("imagelink", ImageLinkPreprocessor(md), "_begin")
+
+
+class ImageLinkPreprocessor(markdown.preprocessors.Preprocessor):
+
+ def run(self, lines):
+
+ url = url_manager.BlogEntryUrl(url_manager.BlogUrl("all"),
+ "2006/08/29/the_rest_of_our")
+
+
+ all_images = []
+ blocks = []
+ in_image_block = False
+
+ new_lines = []
+
+ for line in lines:
+
+ if line.startswith("<~~~~~~~"):
+ albums = []
+ rows = []
+ in_image_block = True
+
+ if not in_image_block:
+
+ new_lines.append(line)
+
+ else:
+
+ line = line.strip()
+
+ if line.endswith("~~~~~~>") or not line:
+ in_image_block = False
+ new_block = "<div><br/><center><span class='image-links'>\n"
+
+ album_url_hash = {}
+
+ for row in rows:
+ for photo_url, title in row:
+ new_block += "&nbsp;"
+ new_block += IMAGE_LINK % (photo_url,
+ photo_url.get_thumbnail(),
+ title)
+
+ album_url_hash[str(photo_url.get_album())] = 1
+
+ new_block += "<br/>"
+
+ new_block += "</span>"
+ new_block += SLIDESHOW_LINK % url.get_slideshow()
+
+ album_urls = album_url_hash.keys()
+ album_urls.sort()
+
+ if len(album_urls) == 1:
+ new_block += ALBUM_LINK % (album_urls[0], "complete album")
+ else :
+ for i in range(len(album_urls)) :
+ new_block += ALBUM_LINK % (album_urls[i],
+ "album %d" % (i + 1) )
+
+ new_lines.append(new_block + "</center><br/></div>")
+
+ elif line[1:6] == "~~~~~" :
+ rows.append([]) # start a new row
+ else :
+ parts = line.split()
+ line = parts[0]
+ title = " ".join(parts[1:])
+
+ album, photo = line.split("/")
+ photo_url = url.get_photo(album, photo,
+ len(all_images)+1)
+ all_images.append(photo_url)
+ rows[-1].append((photo_url, title))
+
+ if not album in albums :
+ albums.append(album)
+
+ return new_lines
+
+
+def makeExtension(configs):
+ return ImageLinksExtension(configs)
+
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/extensions/meta.py b/tools/addon-sdk-1.7/python-lib/markdown/extensions/meta.py
new file mode 100644
index 0000000..1b555b2
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/extensions/meta.py
@@ -0,0 +1,90 @@
+#!usr/bin/python
+
+"""
+Meta Data Extension for Python-Markdown
+=======================================
+
+This extension adds Meta Data handling to markdown.
+
+Basic Usage:
+
+ >>> import markdown
+ >>> text = '''Title: A Test Doc.
+ ... Author: Waylan Limberg
+ ... John Doe
+ ... Blank_Data:
+ ...
+ ... The body. This is paragraph one.
+ ... '''
+ >>> md = markdown.Markdown(['meta'])
+ >>> md.convert(text)
+ u'<p>The body. This is paragraph one.</p>'
+ >>> md.Meta
+ {u'blank_data': [u''], u'author': [u'Waylan Limberg', u'John Doe'], u'title': [u'A Test Doc.']}
+
+Make sure text without Meta Data still works (markdown < 1.6b returns a <p>).
+
+ >>> text = ' Some Code - not extra lines of meta data.'
+ >>> md = markdown.Markdown(['meta'])
+ >>> md.convert(text)
+ u'<pre><code>Some Code - not extra lines of meta data.\\n</code></pre>'
+ >>> md.Meta
+ {}
+
+Copyright 2007-2008 [Waylan Limberg](http://achinghead.com).
+
+Project website: <http://www.freewisdom.org/project/python-markdown/Meta-Data>
+Contact: markdown@freewisdom.org
+
+License: BSD (see ../docs/LICENSE for details)
+
+"""
+
+import markdown, re
+
+# Global Vars
+META_RE = re.compile(r'^[ ]{0,3}(?P<key>[A-Za-z0-9_-]+):\s*(?P<value>.*)')
+META_MORE_RE = re.compile(r'^[ ]{4,}(?P<value>.*)')
+
+class MetaExtension (markdown.Extension):
+ """ Meta-Data extension for Python-Markdown. """
+
+ def extendMarkdown(self, md, md_globals):
+ """ Add MetaPreprocessor to Markdown instance. """
+
+ md.preprocessors.add("meta", MetaPreprocessor(md), "_begin")
+
+
+class MetaPreprocessor(markdown.preprocessors.Preprocessor):
+ """ Get Meta-Data. """
+
+ def run(self, lines):
+ """ Parse Meta-Data and store in Markdown.Meta. """
+ meta = {}
+ key = None
+ while 1:
+ line = lines.pop(0)
+ if line.strip() == '':
+ break # blank line - done
+ m1 = META_RE.match(line)
+ if m1:
+ key = m1.group('key').lower().strip()
+ meta[key] = [m1.group('value').strip()]
+ else:
+ m2 = META_MORE_RE.match(line)
+ if m2 and key:
+ # Add another line to existing key
+ meta[key].append(m2.group('value').strip())
+ else:
+ lines.insert(0, line)
+ break # no meta data - done
+ self.markdown.Meta = meta
+ return lines
+
+
+def makeExtension(configs={}):
+ return MetaExtension(configs=configs)
+
+if __name__ == "__main__":
+ import doctest
+ doctest.testmod()
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/extensions/rss.py b/tools/addon-sdk-1.7/python-lib/markdown/extensions/rss.py
new file mode 100644
index 0000000..1274da2
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/extensions/rss.py
@@ -0,0 +1,114 @@
+import markdown
+from markdown import etree
+
+DEFAULT_URL = "http://www.freewisdom.org/projects/python-markdown/"
+DEFAULT_CREATOR = "Yuri Takhteyev"
+DEFAULT_TITLE = "Markdown in Python"
+GENERATOR = "http://www.freewisdom.org/projects/python-markdown/markdown2rss"
+
+month_map = { "Jan" : "01",
+ "Feb" : "02",
+ "March" : "03",
+ "April" : "04",
+ "May" : "05",
+ "June" : "06",
+ "July" : "07",
+ "August" : "08",
+ "September" : "09",
+ "October" : "10",
+ "November" : "11",
+ "December" : "12" }
+
+def get_time(heading):
+
+ heading = heading.split("-")[0]
+ heading = heading.strip().replace(",", " ").replace(".", " ")
+
+ month, date, year = heading.split()
+ month = month_map[month]
+
+ return rdftime(" ".join((month, date, year, "12:00:00 AM")))
+
+def rdftime(time):
+
+ time = time.replace(":", " ")
+ time = time.replace("/", " ")
+ time = time.split()
+ return "%s-%s-%sT%s:%s:%s-08:00" % (time[0], time[1], time[2],
+ time[3], time[4], time[5])
+
+
+def get_date(text):
+ return "date"
+
+class RssExtension (markdown.Extension):
+
+ def extendMarkdown(self, md, md_globals):
+
+ self.config = { 'URL' : [DEFAULT_URL, "Main URL"],
+ 'CREATOR' : [DEFAULT_CREATOR, "Feed creator's name"],
+ 'TITLE' : [DEFAULT_TITLE, "Feed title"] }
+
+ md.xml_mode = True
+
+ # Insert a tree-processor that would actually add the title tag
+ treeprocessor = RssTreeProcessor(md)
+ treeprocessor.ext = self
+ md.treeprocessors['rss'] = treeprocessor
+ md.stripTopLevelTags = 0
+ md.docType = '<?xml version="1.0" encoding="utf-8"?>\n'
+
+class RssTreeProcessor(markdown.treeprocessors.Treeprocessor):
+
+ def run (self, root):
+
+ rss = etree.Element("rss")
+ rss.set("version", "2.0")
+
+ channel = etree.SubElement(rss, "channel")
+
+ for tag, text in (("title", self.ext.getConfig("TITLE")),
+ ("link", self.ext.getConfig("URL")),
+ ("description", None)):
+
+ element = etree.SubElement(channel, tag)
+ element.text = text
+
+ for child in root:
+
+ if child.tag in ["h1", "h2", "h3", "h4", "h5"]:
+
+ heading = child.text.strip()
+ item = etree.SubElement(channel, "item")
+ link = etree.SubElement(item, "link")
+ link.text = self.ext.getConfig("URL")
+ title = etree.SubElement(item, "title")
+ title.text = heading
+
+ guid = ''.join([x for x in heading if x.isalnum()])
+ guidElem = etree.SubElement(item, "guid")
+ guidElem.text = guid
+ guidElem.set("isPermaLink", "false")
+
+ elif child.tag in ["p"]:
+ try:
+ description = etree.SubElement(item, "description")
+ except UnboundLocalError:
+ # Item not defined - moving on
+ pass
+ else:
+ if len(child):
+ content = "\n".join([etree.tostring(node)
+ for node in child])
+ else:
+ content = child.text
+ pholder = self.markdown.htmlStash.store(
+ "<![CDATA[ %s]]>" % content)
+ description.text = pholder
+
+ return rss
+
+
+def makeExtension(configs):
+
+ return RssExtension(configs)
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/extensions/tables.py b/tools/addon-sdk-1.7/python-lib/markdown/extensions/tables.py
new file mode 100644
index 0000000..1d3c920
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/extensions/tables.py
@@ -0,0 +1,97 @@
+#!/usr/bin/env Python
+"""
+Tables Extension for Python-Markdown
+====================================
+
+Added parsing of tables to Python-Markdown.
+
+A simple example:
+
+ First Header | Second Header
+ ------------- | -------------
+ Content Cell | Content Cell
+ Content Cell | Content Cell
+
+Copyright 2009 - [Waylan Limberg](http://achinghead.com)
+"""
+import markdown
+from markdown import etree
+
+
+class TableProcessor(markdown.blockprocessors.BlockProcessor):
+ """ Process Tables. """
+
+ def test(self, parent, block):
+ rows = block.split('\n')
+ return (len(rows) > 2 and '|' in rows[0] and
+ '|' in rows[1] and '-' in rows[1] and
+ rows[1][0] in ['|', ':', '-'])
+
+ def run(self, parent, blocks):
+ """ Parse a table block and build table. """
+ block = blocks.pop(0).split('\n')
+ header = block[:2]
+ rows = block[2:]
+ # Get format type (bordered by pipes or not)
+ border = False
+ if header[0].startswith('|'):
+ border = True
+ # Get alignment of columns
+ align = []
+ for c in self._split_row(header[1], border):
+ if c.startswith(':') and c.endswith(':'):
+ align.append('center')
+ elif c.startswith(':'):
+ align.append('left')
+ elif c.endswith(':'):
+ align.append('right')
+ else:
+ align.append(None)
+ # Build table
+ table = etree.SubElement(parent, 'table')
+ thead = etree.SubElement(table, 'thead')
+ self._build_row(header[0], thead, align, border)
+ tbody = etree.SubElement(table, 'tbody')
+ for row in rows:
+ self._build_row(row, tbody, align, border)
+
+ def _build_row(self, row, parent, align, border):
+ """ Given a row of text, build table cells. """
+ tr = etree.SubElement(parent, 'tr')
+ tag = 'td'
+ if parent.tag == 'thead':
+ tag = 'th'
+ cells = self._split_row(row, border)
+ # We use align here rather than cells to ensure every row
+ # contains the same number of columns.
+ for i, a in enumerate(align):
+ c = etree.SubElement(tr, tag)
+ try:
+ c.text = cells[i].strip()
+ except IndexError:
+ c.text = ""
+ if a:
+ c.set('align', a)
+
+ def _split_row(self, row, border):
+ """ split a row of text into list of cells. """
+ if border:
+ if row.startswith('|'):
+ row = row[1:]
+ if row.endswith('|'):
+ row = row[:-1]
+ return row.split('|')
+
+
+class TableExtension(markdown.Extension):
+ """ Add tables to Markdown. """
+
+ def extendMarkdown(self, md, md_globals):
+ """ Add an instance of TableProcessor to BlockParser. """
+ md.parser.blockprocessors.add('table',
+ TableProcessor(md.parser),
+ '<hashheader')
+
+
+def makeExtension(configs={}):
+ return TableExtension(configs=configs)
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/extensions/toc.py b/tools/addon-sdk-1.7/python-lib/markdown/extensions/toc.py
new file mode 100644
index 0000000..1624ccf
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/extensions/toc.py
@@ -0,0 +1,140 @@
+"""
+Table of Contents Extension for Python-Markdown
+* * *
+
+(c) 2008 [Jack Miller](http://codezen.org)
+
+Dependencies:
+* [Markdown 2.0+](http://www.freewisdom.org/projects/python-markdown/)
+
+"""
+import markdown
+from markdown import etree
+import re
+
+class TocTreeprocessor(markdown.treeprocessors.Treeprocessor):
+ # Iterator wrapper to get parent and child all at once
+ def iterparent(self, root):
+ for parent in root.getiterator():
+ for child in parent:
+ yield parent, child
+
+ def run(self, doc):
+ div = etree.Element("div")
+ div.attrib["class"] = "toc"
+ last_li = None
+
+ # Add title to the div
+ if self.config["title"][0]:
+ header = etree.SubElement(div, "span")
+ header.attrib["class"] = "toctitle"
+ header.text = self.config["title"][0]
+
+ level = 0
+ list_stack=[div]
+ header_rgx = re.compile("[Hh][123456]")
+
+ # Get a list of id attributes
+ used_ids = []
+ for c in doc.getiterator():
+ if "id" in c.attrib:
+ used_ids.append(c.attrib["id"])
+
+ for (p, c) in self.iterparent(doc):
+ if not c.text:
+ continue
+
+ # To keep the output from screwing up the
+ # validation by putting a <div> inside of a <p>
+ # we actually replace the <p> in its entirety.
+ # We do not allow the marker inside a header as that
+ # would causes an enless loop of placing a new TOC
+ # inside previously generated TOC.
+
+ if c.text.find(self.config["marker"][0]) > -1 and not header_rgx.match(c.tag):
+ for i in range(len(p)):
+ if p[i] == c:
+ p[i] = div
+ break
+
+ if header_rgx.match(c.tag):
+ tag_level = int(c.tag[-1])
+
+ # Regardless of how many levels we jumped
+ # only one list should be created, since
+ # empty lists containing lists are illegal.
+
+ if tag_level < level:
+ list_stack.pop()
+ level = tag_level
+
+ if tag_level > level:
+ newlist = etree.Element("ul")
+ if last_li:
+ last_li.append(newlist)
+ else:
+ list_stack[-1].append(newlist)
+ list_stack.append(newlist)
+ level = tag_level
+
+ # Do not override pre-existing ids
+ if not "id" in c.attrib:
+ id = self.config["slugify"][0](c.text)
+ if id in used_ids:
+ ctr = 1
+ while "%s_%d" % (id, ctr) in used_ids:
+ ctr += 1
+ id = "%s_%d" % (id, ctr)
+ used_ids.append(id)
+ c.attrib["id"] = id
+ else:
+ id = c.attrib["id"]
+
+ # List item link, to be inserted into the toc div
+ last_li = etree.Element("li")
+ link = etree.SubElement(last_li, "a")
+ link.text = c.text
+ link.attrib["href"] = '#' + id
+
+ if int(self.config["anchorlink"][0]):
+ anchor = etree.SubElement(c, "a")
+ anchor.text = c.text
+ anchor.attrib["href"] = "#" + id
+ anchor.attrib["class"] = "toclink"
+ c.text = ""
+
+ list_stack[-1].append(last_li)
+
+class TocExtension(markdown.Extension):
+ def __init__(self, configs):
+ self.config = { "marker" : ["[TOC]",
+ "Text to find and replace with Table of Contents -"
+ "Defaults to \"[TOC]\""],
+ "slugify" : [self.slugify,
+ "Function to generate anchors based on header text-"
+ "Defaults to a built in slugify function."],
+ "title" : [None,
+ "Title to insert into TOC <div> - "
+ "Defaults to None"],
+ "anchorlink" : [0,
+ "1 if header should be a self link"
+ "Defaults to 0"]}
+
+ for key, value in configs:
+ self.setConfig(key, value)
+
+ # This is exactly the same as Django's slugify
+ def slugify(self, value):
+ """ Slugify a string, to make it URL friendly. """
+ import unicodedata
+ value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
+ value = unicode(re.sub('[^\w\s-]', '', value).strip().lower())
+ return re.sub('[-\s]+','-',value)
+
+ def extendMarkdown(self, md, md_globals):
+ tocext = TocTreeprocessor(md)
+ tocext.config = self.config
+ md.treeprocessors.add("toc", tocext, "_begin")
+
+def makeExtension(configs={}):
+ return TocExtension(configs=configs)
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/extensions/wikilinks.py b/tools/addon-sdk-1.7/python-lib/markdown/extensions/wikilinks.py
new file mode 100644
index 0000000..df44e1c
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/extensions/wikilinks.py
@@ -0,0 +1,155 @@
+#!/usr/bin/env python
+
+'''
+WikiLinks Extension for Python-Markdown
+======================================
+
+Converts [[WikiLinks]] to relative links. Requires Python-Markdown 2.0+
+
+Basic usage:
+
+ >>> import markdown
+ >>> text = "Some text with a [[WikiLink]]."
+ >>> html = markdown.markdown(text, ['wikilinks'])
+ >>> html
+ u'<p>Some text with a <a class="wikilink" href="/WikiLink/">WikiLink</a>.</p>'
+
+Whitespace behavior:
+
+ >>> markdown.markdown('[[ foo bar_baz ]]', ['wikilinks'])
+ u'<p><a class="wikilink" href="/foo_bar_baz/">foo bar_baz</a></p>'
+ >>> markdown.markdown('foo [[ ]] bar', ['wikilinks'])
+ u'<p>foo bar</p>'
+
+To define custom settings the simple way:
+
+ >>> markdown.markdown(text,
+ ... ['wikilinks(base_url=/wiki/,end_url=.html,html_class=foo)']
+ ... )
+ u'<p>Some text with a <a class="foo" href="/wiki/WikiLink.html">WikiLink</a>.</p>'
+
+Custom settings the complex way:
+
+ >>> md = markdown.Markdown(
+ ... extensions = ['wikilinks'],
+ ... extension_configs = {'wikilinks': [
+ ... ('base_url', 'http://example.com/'),
+ ... ('end_url', '.html'),
+ ... ('html_class', '') ]},
+ ... safe_mode = True)
+ >>> md.convert(text)
+ u'<p>Some text with a <a href="http://example.com/WikiLink.html">WikiLink</a>.</p>'
+
+Use MetaData with mdx_meta.py (Note the blank html_class in MetaData):
+
+ >>> text = """wiki_base_url: http://example.com/
+ ... wiki_end_url: .html
+ ... wiki_html_class:
+ ...
+ ... Some text with a [[WikiLink]]."""
+ >>> md = markdown.Markdown(extensions=['meta', 'wikilinks'])
+ >>> md.convert(text)
+ u'<p>Some text with a <a href="http://example.com/WikiLink.html">WikiLink</a>.</p>'
+
+MetaData should not carry over to next document:
+
+ >>> md.convert("No [[MetaData]] here.")
+ u'<p>No <a class="wikilink" href="/MetaData/">MetaData</a> here.</p>'
+
+Define a custom URL builder:
+
+ >>> def my_url_builder(label, base, end):
+ ... return '/bar/'
+ >>> md = markdown.Markdown(extensions=['wikilinks'],
+ ... extension_configs={'wikilinks' : [('build_url', my_url_builder)]})
+ >>> md.convert('[[foo]]')
+ u'<p><a class="wikilink" href="/bar/">foo</a></p>'
+
+From the command line:
+
+ python markdown.py -x wikilinks(base_url=http://example.com/,end_url=.html,html_class=foo) src.txt
+
+By [Waylan Limberg](http://achinghead.com/).
+
+License: [BSD](http://www.opensource.org/licenses/bsd-license.php)
+
+Dependencies:
+* [Python 2.3+](http://python.org)
+* [Markdown 2.0+](http://www.freewisdom.org/projects/python-markdown/)
+'''
+
+import markdown
+import re
+
+def build_url(label, base, end):
+ """ Build a url from the label, a base, and an end. """
+ clean_label = re.sub(r'([ ]+_)|(_[ ]+)|([ ]+)', '_', label)
+ return '%s%s%s'% (base, clean_label, end)
+
+
+class WikiLinkExtension(markdown.Extension):
+ def __init__(self, configs):
+ # set extension defaults
+ self.config = {
+ 'base_url' : ['/', 'String to append to beginning or URL.'],
+ 'end_url' : ['/', 'String to append to end of URL.'],
+ 'html_class' : ['wikilink', 'CSS hook. Leave blank for none.'],
+ 'build_url' : [build_url, 'Callable formats URL from label.'],
+ }
+
+ # Override defaults with user settings
+ for key, value in configs :
+ self.setConfig(key, value)
+
+ def extendMarkdown(self, md, md_globals):
+ self.md = md
+
+ # append to end of inline patterns
+ WIKILINK_RE = r'\[\[([A-Za-z0-9_ -]+)\]\]'
+ wikilinkPattern = WikiLinks(WIKILINK_RE, self.config)
+ wikilinkPattern.md = md
+ md.inlinePatterns.add('wikilink', wikilinkPattern, "<not_strong")
+
+
+class WikiLinks(markdown.inlinepatterns.Pattern):
+ def __init__(self, pattern, config):
+ markdown.inlinepatterns.Pattern.__init__(self, pattern)
+ self.config = config
+
+ def handleMatch(self, m):
+ if m.group(2).strip():
+ base_url, end_url, html_class = self._getMeta()
+ label = m.group(2).strip()
+ url = self.config['build_url'][0](label, base_url, end_url)
+ a = markdown.etree.Element('a')
+ a.text = label
+ a.set('href', url)
+ if html_class:
+ a.set('class', html_class)
+ else:
+ a = ''
+ return a
+
+ def _getMeta(self):
+ """ Return meta data or config data. """
+ base_url = self.config['base_url'][0]
+ end_url = self.config['end_url'][0]
+ html_class = self.config['html_class'][0]
+ if hasattr(self.md, 'Meta'):
+ if self.md.Meta.has_key('wiki_base_url'):
+ base_url = self.md.Meta['wiki_base_url'][0]
+ if self.md.Meta.has_key('wiki_end_url'):
+ end_url = self.md.Meta['wiki_end_url'][0]
+ if self.md.Meta.has_key('wiki_html_class'):
+ html_class = self.md.Meta['wiki_html_class'][0]
+ return base_url, end_url, html_class
+
+
+def makeExtension(configs=None) :
+ return WikiLinkExtension(configs=configs)
+
+
+if __name__ == "__main__":
+ import doctest
+ doctest.testmod()
+
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/html4.py b/tools/addon-sdk-1.7/python-lib/markdown/html4.py
new file mode 100644
index 0000000..08f241d
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/html4.py
@@ -0,0 +1,274 @@
+# markdown/html4.py
+#
+# Add html4 serialization to older versions of Elementree
+# Taken from ElementTree 1.3 preview with slight modifications
+#
+# Copyright (c) 1999-2007 by Fredrik Lundh. All rights reserved.
+#
+# fredrik@pythonware.com
+# http://www.pythonware.com
+#
+# --------------------------------------------------------------------
+# The ElementTree toolkit is
+#
+# Copyright (c) 1999-2007 by Fredrik Lundh
+#
+# By obtaining, using, and/or copying this software and/or its
+# associated documentation, you agree that you have read, understood,
+# and will comply with the following terms and conditions:
+#
+# Permission to use, copy, modify, and distribute this software and
+# its associated documentation for any purpose and without fee is
+# hereby granted, provided that the above copyright notice appears in
+# all copies, and that both that copyright notice and this permission
+# notice appear in supporting documentation, and that the name of
+# Secret Labs AB or the author not be used in advertising or publicity
+# pertaining to distribution of the software without specific, written
+# prior permission.
+#
+# SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
+# TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT-
+# ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR
+# BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+# OF THIS SOFTWARE.
+# --------------------------------------------------------------------
+
+
+import markdown
+ElementTree = markdown.etree.ElementTree
+QName = markdown.etree.QName
+Comment = markdown.etree.Comment
+PI = markdown.etree.PI
+ProcessingInstruction = markdown.etree.ProcessingInstruction
+
+HTML_EMPTY = ("area", "base", "basefont", "br", "col", "frame", "hr",
+ "img", "input", "isindex", "link", "meta" "param")
+
+try:
+ HTML_EMPTY = set(HTML_EMPTY)
+except NameError:
+ pass
+
+_namespace_map = {
+ # "well-known" namespace prefixes
+ "http://www.w3.org/XML/1998/namespace": "xml",
+ "http://www.w3.org/1999/xhtml": "html",
+ "http://www.w3.org/1999/02/22-rdf-syntax-ns#": "rdf",
+ "http://schemas.xmlsoap.org/wsdl/": "wsdl",
+ # xml schema
+ "http://www.w3.org/2001/XMLSchema": "xs",
+ "http://www.w3.org/2001/XMLSchema-instance": "xsi",
+ # dublic core
+ "http://purl.org/dc/elements/1.1/": "dc",
+}
+
+
+def _raise_serialization_error(text):
+ raise TypeError(
+ "cannot serialize %r (type %s)" % (text, type(text).__name__)
+ )
+
+def _encode(text, encoding):
+ try:
+ return text.encode(encoding, "xmlcharrefreplace")
+ except (TypeError, AttributeError):
+ _raise_serialization_error(text)
+
+def _escape_cdata(text, encoding):
+ # escape character data
+ try:
+ # it's worth avoiding do-nothing calls for strings that are
+ # shorter than 500 character, or so. assume that's, by far,
+ # the most common case in most applications.
+ if "&" in text:
+ text = text.replace("&", "&amp;")
+ if "<" in text:
+ text = text.replace("<", "&lt;")
+ if ">" in text:
+ text = text.replace(">", "&gt;")
+ return text.encode(encoding, "xmlcharrefreplace")
+ except (TypeError, AttributeError):
+ _raise_serialization_error(text)
+
+
+def _escape_attrib(text, encoding):
+ # escape attribute value
+ try:
+ if "&" in text:
+ text = text.replace("&", "&amp;")
+ if "<" in text:
+ text = text.replace("<", "&lt;")
+ if ">" in text:
+ text = text.replace(">", "&gt;")
+ if "\"" in text:
+ text = text.replace("\"", "&quot;")
+ if "\n" in text:
+ text = text.replace("\n", "&#10;")
+ return text.encode(encoding, "xmlcharrefreplace")
+ except (TypeError, AttributeError):
+ _raise_serialization_error(text)
+
+def _escape_attrib_html(text, encoding):
+ # escape attribute value
+ try:
+ if "&" in text:
+ text = text.replace("&", "&amp;")
+ if ">" in text:
+ text = text.replace(">", "&gt;")
+ if "\"" in text:
+ text = text.replace("\"", "&quot;")
+ return text.encode(encoding, "xmlcharrefreplace")
+ except (TypeError, AttributeError):
+ _raise_serialization_error(text)
+
+
+def _serialize_html(write, elem, encoding, qnames, namespaces):
+ tag = elem.tag
+ text = elem.text
+ if tag is Comment:
+ write("<!--%s-->" % _escape_cdata(text, encoding))
+ elif tag is ProcessingInstruction:
+ write("<?%s?>" % _escape_cdata(text, encoding))
+ else:
+ tag = qnames[tag]
+ if tag is None:
+ if text:
+ write(_escape_cdata(text, encoding))
+ for e in elem:
+ _serialize_html(write, e, encoding, qnames, None)
+ else:
+ write("<" + tag)
+ items = elem.items()
+ if items or namespaces:
+ items.sort() # lexical order
+ for k, v in items:
+ if isinstance(k, QName):
+ k = k.text
+ if isinstance(v, QName):
+ v = qnames[v.text]
+ else:
+ v = _escape_attrib_html(v, encoding)
+ # FIXME: handle boolean attributes
+ write(" %s=\"%s\"" % (qnames[k], v))
+ if namespaces:
+ items = namespaces.items()
+ items.sort(key=lambda x: x[1]) # sort on prefix
+ for v, k in items:
+ if k:
+ k = ":" + k
+ write(" xmlns%s=\"%s\"" % (
+ k.encode(encoding),
+ _escape_attrib(v, encoding)
+ ))
+ write(">")
+ tag = tag.lower()
+ if text:
+ if tag == "script" or tag == "style":
+ write(_encode(text, encoding))
+ else:
+ write(_escape_cdata(text, encoding))
+ for e in elem:
+ _serialize_html(write, e, encoding, qnames, None)
+ if tag not in HTML_EMPTY:
+ write("</" + tag + ">")
+ if elem.tail:
+ write(_escape_cdata(elem.tail, encoding))
+
+def write_html(root, f,
+ # keyword arguments
+ encoding="us-ascii",
+ default_namespace=None):
+ assert root is not None
+ if not hasattr(f, "write"):
+ f = open(f, "wb")
+ write = f.write
+ if not encoding:
+ encoding = "us-ascii"
+ qnames, namespaces = _namespaces(
+ root, encoding, default_namespace
+ )
+ _serialize_html(
+ write, root, encoding, qnames, namespaces
+ )
+
+# --------------------------------------------------------------------
+# serialization support
+
+def _namespaces(elem, encoding, default_namespace=None):
+ # identify namespaces used in this tree
+
+ # maps qnames to *encoded* prefix:local names
+ qnames = {None: None}
+
+ # maps uri:s to prefixes
+ namespaces = {}
+ if default_namespace:
+ namespaces[default_namespace] = ""
+
+ def encode(text):
+ return text.encode(encoding)
+
+ def add_qname(qname):
+ # calculate serialized qname representation
+ try:
+ if qname[:1] == "{":
+ uri, tag = qname[1:].split("}", 1)
+ prefix = namespaces.get(uri)
+ if prefix is None:
+ prefix = _namespace_map.get(uri)
+ if prefix is None:
+ prefix = "ns%d" % len(namespaces)
+ if prefix != "xml":
+ namespaces[uri] = prefix
+ if prefix:
+ qnames[qname] = encode("%s:%s" % (prefix, tag))
+ else:
+ qnames[qname] = encode(tag) # default element
+ else:
+ if default_namespace:
+ # FIXME: can this be handled in XML 1.0?
+ raise ValueError(
+ "cannot use non-qualified names with "
+ "default_namespace option"
+ )
+ qnames[qname] = encode(qname)
+ except TypeError:
+ _raise_serialization_error(qname)
+
+ # populate qname and namespaces table
+ try:
+ iterate = elem.iter
+ except AttributeError:
+ iterate = elem.getiterator # cET compatibility
+ for elem in iterate():
+ tag = elem.tag
+ if isinstance(tag, QName) and tag.text not in qnames:
+ add_qname(tag.text)
+ elif isinstance(tag, basestring):
+ if tag not in qnames:
+ add_qname(tag)
+ elif tag is not None and tag is not Comment and tag is not PI:
+ _raise_serialization_error(tag)
+ for key, value in elem.items():
+ if isinstance(key, QName):
+ key = key.text
+ if key not in qnames:
+ add_qname(key)
+ if isinstance(value, QName) and value.text not in qnames:
+ add_qname(value.text)
+ text = elem.text
+ if isinstance(text, QName) and text.text not in qnames:
+ add_qname(text.text)
+ return qnames, namespaces
+
+def to_html_string(element, encoding=None):
+ class dummy:
+ pass
+ data = []
+ file = dummy()
+ file.write = data.append
+ write_html(ElementTree(element).getroot(),file,encoding)
+ return "".join(data)
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/inlinepatterns.py b/tools/addon-sdk-1.7/python-lib/markdown/inlinepatterns.py
new file mode 100644
index 0000000..89fa3b2
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/inlinepatterns.py
@@ -0,0 +1,371 @@
+"""
+INLINE PATTERNS
+=============================================================================
+
+Inline patterns such as *emphasis* are handled by means of auxiliary
+objects, one per pattern. Pattern objects must be instances of classes
+that extend markdown.Pattern. Each pattern object uses a single regular
+expression and needs support the following methods:
+
+ pattern.getCompiledRegExp() # returns a regular expression
+
+ pattern.handleMatch(m) # takes a match object and returns
+ # an ElementTree element or just plain text
+
+All of python markdown's built-in patterns subclass from Pattern,
+but you can add additional patterns that don't.
+
+Also note that all the regular expressions used by inline must
+capture the whole block. For this reason, they all start with
+'^(.*)' and end with '(.*)!'. In case with built-in expression
+Pattern takes care of adding the "^(.*)" and "(.*)!".
+
+Finally, the order in which regular expressions are applied is very
+important - e.g. if we first replace http://.../ links with <a> tags
+and _then_ try to replace inline html, we would end up with a mess.
+So, we apply the expressions in the following order:
+
+* escape and backticks have to go before everything else, so
+ that we can preempt any markdown patterns by escaping them.
+
+* then we handle auto-links (must be done before inline html)
+
+* then we handle inline HTML. At this point we will simply
+ replace all inline HTML strings with a placeholder and add
+ the actual HTML to a hash.
+
+* then inline images (must be done before links)
+
+* then bracketed links, first regular then reference-style
+
+* finally we apply strong and emphasis
+"""
+
+import markdown
+import re
+from urlparse import urlparse, urlunparse
+import sys
+if sys.version >= "3.0":
+ from html import entities as htmlentitydefs
+else:
+ import htmlentitydefs
+
+"""
+The actual regular expressions for patterns
+-----------------------------------------------------------------------------
+"""
+
+NOBRACKET = r'[^\]\[]*'
+BRK = ( r'\[('
+ + (NOBRACKET + r'(\[')*6
+ + (NOBRACKET+ r'\])*')*6
+ + NOBRACKET + r')\]' )
+NOIMG = r'(?<!\!)'
+
+BACKTICK_RE = r'(?<!\\)(`+)(.+?)(?<!`)\2(?!`)' # `e=f()` or ``e=f("`")``
+ESCAPE_RE = r'\\(.)' # \<
+EMPHASIS_RE = r'(\*)([^\*]*)\2' # *emphasis*
+STRONG_RE = r'(\*{2}|_{2})(.*?)\2' # **strong**
+STRONG_EM_RE = r'(\*{3}|_{3})(.*?)\2' # ***strong***
+
+if markdown.SMART_EMPHASIS:
+ EMPHASIS_2_RE = r'(?<!\S)(_)(\S.*?)\2' # _emphasis_
+else:
+ EMPHASIS_2_RE = r'(_)(.*?)\2' # _emphasis_
+
+LINK_RE = NOIMG + BRK + \
+r'''\(\s*(<.*?>|((?:(?:\(.*?\))|[^\(\)]))*?)\s*((['"])(.*)\12)?\)'''
+# [text](url) or [text](<url>)
+
+IMAGE_LINK_RE = r'\!' + BRK + r'\s*\((<.*?>|([^\)]*))\)'
+# ![alttxt](http://x.com/) or ![alttxt](<http://x.com/>)
+REFERENCE_RE = NOIMG + BRK+ r'\s*\[([^\]]*)\]' # [Google][3]
+IMAGE_REFERENCE_RE = r'\!' + BRK + '\s*\[([^\]]*)\]' # ![alt text][2]
+NOT_STRONG_RE = r'( \* )' # stand-alone * or _
+AUTOLINK_RE = r'<((?:f|ht)tps?://[^>]*)>' # <http://www.123.com>
+AUTOMAIL_RE = r'<([^> \!]*@[^> ]*)>' # <me@example.com>
+
+HTML_RE = r'(\<([a-zA-Z/][^\>]*?|\!--.*?--)\>)' # <...>
+ENTITY_RE = r'(&[\#a-zA-Z0-9]*;)' # &amp;
+LINE_BREAK_RE = r' \n' # two spaces at end of line
+LINE_BREAK_2_RE = r' $' # two spaces at end of text
+
+
+def dequote(string):
+ """Remove quotes from around a string."""
+ if ( ( string.startswith('"') and string.endswith('"'))
+ or (string.startswith("'") and string.endswith("'")) ):
+ return string[1:-1]
+ else:
+ return string
+
+ATTR_RE = re.compile("\{@([^\}]*)=([^\}]*)}") # {@id=123}
+
+def handleAttributes(text, parent):
+ """Set values of an element based on attribute definitions ({@id=123})."""
+ def attributeCallback(match):
+ parent.set(match.group(1), match.group(2).replace('\n', ' '))
+ return ATTR_RE.sub(attributeCallback, text)
+
+
+"""
+The pattern classes
+-----------------------------------------------------------------------------
+"""
+
+class Pattern:
+ """Base class that inline patterns subclass. """
+
+ def __init__ (self, pattern, markdown_instance=None):
+ """
+ Create an instant of an inline pattern.
+
+ Keyword arguments:
+
+ * pattern: A regular expression that matches a pattern
+
+ """
+ self.pattern = pattern
+ self.compiled_re = re.compile("^(.*?)%s(.*?)$" % pattern, re.DOTALL)
+
+ # Api for Markdown to pass safe_mode into instance
+ self.safe_mode = False
+ if markdown_instance:
+ self.markdown = markdown_instance
+
+ def getCompiledRegExp (self):
+ """ Return a compiled regular expression. """
+ return self.compiled_re
+
+ def handleMatch(self, m):
+ """Return a ElementTree element from the given match.
+
+ Subclasses should override this method.
+
+ Keyword arguments:
+
+ * m: A re match object containing a match of the pattern.
+
+ """
+ pass
+
+ def type(self):
+ """ Return class name, to define pattern type """
+ return self.__class__.__name__
+
+BasePattern = Pattern # for backward compatibility
+
+class SimpleTextPattern (Pattern):
+ """ Return a simple text of group(2) of a Pattern. """
+ def handleMatch(self, m):
+ text = m.group(2)
+ if text == markdown.INLINE_PLACEHOLDER_PREFIX:
+ return None
+ return text
+
+class SimpleTagPattern (Pattern):
+ """
+ Return element of type `tag` with a text attribute of group(3)
+ of a Pattern.
+
+ """
+ def __init__ (self, pattern, tag):
+ Pattern.__init__(self, pattern)
+ self.tag = tag
+
+ def handleMatch(self, m):
+ el = markdown.etree.Element(self.tag)
+ el.text = m.group(3)
+ return el
+
+
+class SubstituteTagPattern (SimpleTagPattern):
+ """ Return a eLement of type `tag` with no children. """
+ def handleMatch (self, m):
+ return markdown.etree.Element(self.tag)
+
+
+class BacktickPattern (Pattern):
+ """ Return a `<code>` element containing the matching text. """
+ def __init__ (self, pattern):
+ Pattern.__init__(self, pattern)
+ self.tag = "code"
+
+ def handleMatch(self, m):
+ el = markdown.etree.Element(self.tag)
+ el.text = markdown.AtomicString(m.group(3).strip())
+ return el
+
+
+class DoubleTagPattern (SimpleTagPattern):
+ """Return a ElementTree element nested in tag2 nested in tag1.
+
+ Useful for strong emphasis etc.
+
+ """
+ def handleMatch(self, m):
+ tag1, tag2 = self.tag.split(",")
+ el1 = markdown.etree.Element(tag1)
+ el2 = markdown.etree.SubElement(el1, tag2)
+ el2.text = m.group(3)
+ return el1
+
+
+class HtmlPattern (Pattern):
+ """ Store raw inline html and return a placeholder. """
+ def handleMatch (self, m):
+ rawhtml = m.group(2)
+ inline = True
+ place_holder = self.markdown.htmlStash.store(rawhtml)
+ return place_holder
+
+
+class LinkPattern (Pattern):
+ """ Return a link element from the given match. """
+ def handleMatch(self, m):
+ el = markdown.etree.Element("a")
+ el.text = m.group(2)
+ title = m.group(11)
+ href = m.group(9)
+
+ if href:
+ if href[0] == "<":
+ href = href[1:-1]
+ el.set("href", self.sanitize_url(href.strip()))
+ else:
+ el.set("href", "")
+
+ if title:
+ title = dequote(title) #.replace('"', "&quot;")
+ el.set("title", title)
+ return el
+
+ def sanitize_url(self, url):
+ """
+ Sanitize a url against xss attacks in "safe_mode".
+
+ Rather than specifically blacklisting `javascript:alert("XSS")` and all
+ its aliases (see <http://ha.ckers.org/xss.html>), we whitelist known
+ safe url formats. Most urls contain a network location, however some
+ are known not to (i.e.: mailto links). Script urls do not contain a
+ location. Additionally, for `javascript:...`, the scheme would be
+ "javascript" but some aliases will appear to `urlparse()` to have no
+ scheme. On top of that relative links (i.e.: "foo/bar.html") have no
+ scheme. Therefore we must check "path", "parameters", "query" and
+ "fragment" for any literal colons. We don't check "scheme" for colons
+ because it *should* never have any and "netloc" must allow the form:
+ `username:password@host:port`.
+
+ """
+ locless_schemes = ['', 'mailto', 'news']
+ scheme, netloc, path, params, query, fragment = url = urlparse(url)
+ safe_url = False
+ if netloc != '' or scheme in locless_schemes:
+ safe_url = True
+
+ for part in url[2:]:
+ if ":" in part:
+ safe_url = False
+
+ if self.markdown.safeMode and not safe_url:
+ return ''
+ else:
+ return urlunparse(url)
+
+class ImagePattern(LinkPattern):
+ """ Return a img element from the given match. """
+ def handleMatch(self, m):
+ el = markdown.etree.Element("img")
+ src_parts = m.group(9).split()
+ if src_parts:
+ src = src_parts[0]
+ if src[0] == "<" and src[-1] == ">":
+ src = src[1:-1]
+ el.set('src', self.sanitize_url(src))
+ else:
+ el.set('src', "")
+ if len(src_parts) > 1:
+ el.set('title', dequote(" ".join(src_parts[1:])))
+
+ if markdown.ENABLE_ATTRIBUTES:
+ truealt = handleAttributes(m.group(2), el)
+ else:
+ truealt = m.group(2)
+
+ el.set('alt', truealt)
+ return el
+
+class ReferencePattern(LinkPattern):
+ """ Match to a stored reference and return link element. """
+ def handleMatch(self, m):
+ if m.group(9):
+ id = m.group(9).lower()
+ else:
+ # if we got something like "[Google][]"
+ # we'll use "google" as the id
+ id = m.group(2).lower()
+
+ if not id in self.markdown.references: # ignore undefined refs
+ return None
+ href, title = self.markdown.references[id]
+
+ text = m.group(2)
+ return self.makeTag(href, title, text)
+
+ def makeTag(self, href, title, text):
+ el = markdown.etree.Element('a')
+
+ el.set('href', self.sanitize_url(href))
+ if title:
+ el.set('title', title)
+
+ el.text = text
+ return el
+
+
+class ImageReferencePattern (ReferencePattern):
+ """ Match to a stored reference and return img element. """
+ def makeTag(self, href, title, text):
+ el = markdown.etree.Element("img")
+ el.set("src", self.sanitize_url(href))
+ if title:
+ el.set("title", title)
+ el.set("alt", text)
+ return el
+
+
+class AutolinkPattern (Pattern):
+ """ Return a link Element given an autolink (`<http://example/com>`). """
+ def handleMatch(self, m):
+ el = markdown.etree.Element("a")
+ el.set('href', m.group(2))
+ el.text = markdown.AtomicString(m.group(2))
+ return el
+
+class AutomailPattern (Pattern):
+ """
+ Return a mailto link Element given an automail link (`<foo@example.com>`).
+ """
+ def handleMatch(self, m):
+ el = markdown.etree.Element('a')
+ email = m.group(2)
+ if email.startswith("mailto:"):
+ email = email[len("mailto:"):]
+
+ def codepoint2name(code):
+ """Return entity definition by code, or the code if not defined."""
+ entity = htmlentitydefs.codepoint2name.get(code)
+ if entity:
+ return "%s%s;" % (markdown.AMP_SUBSTITUTE, entity)
+ else:
+ return "%s#%d;" % (markdown.AMP_SUBSTITUTE, code)
+
+ letters = [codepoint2name(ord(letter)) for letter in email]
+ el.text = markdown.AtomicString(''.join(letters))
+
+ mailto = "mailto:" + email
+ mailto = "".join([markdown.AMP_SUBSTITUTE + '#%d;' %
+ ord(letter) for letter in mailto])
+ el.set('href', mailto)
+ return el
+
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/odict.py b/tools/addon-sdk-1.7/python-lib/markdown/odict.py
new file mode 100644
index 0000000..bf3ef07
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/odict.py
@@ -0,0 +1,162 @@
+class OrderedDict(dict):
+ """
+ A dictionary that keeps its keys in the order in which they're inserted.
+
+ Copied from Django's SortedDict with some modifications.
+
+ """
+ def __new__(cls, *args, **kwargs):
+ instance = super(OrderedDict, cls).__new__(cls, *args, **kwargs)
+ instance.keyOrder = []
+ return instance
+
+ def __init__(self, data=None):
+ if data is None:
+ data = {}
+ super(OrderedDict, self).__init__(data)
+ if isinstance(data, dict):
+ self.keyOrder = data.keys()
+ else:
+ self.keyOrder = []
+ for key, value in data:
+ if key not in self.keyOrder:
+ self.keyOrder.append(key)
+
+ def __deepcopy__(self, memo):
+ from copy import deepcopy
+ return self.__class__([(key, deepcopy(value, memo))
+ for key, value in self.iteritems()])
+
+ def __setitem__(self, key, value):
+ super(OrderedDict, self).__setitem__(key, value)
+ if key not in self.keyOrder:
+ self.keyOrder.append(key)
+
+ def __delitem__(self, key):
+ super(OrderedDict, self).__delitem__(key)
+ self.keyOrder.remove(key)
+
+ def __iter__(self):
+ for k in self.keyOrder:
+ yield k
+
+ def pop(self, k, *args):
+ result = super(OrderedDict, self).pop(k, *args)
+ try:
+ self.keyOrder.remove(k)
+ except ValueError:
+ # Key wasn't in the dictionary in the first place. No problem.
+ pass
+ return result
+
+ def popitem(self):
+ result = super(OrderedDict, self).popitem()
+ self.keyOrder.remove(result[0])
+ return result
+
+ def items(self):
+ return zip(self.keyOrder, self.values())
+
+ def iteritems(self):
+ for key in self.keyOrder:
+ yield key, super(OrderedDict, self).__getitem__(key)
+
+ def keys(self):
+ return self.keyOrder[:]
+
+ def iterkeys(self):
+ return iter(self.keyOrder)
+
+ def values(self):
+ return [super(OrderedDict, self).__getitem__(k) for k in self.keyOrder]
+
+ def itervalues(self):
+ for key in self.keyOrder:
+ yield super(OrderedDict, self).__getitem__(key)
+
+ def update(self, dict_):
+ for k, v in dict_.items():
+ self.__setitem__(k, v)
+
+ def setdefault(self, key, default):
+ if key not in self.keyOrder:
+ self.keyOrder.append(key)
+ return super(OrderedDict, self).setdefault(key, default)
+
+ def value_for_index(self, index):
+ """Return the value of the item at the given zero-based index."""
+ return self[self.keyOrder[index]]
+
+ def insert(self, index, key, value):
+ """Insert the key, value pair before the item with the given index."""
+ if key in self.keyOrder:
+ n = self.keyOrder.index(key)
+ del self.keyOrder[n]
+ if n < index:
+ index -= 1
+ self.keyOrder.insert(index, key)
+ super(OrderedDict, self).__setitem__(key, value)
+
+ def copy(self):
+ """Return a copy of this object."""
+ # This way of initializing the copy means it works for subclasses, too.
+ obj = self.__class__(self)
+ obj.keyOrder = self.keyOrder[:]
+ return obj
+
+ def __repr__(self):
+ """
+ Replace the normal dict.__repr__ with a version that returns the keys
+ in their sorted order.
+ """
+ return '{%s}' % ', '.join(['%r: %r' % (k, v) for k, v in self.items()])
+
+ def clear(self):
+ super(OrderedDict, self).clear()
+ self.keyOrder = []
+
+ def index(self, key):
+ """ Return the index of a given key. """
+ return self.keyOrder.index(key)
+
+ def index_for_location(self, location):
+ """ Return index or None for a given location. """
+ if location == '_begin':
+ i = 0
+ elif location == '_end':
+ i = None
+ elif location.startswith('<') or location.startswith('>'):
+ i = self.index(location[1:])
+ if location.startswith('>'):
+ if i >= len(self):
+ # last item
+ i = None
+ else:
+ i += 1
+ else:
+ raise ValueError('Not a valid location: "%s". Location key '
+ 'must start with a ">" or "<".' % location)
+ return i
+
+ def add(self, key, value, location):
+ """ Insert by key location. """
+ i = self.index_for_location(location)
+ if i is not None:
+ self.insert(i, key, value)
+ else:
+ self.__setitem__(key, value)
+
+ def link(self, key, location):
+ """ Change location of an existing item. """
+ n = self.keyOrder.index(key)
+ del self.keyOrder[n]
+ i = self.index_for_location(location)
+ try:
+ if i is not None:
+ self.keyOrder.insert(i, key)
+ else:
+ self.keyOrder.append(key)
+ except Error:
+ # restore to prevent data loss and reraise
+ self.keyOrder.insert(n, key)
+ raise Error
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/postprocessors.py b/tools/addon-sdk-1.7/python-lib/markdown/postprocessors.py
new file mode 100644
index 0000000..80227bb
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/postprocessors.py
@@ -0,0 +1,77 @@
+"""
+POST-PROCESSORS
+=============================================================================
+
+Markdown also allows post-processors, which are similar to preprocessors in
+that they need to implement a "run" method. However, they are run after core
+processing.
+
+"""
+
+
+import markdown
+
+class Processor:
+ def __init__(self, markdown_instance=None):
+ if markdown_instance:
+ self.markdown = markdown_instance
+
+class Postprocessor(Processor):
+ """
+ Postprocessors are run after the ElementTree it converted back into text.
+
+ Each Postprocessor implements a "run" method that takes a pointer to a
+ text string, modifies it as necessary and returns a text string.
+
+ Postprocessors must extend markdown.Postprocessor.
+
+ """
+
+ def run(self, text):
+ """
+ Subclasses of Postprocessor should implement a `run` method, which
+ takes the html document as a single text string and returns a
+ (possibly modified) string.
+
+ """
+ pass
+
+
+class RawHtmlPostprocessor(Postprocessor):
+ """ Restore raw html to the document. """
+
+ def run(self, text):
+ """ Iterate over html stash and restore "safe" html. """
+ for i in range(self.markdown.htmlStash.html_counter):
+ html, safe = self.markdown.htmlStash.rawHtmlBlocks[i]
+ if self.markdown.safeMode and not safe:
+ if str(self.markdown.safeMode).lower() == 'escape':
+ html = self.escape(html)
+ elif str(self.markdown.safeMode).lower() == 'remove':
+ html = ''
+ else:
+ html = markdown.HTML_REMOVED_TEXT
+ if safe or not self.markdown.safeMode:
+ text = text.replace("<p>%s</p>" %
+ (markdown.preprocessors.HTML_PLACEHOLDER % i),
+ html + "\n")
+ text = text.replace(markdown.preprocessors.HTML_PLACEHOLDER % i,
+ html)
+ return text
+
+ def escape(self, html):
+ """ Basic html escaping """
+ html = html.replace('&', '&amp;')
+ html = html.replace('<', '&lt;')
+ html = html.replace('>', '&gt;')
+ return html.replace('"', '&quot;')
+
+
+class AndSubstitutePostprocessor(Postprocessor):
+ """ Restore valid entities """
+ def __init__(self):
+ pass
+
+ def run(self, text):
+ text = text.replace(markdown.AMP_SUBSTITUTE, "&")
+ return text
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/preprocessors.py b/tools/addon-sdk-1.7/python-lib/markdown/preprocessors.py
new file mode 100644
index 0000000..712a1e8
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/preprocessors.py
@@ -0,0 +1,214 @@
+
+"""
+PRE-PROCESSORS
+=============================================================================
+
+Preprocessors work on source text before we start doing anything too
+complicated.
+"""
+
+import re
+import markdown
+
+HTML_PLACEHOLDER_PREFIX = markdown.STX+"wzxhzdk:"
+HTML_PLACEHOLDER = HTML_PLACEHOLDER_PREFIX + "%d" + markdown.ETX
+
+class Processor:
+ def __init__(self, markdown_instance=None):
+ if markdown_instance:
+ self.markdown = markdown_instance
+
+class Preprocessor (Processor):
+ """
+ Preprocessors are run after the text is broken into lines.
+
+ Each preprocessor implements a "run" method that takes a pointer to a
+ list of lines of the document, modifies it as necessary and returns
+ either the same pointer or a pointer to a new list.
+
+ Preprocessors must extend markdown.Preprocessor.
+
+ """
+ def run(self, lines):
+ """
+ Each subclass of Preprocessor should override the `run` method, which
+ takes the document as a list of strings split by newlines and returns
+ the (possibly modified) list of lines.
+
+ """
+ pass
+
+class HtmlStash:
+ """
+ This class is used for stashing HTML objects that we extract
+ in the beginning and replace with place-holders.
+ """
+
+ def __init__ (self):
+ """ Create a HtmlStash. """
+ self.html_counter = 0 # for counting inline html segments
+ self.rawHtmlBlocks=[]
+
+ def store(self, html, safe=False):
+ """
+ Saves an HTML segment for later reinsertion. Returns a
+ placeholder string that needs to be inserted into the
+ document.
+
+ Keyword arguments:
+
+ * html: an html segment
+ * safe: label an html segment as safe for safemode
+
+ Returns : a placeholder string
+
+ """
+ self.rawHtmlBlocks.append((html, safe))
+ placeholder = HTML_PLACEHOLDER % self.html_counter
+ self.html_counter += 1
+ return placeholder
+
+ def reset(self):
+ self.html_counter = 0
+ self.rawHtmlBlocks = []
+
+
+class HtmlBlockPreprocessor(Preprocessor):
+ """Remove html blocks from the text and store them for later retrieval."""
+
+ right_tag_patterns = ["</%s>", "%s>"]
+
+ def _get_left_tag(self, block):
+ return block[1:].replace(">", " ", 1).split()[0].lower()
+
+ def _get_right_tag(self, left_tag, block):
+ for p in self.right_tag_patterns:
+ tag = p % left_tag
+ i = block.rfind(tag)
+ if i > 2:
+ return tag.lstrip("<").rstrip(">"), i + len(p)-2 + len(left_tag)
+ return block.rstrip()[-len(left_tag)-2:-1].lower(), len(block)
+
+ def _equal_tags(self, left_tag, right_tag):
+ if left_tag == 'div' or left_tag[0] in ['?', '@', '%']: # handle PHP, etc.
+ return True
+ if ("/" + left_tag) == right_tag:
+ return True
+ if (right_tag == "--" and left_tag == "--"):
+ return True
+ elif left_tag == right_tag[1:] \
+ and right_tag[0] != "<":
+ return True
+ else:
+ return False
+
+ def _is_oneliner(self, tag):
+ return (tag in ['hr', 'hr/'])
+
+ def run(self, lines):
+ text = "\n".join(lines)
+ new_blocks = []
+ text = text.split("\n\n")
+ items = []
+ left_tag = ''
+ right_tag = ''
+ in_tag = False # flag
+
+ while text:
+ block = text[0]
+ if block.startswith("\n"):
+ block = block[1:]
+ text = text[1:]
+
+ if block.startswith("\n"):
+ block = block[1:]
+
+ if not in_tag:
+ if block.startswith("<"):
+ left_tag = self._get_left_tag(block)
+ right_tag, data_index = self._get_right_tag(left_tag, block)
+
+ if data_index < len(block):
+ text.insert(0, block[data_index:])
+ block = block[:data_index]
+
+ if not (markdown.isBlockLevel(left_tag) \
+ or block[1] in ["!", "?", "@", "%"]):
+ new_blocks.append(block)
+ continue
+
+ if self._is_oneliner(left_tag):
+ new_blocks.append(block.strip())
+ continue
+
+ if block[1] == "!":
+ # is a comment block
+ left_tag = "--"
+ right_tag, data_index = self._get_right_tag(left_tag, block)
+ # keep checking conditions below and maybe just append
+
+ if block.rstrip().endswith(">") \
+ and self._equal_tags(left_tag, right_tag):
+ new_blocks.append(
+ self.markdown.htmlStash.store(block.strip()))
+ continue
+ else: #if not block[1] == "!":
+ # if is block level tag and is not complete
+
+ if markdown.isBlockLevel(left_tag) or left_tag == "--" \
+ and not block.rstrip().endswith(">"):
+ items.append(block.strip())
+ in_tag = True
+ else:
+ new_blocks.append(
+ self.markdown.htmlStash.store(block.strip()))
+
+ continue
+
+ new_blocks.append(block)
+
+ else:
+ items.append(block.strip())
+
+ right_tag, data_index = self._get_right_tag(left_tag, block)
+
+ if self._equal_tags(left_tag, right_tag):
+ # if find closing tag
+ in_tag = False
+ new_blocks.append(
+ self.markdown.htmlStash.store('\n\n'.join(items)))
+ items = []
+
+ if items:
+ new_blocks.append(self.markdown.htmlStash.store('\n\n'.join(items)))
+ new_blocks.append('\n')
+
+ new_text = "\n\n".join(new_blocks)
+ return new_text.split("\n")
+
+
+class ReferencePreprocessor(Preprocessor):
+ """ Remove reference definitions from text and store for later use. """
+
+ RE = re.compile(r'^(\ ?\ ?\ ?)\[([^\]]*)\]:\s*([^ ]*)(.*)$', re.DOTALL)
+
+ def run (self, lines):
+ new_text = [];
+ for line in lines:
+ m = self.RE.match(line)
+ if m:
+ id = m.group(2).strip().lower()
+ t = m.group(4).strip() # potential title
+ if not t:
+ self.markdown.references[id] = (m.group(3), t)
+ elif (len(t) >= 2
+ and (t[0] == t[-1] == "\""
+ or t[0] == t[-1] == "\'"
+ or (t[0] == "(" and t[-1] == ")") ) ):
+ self.markdown.references[id] = (m.group(3), t[1:-1])
+ else:
+ new_text.append(line)
+ else:
+ new_text.append(line)
+
+ return new_text #+ "\n"
diff --git a/tools/addon-sdk-1.7/python-lib/markdown/treeprocessors.py b/tools/addon-sdk-1.7/python-lib/markdown/treeprocessors.py
new file mode 100644
index 0000000..1dc612a
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/markdown/treeprocessors.py
@@ -0,0 +1,329 @@
+import markdown
+import re
+
+def isString(s):
+ """ Check if it's string """
+ return isinstance(s, unicode) or isinstance(s, str)
+
+class Processor:
+ def __init__(self, markdown_instance=None):
+ if markdown_instance:
+ self.markdown = markdown_instance
+
+class Treeprocessor(Processor):
+ """
+ Treeprocessors are run on the ElementTree object before serialization.
+
+ Each Treeprocessor implements a "run" method that takes a pointer to an
+ ElementTree, modifies it as necessary and returns an ElementTree
+ object.
+
+ Treeprocessors must extend markdown.Treeprocessor.
+
+ """
+ def run(self, root):
+ """
+ Subclasses of Treeprocessor should implement a `run` method, which
+ takes a root ElementTree. This method can return another ElementTree
+ object, and the existing root ElementTree will be replaced, or it can
+ modify the current tree and return None.
+ """
+ pass
+
+
+class InlineProcessor(Treeprocessor):
+ """
+ A Treeprocessor that traverses a tree, applying inline patterns.
+ """
+
+ def __init__ (self, md):
+ self.__placeholder_prefix = markdown.INLINE_PLACEHOLDER_PREFIX
+ self.__placeholder_suffix = markdown.ETX
+ self.__placeholder_length = 4 + len(self.__placeholder_prefix) \
+ + len(self.__placeholder_suffix)
+ self.__placeholder_re = re.compile(markdown.INLINE_PLACEHOLDER % r'([0-9]{4})')
+ self.markdown = md
+
+ def __makePlaceholder(self, type):
+ """ Generate a placeholder """
+ id = "%04d" % len(self.stashed_nodes)
+ hash = markdown.INLINE_PLACEHOLDER % id
+ return hash, id
+
+ def __findPlaceholder(self, data, index):
+ """
+ Extract id from data string, start from index
+
+ Keyword arguments:
+
+ * data: string
+ * index: index, from which we start search
+
+ Returns: placeholder id and string index, after the found placeholder.
+ """
+
+ m = self.__placeholder_re.search(data, index)
+ if m:
+ return m.group(1), m.end()
+ else:
+ return None, index + 1
+
+ def __stashNode(self, node, type):
+ """ Add node to stash """
+ placeholder, id = self.__makePlaceholder(type)
+ self.stashed_nodes[id] = node
+ return placeholder
+
+ def __handleInline(self, data, patternIndex=0):
+ """
+ Process string with inline patterns and replace it
+ with placeholders
+
+ Keyword arguments:
+
+ * data: A line of Markdown text
+ * patternIndex: The index of the inlinePattern to start with
+
+ Returns: String with placeholders.
+
+ """
+ if not isinstance(data, markdown.AtomicString):
+ startIndex = 0
+ while patternIndex < len(self.markdown.inlinePatterns):
+ data, matched, startIndex = self.__applyPattern(
+ self.markdown.inlinePatterns.value_for_index(patternIndex),
+ data, patternIndex, startIndex)
+ if not matched:
+ patternIndex += 1
+ return data
+
+ def __processElementText(self, node, subnode, isText=True):
+ """
+ Process placeholders in Element.text or Element.tail
+ of Elements popped from self.stashed_nodes.
+
+ Keywords arguments:
+
+ * node: parent node
+ * subnode: processing node
+ * isText: bool variable, True - it's text, False - it's tail
+
+ Returns: None
+
+ """
+ if isText:
+ text = subnode.text
+ subnode.text = None
+ else:
+ text = subnode.tail
+ subnode.tail = None
+
+ childResult = self.__processPlaceholders(text, subnode)
+
+ if not isText and node is not subnode:
+ pos = node.getchildren().index(subnode)
+ node.remove(subnode)
+ else:
+ pos = 0
+
+ childResult.reverse()
+ for newChild in childResult:
+ node.insert(pos, newChild)
+
+ def __processPlaceholders(self, data, parent):
+ """
+ Process string with placeholders and generate ElementTree tree.
+
+ Keyword arguments:
+
+ * data: string with placeholders instead of ElementTree elements.
+ * parent: Element, which contains processing inline data
+
+ Returns: list with ElementTree elements with applied inline patterns.
+ """
+ def linkText(text):
+ if text:
+ if result:
+ if result[-1].tail:
+ result[-1].tail += text
+ else:
+ result[-1].tail = text
+ else:
+ if parent.text:
+ parent.text += text
+ else:
+ parent.text = text
+
+ result = []
+ strartIndex = 0
+ while data:
+ index = data.find(self.__placeholder_prefix, strartIndex)
+ if index != -1:
+ id, phEndIndex = self.__findPlaceholder(data, index)
+
+ if id in self.stashed_nodes:
+ node = self.stashed_nodes.get(id)
+
+ if index > 0:
+ text = data[strartIndex:index]
+ linkText(text)
+
+ if not isString(node): # it's Element
+ for child in [node] + node.getchildren():
+ if child.tail:
+ if child.tail.strip():
+ self.__processElementText(node, child, False)
+ if child.text:
+ if child.text.strip():
+ self.__processElementText(child, child)
+ else: # it's just a string
+ linkText(node)
+ strartIndex = phEndIndex
+ continue
+
+ strartIndex = phEndIndex
+ result.append(node)
+
+ else: # wrong placeholder
+ end = index + len(prefix)
+ linkText(data[strartIndex:end])
+ strartIndex = end
+ else:
+ text = data[strartIndex:]
+ linkText(text)
+ data = ""
+
+ return result
+
+ def __applyPattern(self, pattern, data, patternIndex, startIndex=0):
+ """
+ Check if the line fits the pattern, create the necessary
+ elements, add it to stashed_nodes.
+
+ Keyword arguments:
+
+ * data: the text to be processed
+ * pattern: the pattern to be checked
+ * patternIndex: index of current pattern
+ * startIndex: string index, from which we starting search
+
+ Returns: String with placeholders instead of ElementTree elements.
+
+ """
+ match = pattern.getCompiledRegExp().match(data[startIndex:])
+ leftData = data[:startIndex]
+
+ if not match:
+ return data, False, 0
+
+ node = pattern.handleMatch(match)
+
+ if node is None:
+ return data, True, len(leftData) + match.span(len(match.groups()))[0]
+
+ if not isString(node):
+ if not isinstance(node.text, markdown.AtomicString):
+ # We need to process current node too
+ for child in [node] + node.getchildren():
+ if not isString(node):
+ if child.text:
+ child.text = self.__handleInline(child.text,
+ patternIndex + 1)
+ if child.tail:
+ child.tail = self.__handleInline(child.tail,
+ patternIndex)
+
+ placeholder = self.__stashNode(node, pattern.type())
+
+ return "%s%s%s%s" % (leftData,
+ match.group(1),
+ placeholder, match.groups()[-1]), True, 0
+
+ def run(self, tree):
+ """Apply inline patterns to a parsed Markdown tree.
+
+ Iterate over ElementTree, find elements with inline tag, apply inline
+ patterns and append newly created Elements to tree. If you don't
+ want process your data with inline paterns, instead of normal string,
+ use subclass AtomicString:
+
+ node.text = markdown.AtomicString("data won't be processed with inline patterns")
+
+ Arguments:
+
+ * markdownTree: ElementTree object, representing Markdown tree.
+
+ Returns: ElementTree object with applied inline patterns.
+
+ """
+ self.stashed_nodes = {}
+
+ stack = [tree]
+
+ while stack:
+ currElement = stack.pop()
+ insertQueue = []
+ for child in currElement.getchildren():
+ if child.text and not isinstance(child.text, markdown.AtomicString):
+ text = child.text
+ child.text = None
+ lst = self.__processPlaceholders(self.__handleInline(
+ text), child)
+ stack += lst
+ insertQueue.append((child, lst))
+
+ if child.getchildren():
+ stack.append(child)
+
+ for element, lst in insertQueue:
+ if element.text:
+ element.text = \
+ markdown.inlinepatterns.handleAttributes(element.text,
+ element)
+ i = 0
+ for newChild in lst:
+ # Processing attributes
+ if newChild.tail:
+ newChild.tail = \
+ markdown.inlinepatterns.handleAttributes(newChild.tail,
+ element)
+ if newChild.text:
+ newChild.text = \
+ markdown.inlinepatterns.handleAttributes(newChild.text,
+ newChild)
+ element.insert(i, newChild)
+ i += 1
+ return tree
+
+
+class PrettifyTreeprocessor(Treeprocessor):
+ """ Add linebreaks to the html document. """
+
+ def _prettifyETree(self, elem):
+ """ Recursively add linebreaks to ElementTree children. """
+
+ i = "\n"
+ if markdown.isBlockLevel(elem.tag) and elem.tag not in ['code', 'pre']:
+ if (not elem.text or not elem.text.strip()) \
+ and len(elem) and markdown.isBlockLevel(elem[0].tag):
+ elem.text = i
+ for e in elem:
+ if markdown.isBlockLevel(e.tag):
+ self._prettifyETree(e)
+ if not elem.tail or not elem.tail.strip():
+ elem.tail = i
+ if not elem.tail or not elem.tail.strip():
+ elem.tail = i
+
+ def run(self, root):
+ """ Add linebreaks to ElementTree root object. """
+
+ self._prettifyETree(root)
+ # Do <br />'s seperately as they are often in the middle of
+ # inline content and missed by _prettifyETree.
+ brs = root.getiterator('br')
+ for br in brs:
+ if not br.tail or not br.tail.strip():
+ br.tail = '\n'
+ else:
+ br.tail = '\n%s' % br.tail
diff --git a/tools/addon-sdk-1.7/python-lib/mozrunner/__init__.py b/tools/addon-sdk-1.7/python-lib/mozrunner/__init__.py
new file mode 100644
index 0000000..b88c734
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/mozrunner/__init__.py
@@ -0,0 +1,690 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import sys
+import copy
+import tempfile
+import signal
+import commands
+import zipfile
+import optparse
+import killableprocess
+import subprocess
+import platform
+import shutil
+from StringIO import StringIO
+from xml.dom import minidom
+
+from distutils import dir_util
+from time import sleep
+
+# conditional (version-dependent) imports
+try:
+ import simplejson
+except ImportError:
+ import json as simplejson
+
+import logging
+logger = logging.getLogger(__name__)
+
+# Use dir_util for copy/rm operations because shutil is all kinds of broken
+copytree = dir_util.copy_tree
+rmtree = dir_util.remove_tree
+
+def findInPath(fileName, path=os.environ['PATH']):
+ dirs = path.split(os.pathsep)
+ for dir in dirs:
+ if os.path.isfile(os.path.join(dir, fileName)):
+ return os.path.join(dir, fileName)
+ if os.name == 'nt' or sys.platform == 'cygwin':
+ if os.path.isfile(os.path.join(dir, fileName + ".exe")):
+ return os.path.join(dir, fileName + ".exe")
+ return None
+
+stdout = sys.stdout
+stderr = sys.stderr
+stdin = sys.stdin
+
+def run_command(cmd, env=None, **kwargs):
+ """Run the given command in killable process."""
+ killable_kwargs = {'stdout':stdout ,'stderr':stderr, 'stdin':stdin}
+ killable_kwargs.update(kwargs)
+
+ if sys.platform != "win32":
+ return killableprocess.Popen(cmd, preexec_fn=lambda : os.setpgid(0, 0),
+ env=env, **killable_kwargs)
+ else:
+ return killableprocess.Popen(cmd, env=env, **killable_kwargs)
+
+def getoutput(l):
+ tmp = tempfile.mktemp()
+ x = open(tmp, 'w')
+ subprocess.call(l, stdout=x, stderr=x)
+ x.close(); x = open(tmp, 'r')
+ r = x.read() ; x.close()
+ os.remove(tmp)
+ return r
+
+def get_pids(name, minimun_pid=0):
+ """Get all the pids matching name, exclude any pids below minimum_pid."""
+ if os.name == 'nt' or sys.platform == 'cygwin':
+ import wpk
+
+ pids = wpk.get_pids(name)
+
+ else:
+ data = getoutput(['ps', 'ax']).splitlines()
+ pids = [int(line.split()[0]) for line in data if line.find(name) is not -1]
+
+ matching_pids = [m for m in pids if m > minimun_pid]
+ return matching_pids
+
+def makedirs(name):
+
+ head, tail = os.path.split(name)
+ if not tail:
+ head, tail = os.path.split(head)
+ if head and tail and not os.path.exists(head):
+ try:
+ makedirs(head)
+ except OSError, e:
+ pass
+ if tail == os.curdir: # xxx/newdir/. exists if xxx/newdir exists
+ return
+ try:
+ os.mkdir(name)
+ except:
+ pass
+
+# addon_details() copied from mozprofile
+def addon_details(install_rdf_fh):
+ """
+ returns a dictionary of details about the addon
+ - addon_path : path to the addon directory
+ Returns:
+ {'id': u'rainbow@colors.org', # id of the addon
+ 'version': u'1.4', # version of the addon
+ 'name': u'Rainbow', # name of the addon
+ 'unpack': # whether to unpack the addon
+ """
+
+ details = {
+ 'id': None,
+ 'unpack': False,
+ 'name': None,
+ 'version': None
+ }
+
+ def get_namespace_id(doc, url):
+ attributes = doc.documentElement.attributes
+ namespace = ""
+ for i in range(attributes.length):
+ if attributes.item(i).value == url:
+ if ":" in attributes.item(i).name:
+ # If the namespace is not the default one remove 'xlmns:'
+ namespace = attributes.item(i).name.split(':')[1] + ":"
+ break
+ return namespace
+
+ def get_text(element):
+ """Retrieve the text value of a given node"""
+ rc = []
+ for node in element.childNodes:
+ if node.nodeType == node.TEXT_NODE:
+ rc.append(node.data)
+ return ''.join(rc).strip()
+
+ doc = minidom.parse(install_rdf_fh)
+
+ # Get the namespaces abbreviations
+ em = get_namespace_id(doc, "http://www.mozilla.org/2004/em-rdf#")
+ rdf = get_namespace_id(doc, "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
+
+ description = doc.getElementsByTagName(rdf + "Description").item(0)
+ for node in description.childNodes:
+ # Remove the namespace prefix from the tag for comparison
+ entry = node.nodeName.replace(em, "")
+ if entry in details.keys():
+ details.update({ entry: get_text(node) })
+
+ # turn unpack into a true/false value
+ if isinstance(details['unpack'], basestring):
+ details['unpack'] = details['unpack'].lower() == 'true'
+
+ return details
+
+class Profile(object):
+ """Handles all operations regarding profile. Created new profiles, installs extensions,
+ sets preferences and handles cleanup."""
+
+ def __init__(self, binary=None, profile=None, addons=None,
+ preferences=None):
+
+ self.binary = binary
+
+ self.create_new = not(bool(profile))
+ if profile:
+ self.profile = profile
+ else:
+ self.profile = self.create_new_profile(self.binary)
+
+ self.addons_installed = []
+ self.addons = addons or []
+
+ ### set preferences from class preferences
+ preferences = preferences or {}
+ if hasattr(self.__class__, 'preferences'):
+ self.preferences = self.__class__.preferences.copy()
+ else:
+ self.preferences = {}
+ self.preferences.update(preferences)
+
+ for addon in self.addons:
+ self.install_addon(addon)
+
+ self.set_preferences(self.preferences)
+
+ def create_new_profile(self, binary):
+ """Create a new clean profile in tmp which is a simple empty folder"""
+ profile = tempfile.mkdtemp(suffix='.mozrunner')
+ return profile
+
+ def unpack_addon(self, xpi_zipfile, addon_path):
+ for name in xpi_zipfile.namelist():
+ if name.endswith('/'):
+ makedirs(os.path.join(addon_path, name))
+ else:
+ if not os.path.isdir(os.path.dirname(os.path.join(addon_path, name))):
+ makedirs(os.path.dirname(os.path.join(addon_path, name)))
+ data = xpi_zipfile.read(name)
+ f = open(os.path.join(addon_path, name), 'wb')
+ f.write(data) ; f.close()
+ zi = xpi_zipfile.getinfo(name)
+ os.chmod(os.path.join(addon_path,name), (zi.external_attr>>16))
+
+ def install_addon(self, path):
+ """Installs the given addon or directory of addons in the profile."""
+
+ extensions_path = os.path.join(self.profile, 'extensions')
+ if not os.path.exists(extensions_path):
+ os.makedirs(extensions_path)
+
+ addons = [path]
+ if not path.endswith('.xpi') and not os.path.exists(os.path.join(path, 'install.rdf')):
+ addons = [os.path.join(path, x) for x in os.listdir(path)]
+
+ for addon in addons:
+ if addon.endswith('.xpi'):
+ xpi_zipfile = zipfile.ZipFile(addon, "r")
+ details = addon_details(StringIO(xpi_zipfile.read('install.rdf')))
+ addon_path = os.path.join(extensions_path, details["id"])
+ if details.get("unpack", True):
+ self.unpack_addon(xpi_zipfile, addon_path)
+ self.addons_installed.append(addon_path)
+ else:
+ shutil.copy(addon, addon_path + '.xpi')
+ else:
+ # it's already unpacked, but we need to extract the id so we
+ # can copy it
+ details = addon_details(open(os.path.join(addon, "install.rdf"), "rb"))
+ addon_path = os.path.join(extensions_path, details["id"])
+ shutil.copytree(addon, addon_path, symlinks=True)
+
+ def set_preferences(self, preferences):
+ """Adds preferences dict to profile preferences"""
+ prefs_file = os.path.join(self.profile, 'user.js')
+ # Ensure that the file exists first otherwise create an empty file
+ if os.path.isfile(prefs_file):
+ f = open(prefs_file, 'a+')
+ else:
+ f = open(prefs_file, 'w')
+
+ f.write('\n#MozRunner Prefs Start\n')
+
+ pref_lines = ['user_pref(%s, %s);' %
+ (simplejson.dumps(k), simplejson.dumps(v) ) for k, v in
+ preferences.items()]
+ for line in pref_lines:
+ f.write(line+'\n')
+ f.write('#MozRunner Prefs End\n')
+ f.flush() ; f.close()
+
+ def pop_preferences(self):
+ """
+ pop the last set of preferences added
+ returns True if popped
+ """
+
+ # our magic markers
+ delimeters = ('#MozRunner Prefs Start', '#MozRunner Prefs End')
+
+ lines = file(os.path.join(self.profile, 'user.js')).read().splitlines()
+ def last_index(_list, value):
+ """
+ returns the last index of an item;
+ this should actually be part of python code but it isn't
+ """
+ for index in reversed(range(len(_list))):
+ if _list[index] == value:
+ return index
+ s = last_index(lines, delimeters[0])
+ e = last_index(lines, delimeters[1])
+
+ # ensure both markers are found
+ if s is None:
+ assert e is None, '%s found without %s' % (delimeters[1], delimeters[0])
+ return False # no preferences found
+ elif e is None:
+ assert e is None, '%s found without %s' % (delimeters[0], delimeters[1])
+
+ # ensure the markers are in the proper order
+ assert e > s, '%s found at %s, while %s found at %s' (delimeter[1], e, delimeter[0], s)
+
+ # write the prefs
+ cleaned_prefs = '\n'.join(lines[:s] + lines[e+1:])
+ f = file(os.path.join(self.profile, 'user.js'), 'w')
+ f.write(cleaned_prefs)
+ f.close()
+ return True
+
+ def clean_preferences(self):
+ """Removed preferences added by mozrunner."""
+ while True:
+ if not self.pop_preferences():
+ break
+
+ def clean_addons(self):
+ """Cleans up addons in the profile."""
+ for addon in self.addons_installed:
+ if os.path.isdir(addon):
+ rmtree(addon)
+
+ def cleanup(self):
+ """Cleanup operations on the profile."""
+ def oncleanup_error(function, path, excinfo):
+ #TODO: How should we handle this?
+ print "Error Cleaning up: " + str(excinfo[1])
+ if self.create_new:
+ shutil.rmtree(self.profile, False, oncleanup_error)
+ else:
+ self.clean_preferences()
+ self.clean_addons()
+
+class FirefoxProfile(Profile):
+ """Specialized Profile subclass for Firefox"""
+ preferences = {# Don't automatically update the application
+ 'app.update.enabled' : False,
+ # Don't restore the last open set of tabs if the browser has crashed
+ 'browser.sessionstore.resume_from_crash': False,
+ # Don't check for the default web browser
+ 'browser.shell.checkDefaultBrowser' : False,
+ # Don't warn on exit when multiple tabs are open
+ 'browser.tabs.warnOnClose' : False,
+ # Don't warn when exiting the browser
+ 'browser.warnOnQuit': False,
+ # Only install add-ons from the profile and the app folder
+ 'extensions.enabledScopes' : 5,
+ # Don't automatically update add-ons
+ 'extensions.update.enabled' : False,
+ # Don't open a dialog to show available add-on updates
+ 'extensions.update.notifyUser' : False,
+ }
+
+ # The possible names of application bundles on Mac OS X, in order of
+ # preference from most to least preferred.
+ # Note: Nightly is obsolete, as it has been renamed to FirefoxNightly,
+ # but it will still be present if users update an older nightly build
+ # via the app update service.
+ bundle_names = ['Firefox', 'FirefoxNightly', 'Nightly']
+
+ # The possible names of binaries, in order of preference from most to least
+ # preferred.
+ @property
+ def names(self):
+ if sys.platform == 'darwin':
+ return ['firefox', 'nightly', 'shiretoko']
+ if (sys.platform == 'linux2') or (sys.platform in ('sunos5', 'solaris')):
+ return ['firefox', 'mozilla-firefox', 'iceweasel']
+ if os.name == 'nt' or sys.platform == 'cygwin':
+ return ['firefox']
+
+class ThunderbirdProfile(Profile):
+ preferences = {'extensions.update.enabled' : False,
+ 'extensions.update.notifyUser' : False,
+ 'browser.shell.checkDefaultBrowser' : False,
+ 'browser.tabs.warnOnClose' : False,
+ 'browser.warnOnQuit': False,
+ 'browser.sessionstore.resume_from_crash': False,
+ }
+
+ # The possible names of application bundles on Mac OS X, in order of
+ # preference from most to least preferred.
+ bundle_names = ["Thunderbird", "Shredder"]
+
+ # The possible names of binaries, in order of preference from most to least
+ # preferred.
+ names = ["thunderbird", "shredder"]
+
+
+class Runner(object):
+ """Handles all running operations. Finds bins, runs and kills the process."""
+
+ def __init__(self, binary=None, profile=None, cmdargs=[], env=None,
+ kp_kwargs={}):
+ if binary is None:
+ self.binary = self.find_binary()
+ elif sys.platform == 'darwin' and binary.find('Contents/MacOS/') == -1:
+ self.binary = os.path.join(binary, 'Contents/MacOS/%s-bin' % self.names[0])
+ else:
+ self.binary = binary
+
+ if not os.path.exists(self.binary):
+ raise Exception("Binary path does not exist "+self.binary)
+
+ if sys.platform == 'linux2' and self.binary.endswith('-bin'):
+ dirname = os.path.dirname(self.binary)
+ if os.environ.get('LD_LIBRARY_PATH', None):
+ os.environ['LD_LIBRARY_PATH'] = '%s:%s' % (os.environ['LD_LIBRARY_PATH'], dirname)
+ else:
+ os.environ['LD_LIBRARY_PATH'] = dirname
+
+ # Disable the crash reporter by default
+ os.environ['MOZ_CRASHREPORTER_NO_REPORT'] = '1'
+
+ self.profile = profile
+
+ self.cmdargs = cmdargs
+ if env is None:
+ self.env = copy.copy(os.environ)
+ self.env.update({'MOZ_NO_REMOTE':"1",})
+ else:
+ self.env = env
+ self.kp_kwargs = kp_kwargs or {}
+
+ def find_binary(self):
+ """Finds the binary for self.names if one was not provided."""
+ binary = None
+ if sys.platform in ('linux2', 'sunos5', 'solaris'):
+ for name in reversed(self.names):
+ binary = findInPath(name)
+ elif os.name == 'nt' or sys.platform == 'cygwin':
+
+ # find the default executable from the windows registry
+ try:
+ import _winreg
+ except ImportError:
+ pass
+ else:
+ sam_flags = [0]
+ # KEY_WOW64_32KEY etc only appeared in 2.6+, but that's OK as
+ # only 2.6+ has functioning 64bit builds.
+ if hasattr(_winreg, "KEY_WOW64_32KEY"):
+ if "64 bit" in sys.version:
+ # a 64bit Python should also look in the 32bit registry
+ sam_flags.append(_winreg.KEY_WOW64_32KEY)
+ else:
+ # possibly a 32bit Python on 64bit Windows, so look in
+ # the 64bit registry incase there is a 64bit app.
+ sam_flags.append(_winreg.KEY_WOW64_64KEY)
+ for sam_flag in sam_flags:
+ try:
+ # assumes self.app_name is defined, as it should be for
+ # implementors
+ keyname = r"Software\Mozilla\Mozilla %s" % self.app_name
+ sam = _winreg.KEY_READ | sam_flag
+ app_key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, keyname, 0, sam)
+ version, _type = _winreg.QueryValueEx(app_key, "CurrentVersion")
+ version_key = _winreg.OpenKey(app_key, version + r"\Main")
+ path, _ = _winreg.QueryValueEx(version_key, "PathToExe")
+ return path
+ except _winreg.error:
+ pass
+
+ # search for the binary in the path
+ for name in reversed(self.names):
+ binary = findInPath(name)
+ if sys.platform == 'cygwin':
+ program_files = os.environ['PROGRAMFILES']
+ else:
+ program_files = os.environ['ProgramFiles']
+
+ if binary is None:
+ for bin in [(program_files, 'Mozilla Firefox', 'firefox.exe'),
+ (os.environ.get("ProgramFiles(x86)"),'Mozilla Firefox', 'firefox.exe'),
+ (program_files,'Nightly', 'firefox.exe'),
+ (os.environ.get("ProgramFiles(x86)"),'Nightly', 'firefox.exe')
+ ]:
+ path = os.path.join(*bin)
+ if os.path.isfile(path):
+ binary = path
+ break
+ elif sys.platform == 'darwin':
+ for bundle_name in self.bundle_names:
+ # Look for the application bundle in the user's home directory
+ # or the system-wide /Applications directory. If we don't find
+ # it in one of those locations, we move on to the next possible
+ # bundle name.
+ appdir = os.path.join("~/Applications/%s.app" % bundle_name)
+ if not os.path.isdir(appdir):
+ appdir = "/Applications/%s.app" % bundle_name
+ if not os.path.isdir(appdir):
+ continue
+
+ # Look for a binary with any of the possible binary names
+ # inside the application bundle.
+ for binname in self.names:
+ binpath = os.path.join(appdir,
+ "Contents/MacOS/%s-bin" % binname)
+ if (os.path.isfile(binpath)):
+ binary = binpath
+ break
+
+ if binary:
+ break
+
+ if binary is None:
+ raise Exception('Mozrunner could not locate your binary, you will need to set it.')
+ return binary
+
+ @property
+ def command(self):
+ """Returns the command list to run."""
+ cmd = [self.binary, '-profile', self.profile.profile]
+ # On i386 OS X machines, i386+x86_64 universal binaries need to be told
+ # to run as i386 binaries. If we're not running a i386+x86_64 universal
+ # binary, then this command modification is harmless.
+ if sys.platform == 'darwin':
+ if hasattr(platform, 'architecture') and platform.architecture()[0] == '32bit':
+ cmd = ['arch', '-i386'] + cmd
+ return cmd
+
+ def get_repositoryInfo(self):
+ """Read repository information from application.ini and platform.ini."""
+ import ConfigParser
+
+ config = ConfigParser.RawConfigParser()
+ dirname = os.path.dirname(self.binary)
+ repository = { }
+
+ for entry in [['application', 'App'], ['platform', 'Build']]:
+ (file, section) = entry
+ config.read(os.path.join(dirname, '%s.ini' % file))
+
+ for entry in [['SourceRepository', 'repository'], ['SourceStamp', 'changeset']]:
+ (key, id) = entry
+
+ try:
+ repository['%s_%s' % (file, id)] = config.get(section, key);
+ except:
+ repository['%s_%s' % (file, id)] = None
+
+ return repository
+
+ def start(self):
+ """Run self.command in the proper environment."""
+ if self.profile is None:
+ self.profile = self.profile_class()
+ self.process_handler = run_command(self.command+self.cmdargs, self.env, **self.kp_kwargs)
+
+ def wait(self, timeout=None):
+ """Wait for the browser to exit."""
+ self.process_handler.wait(timeout=timeout)
+
+ if sys.platform != 'win32':
+ for name in self.names:
+ for pid in get_pids(name, self.process_handler.pid):
+ self.process_handler.pid = pid
+ self.process_handler.wait(timeout=timeout)
+
+ def kill(self, kill_signal=signal.SIGTERM):
+ """Kill the browser"""
+ if sys.platform != 'win32':
+ self.process_handler.kill()
+ for name in self.names:
+ for pid in get_pids(name, self.process_handler.pid):
+ self.process_handler.pid = pid
+ self.process_handler.kill()
+ else:
+ try:
+ self.process_handler.kill(group=True)
+ # On windows, it sometimes behooves one to wait for dust to settle
+ # after killing processes. Let's try that.
+ # TODO: Bug 640047 is invesitgating the correct way to handle this case
+ self.process_handler.wait(timeout=10)
+ except Exception, e:
+ logger.error('Cannot kill process, '+type(e).__name__+' '+e.message)
+
+ def stop(self):
+ self.kill()
+
+class FirefoxRunner(Runner):
+ """Specialized Runner subclass for running Firefox."""
+
+ app_name = 'Firefox'
+ profile_class = FirefoxProfile
+
+ # The possible names of application bundles on Mac OS X, in order of
+ # preference from most to least preferred.
+ # Note: Nightly is obsolete, as it has been renamed to FirefoxNightly,
+ # but it will still be present if users update an older nightly build
+ # only via the app update service.
+ bundle_names = ['Firefox', 'FirefoxNightly', 'Nightly']
+
+ @property
+ def names(self):
+ if sys.platform == 'darwin':
+ return ['firefox', 'nightly', 'shiretoko']
+ if (sys.platform == 'linux2') or (sys.platform in ('sunos5', 'solaris')):
+ return ['firefox', 'mozilla-firefox', 'iceweasel']
+ if os.name == 'nt' or sys.platform == 'cygwin':
+ return ['firefox']
+
+class ThunderbirdRunner(Runner):
+ """Specialized Runner subclass for running Thunderbird"""
+
+ app_name = 'Thunderbird'
+ profile_class = ThunderbirdProfile
+
+ # The possible names of application bundles on Mac OS X, in order of
+ # preference from most to least preferred.
+ bundle_names = ["Thunderbird", "Shredder"]
+
+ # The possible names of binaries, in order of preference from most to least
+ # preferred.
+ names = ["thunderbird", "shredder"]
+
+class CLI(object):
+ """Command line interface."""
+
+ runner_class = FirefoxRunner
+ profile_class = FirefoxProfile
+ module = "mozrunner"
+
+ parser_options = {("-b", "--binary",): dict(dest="binary", help="Binary path.",
+ metavar=None, default=None),
+ ('-p', "--profile",): dict(dest="profile", help="Profile path.",
+ metavar=None, default=None),
+ ('-a', "--addons",): dict(dest="addons",
+ help="Addons paths to install.",
+ metavar=None, default=None),
+ ("--info",): dict(dest="info", default=False,
+ action="store_true",
+ help="Print module information")
+ }
+
+ def __init__(self):
+ """ Setup command line parser and parse arguments """
+ self.metadata = self.get_metadata_from_egg()
+ self.parser = optparse.OptionParser(version="%prog " + self.metadata["Version"])
+ for names, opts in self.parser_options.items():
+ self.parser.add_option(*names, **opts)
+ (self.options, self.args) = self.parser.parse_args()
+
+ if self.options.info:
+ self.print_metadata()
+ sys.exit(0)
+
+ # XXX should use action='append' instead of rolling our own
+ try:
+ self.addons = self.options.addons.split(',')
+ except:
+ self.addons = []
+
+ def get_metadata_from_egg(self):
+ import pkg_resources
+ ret = {}
+ dist = pkg_resources.get_distribution(self.module)
+ if dist.has_metadata("PKG-INFO"):
+ for line in dist.get_metadata_lines("PKG-INFO"):
+ key, value = line.split(':', 1)
+ ret[key] = value
+ if dist.has_metadata("requires.txt"):
+ ret["Dependencies"] = "\n" + dist.get_metadata("requires.txt")
+ return ret
+
+ def print_metadata(self, data=("Name", "Version", "Summary", "Home-page",
+ "Author", "Author-email", "License", "Platform", "Dependencies")):
+ for key in data:
+ if key in self.metadata:
+ print key + ": " + self.metadata[key]
+
+ def create_runner(self):
+ """ Get the runner object """
+ runner = self.get_runner(binary=self.options.binary)
+ profile = self.get_profile(binary=runner.binary,
+ profile=self.options.profile,
+ addons=self.addons)
+ runner.profile = profile
+ return runner
+
+ def get_runner(self, binary=None, profile=None):
+ """Returns the runner instance for the given command line binary argument
+ the profile instance returned from self.get_profile()."""
+ return self.runner_class(binary, profile)
+
+ def get_profile(self, binary=None, profile=None, addons=None, preferences=None):
+ """Returns the profile instance for the given command line arguments."""
+ addons = addons or []
+ preferences = preferences or {}
+ return self.profile_class(binary, profile, addons, preferences)
+
+ def run(self):
+ runner = self.create_runner()
+ self.start(runner)
+ runner.profile.cleanup()
+
+ def start(self, runner):
+ """Starts the runner and waits for Firefox to exitor Keyboard Interrupt.
+ Shoule be overwritten to provide custom running of the runner instance."""
+ runner.start()
+ print 'Started:', ' '.join(runner.command)
+ try:
+ runner.wait()
+ except KeyboardInterrupt:
+ runner.stop()
+
+
+def cli():
+ CLI().run()
diff --git a/tools/addon-sdk-1.7/python-lib/mozrunner/killableprocess.py b/tools/addon-sdk-1.7/python-lib/mozrunner/killableprocess.py
new file mode 100644
index 0000000..892ed87
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/mozrunner/killableprocess.py
@@ -0,0 +1,316 @@
+# killableprocess - subprocesses which can be reliably killed
+#
+# Parts of this module are copied from the subprocess.py file contained
+# in the Python distribution.
+#
+# Copyright (c) 2003-2004 by Peter Astrand <astrand@lysator.liu.se>
+#
+# Additions and modifications written by Benjamin Smedberg
+# <benjamin@smedbergs.us> are Copyright (c) 2006 by the Mozilla Foundation
+# <http://www.mozilla.org/>
+#
+# More Modifications
+# Copyright (c) 2006-2007 by Mike Taylor <bear@code-bear.com>
+# Copyright (c) 2007-2008 by Mikeal Rogers <mikeal@mozilla.com>
+#
+# By obtaining, using, and/or copying this software and/or its
+# associated documentation, you agree that you have read, understood,
+# and will comply with the following terms and conditions:
+#
+# Permission to use, copy, modify, and distribute this software and
+# its associated documentation for any purpose and without fee is
+# hereby granted, provided that the above copyright notice appears in
+# all copies, and that both that copyright notice and this permission
+# notice appear in supporting documentation, and that the name of the
+# author not be used in advertising or publicity pertaining to
+# distribution of the software without specific, written prior
+# permission.
+#
+# THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+"""killableprocess - Subprocesses which can be reliably killed
+
+This module is a subclass of the builtin "subprocess" module. It allows
+processes that launch subprocesses to be reliably killed on Windows (via the Popen.kill() method.
+
+It also adds a timeout argument to Wait() for a limited period of time before
+forcefully killing the process.
+
+Note: On Windows, this module requires Windows 2000 or higher (no support for
+Windows 95, 98, or NT 4.0). It also requires ctypes, which is bundled with
+Python 2.5+ or available from http://python.net/crew/theller/ctypes/
+"""
+
+import subprocess
+import sys
+import os
+import time
+import datetime
+import types
+import exceptions
+
+try:
+ from subprocess import CalledProcessError
+except ImportError:
+ # Python 2.4 doesn't implement CalledProcessError
+ class CalledProcessError(Exception):
+ """This exception is raised when a process run by check_call() returns
+ a non-zero exit status. The exit status will be stored in the
+ returncode attribute."""
+ def __init__(self, returncode, cmd):
+ self.returncode = returncode
+ self.cmd = cmd
+ def __str__(self):
+ return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode)
+
+mswindows = (sys.platform == "win32")
+
+if mswindows:
+ import winprocess
+else:
+ import signal
+
+# This is normally defined in win32con, but we don't want
+# to incur the huge tree of dependencies (pywin32 and friends)
+# just to get one constant. So here's our hack
+STILL_ACTIVE = 259
+
+def call(*args, **kwargs):
+ waitargs = {}
+ if "timeout" in kwargs:
+ waitargs["timeout"] = kwargs.pop("timeout")
+
+ return Popen(*args, **kwargs).wait(**waitargs)
+
+def check_call(*args, **kwargs):
+ """Call a program with an optional timeout. If the program has a non-zero
+ exit status, raises a CalledProcessError."""
+
+ retcode = call(*args, **kwargs)
+ if retcode:
+ cmd = kwargs.get("args")
+ if cmd is None:
+ cmd = args[0]
+ raise CalledProcessError(retcode, cmd)
+
+if not mswindows:
+ def DoNothing(*args):
+ pass
+
+class Popen(subprocess.Popen):
+ kill_called = False
+ if mswindows:
+ def _execute_child(self, args, executable, preexec_fn, close_fds,
+ cwd, env, universal_newlines, startupinfo,
+ creationflags, shell,
+ p2cread, p2cwrite,
+ c2pread, c2pwrite,
+ errread, errwrite):
+ if not isinstance(args, types.StringTypes):
+ args = subprocess.list2cmdline(args)
+
+ # Always or in the create new process group
+ creationflags |= winprocess.CREATE_NEW_PROCESS_GROUP
+
+ if startupinfo is None:
+ startupinfo = winprocess.STARTUPINFO()
+
+ if None not in (p2cread, c2pwrite, errwrite):
+ startupinfo.dwFlags |= winprocess.STARTF_USESTDHANDLES
+
+ startupinfo.hStdInput = int(p2cread)
+ startupinfo.hStdOutput = int(c2pwrite)
+ startupinfo.hStdError = int(errwrite)
+ if shell:
+ startupinfo.dwFlags |= winprocess.STARTF_USESHOWWINDOW
+ startupinfo.wShowWindow = winprocess.SW_HIDE
+ comspec = os.environ.get("COMSPEC", "cmd.exe")
+ args = comspec + " /c " + args
+
+ # determine if we can create create a job
+ canCreateJob = winprocess.CanCreateJobObject()
+
+ # set process creation flags
+ creationflags |= winprocess.CREATE_SUSPENDED
+ creationflags |= winprocess.CREATE_UNICODE_ENVIRONMENT
+ if canCreateJob:
+ # Uncomment this line below to discover very useful things about your environment
+ #print "++++ killableprocess: releng twistd patch not applied, we can create job objects"
+ creationflags |= winprocess.CREATE_BREAKAWAY_FROM_JOB
+
+ # create the process
+ hp, ht, pid, tid = winprocess.CreateProcess(
+ executable, args,
+ None, None, # No special security
+ 1, # Must inherit handles!
+ creationflags,
+ winprocess.EnvironmentBlock(env),
+ cwd, startupinfo)
+ self._child_created = True
+ self._handle = hp
+ self._thread = ht
+ self.pid = pid
+ self.tid = tid
+
+ if canCreateJob:
+ # We create a new job for this process, so that we can kill
+ # the process and any sub-processes
+ self._job = winprocess.CreateJobObject()
+ winprocess.AssignProcessToJobObject(self._job, int(hp))
+ else:
+ self._job = None
+
+ winprocess.ResumeThread(int(ht))
+ ht.Close()
+
+ if p2cread is not None:
+ p2cread.Close()
+ if c2pwrite is not None:
+ c2pwrite.Close()
+ if errwrite is not None:
+ errwrite.Close()
+ time.sleep(.1)
+
+ def kill(self, group=True):
+ """Kill the process. If group=True, all sub-processes will also be killed."""
+ self.kill_called = True
+
+ if mswindows:
+ if group and self._job:
+ winprocess.TerminateJobObject(self._job, 127)
+ else:
+ winprocess.TerminateProcess(self._handle, 127)
+ self.returncode = 127
+ else:
+ if group:
+ try:
+ os.killpg(self.pid, signal.SIGKILL)
+ except: pass
+ else:
+ os.kill(self.pid, signal.SIGKILL)
+ self.returncode = -9
+
+ def wait(self, timeout=None, group=True):
+ """Wait for the process to terminate. Returns returncode attribute.
+ If timeout seconds are reached and the process has not terminated,
+ it will be forcefully killed. If timeout is -1, wait will not
+ time out."""
+ if timeout is not None:
+ # timeout is now in milliseconds
+ timeout = timeout * 1000
+
+ starttime = datetime.datetime.now()
+
+ if mswindows:
+ if timeout is None:
+ timeout = -1
+ rc = winprocess.WaitForSingleObject(self._handle, timeout)
+
+ if (rc == winprocess.WAIT_OBJECT_0 or
+ rc == winprocess.WAIT_ABANDONED or
+ rc == winprocess.WAIT_FAILED):
+ # Object has either signaled, or the API call has failed. In
+ # both cases we want to give the OS the benefit of the doubt
+ # and supply a little time before we start shooting processes
+ # with an M-16.
+
+ # Returns 1 if running, 0 if not, -1 if timed out
+ def check():
+ now = datetime.datetime.now()
+ diff = now - starttime
+ if (diff.seconds * 1000 * 1000 + diff.microseconds) < (timeout * 1000):
+ if self._job:
+ if (winprocess.QueryInformationJobObject(self._job, 8)['BasicInfo']['ActiveProcesses'] > 0):
+ # Job Object is still containing active processes
+ return 1
+ else:
+ # No job, we use GetExitCodeProcess, which will tell us if the process is still active
+ self.returncode = winprocess.GetExitCodeProcess(self._handle)
+ if (self.returncode == STILL_ACTIVE):
+ # Process still active, continue waiting
+ return 1
+ # Process not active, return 0
+ return 0
+ else:
+ # Timed out, return -1
+ return -1
+
+ notdone = check()
+ while notdone == 1:
+ time.sleep(.5)
+ notdone = check()
+
+ if notdone == -1:
+ # Then check timed out, we have a hung process, attempt
+ # last ditch kill with explosives
+ self.kill(group)
+
+ else:
+ # In this case waitforsingleobject timed out. We have to
+ # take the process behind the woodshed and shoot it.
+ self.kill(group)
+
+ else:
+ if (sys.platform == 'linux2') or (sys.platform in ('sunos5', 'solaris')):
+ def group_wait(timeout):
+ try:
+ os.waitpid(self.pid, 0)
+ except OSError, e:
+ pass # If wait has already been called on this pid, bad things happen
+ return self.returncode
+ elif sys.platform == 'darwin':
+ def group_wait(timeout):
+ try:
+ count = 0
+ if timeout is None and self.kill_called:
+ timeout = 10 # Have to set some kind of timeout or else this could go on forever
+ if timeout is None:
+ while 1:
+ os.killpg(self.pid, signal.SIG_DFL)
+ while ((count * 2) <= timeout):
+ os.killpg(self.pid, signal.SIG_DFL)
+ # count is increased by 500ms for every 0.5s of sleep
+ time.sleep(.5); count += 500
+ except exceptions.OSError:
+ return self.returncode
+
+ if timeout is None:
+ if group is True:
+ return group_wait(timeout)
+ else:
+ subprocess.Popen.wait(self)
+ return self.returncode
+
+ returncode = False
+
+ now = datetime.datetime.now()
+ diff = now - starttime
+ while (diff.seconds * 1000 * 1000 + diff.microseconds) < (timeout * 1000) and ( returncode is False ):
+ if group is True:
+ return group_wait(timeout)
+ else:
+ if subprocess.poll() is not None:
+ returncode = self.returncode
+ time.sleep(.5)
+ now = datetime.datetime.now()
+ diff = now - starttime
+ return self.returncode
+
+ return self.returncode
+ # We get random maxint errors from subprocesses __del__
+ __del__ = lambda self: None
+
+def setpgid_preexec_fn():
+ os.setpgid(0, 0)
+
+def runCommand(cmd, **kwargs):
+ if sys.platform != "win32":
+ return Popen(cmd, preexec_fn=setpgid_preexec_fn, **kwargs)
+ else:
+ return Popen(cmd, **kwargs)
diff --git a/tools/addon-sdk-1.7/python-lib/mozrunner/qijo.py b/tools/addon-sdk-1.7/python-lib/mozrunner/qijo.py
new file mode 100644
index 0000000..0580557
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/mozrunner/qijo.py
@@ -0,0 +1,166 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from ctypes import c_void_p, POINTER, sizeof, Structure, windll, WinError, WINFUNCTYPE, addressof, c_size_t, c_ulong
+from ctypes.wintypes import BOOL, BYTE, DWORD, HANDLE, LARGE_INTEGER
+
+LPVOID = c_void_p
+LPDWORD = POINTER(DWORD)
+SIZE_T = c_size_t
+ULONG_PTR = POINTER(c_ulong)
+
+# A ULONGLONG is a 64-bit unsigned integer.
+# Thus there are 8 bytes in a ULONGLONG.
+# XXX why not import c_ulonglong ?
+ULONGLONG = BYTE * 8
+
+class IO_COUNTERS(Structure):
+ # The IO_COUNTERS struct is 6 ULONGLONGs.
+ # TODO: Replace with non-dummy fields.
+ _fields_ = [('dummy', ULONGLONG * 6)]
+
+class JOBOBJECT_BASIC_ACCOUNTING_INFORMATION(Structure):
+ _fields_ = [('TotalUserTime', LARGE_INTEGER),
+ ('TotalKernelTime', LARGE_INTEGER),
+ ('ThisPeriodTotalUserTime', LARGE_INTEGER),
+ ('ThisPeriodTotalKernelTime', LARGE_INTEGER),
+ ('TotalPageFaultCount', DWORD),
+ ('TotalProcesses', DWORD),
+ ('ActiveProcesses', DWORD),
+ ('TotalTerminatedProcesses', DWORD)]
+
+class JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION(Structure):
+ _fields_ = [('BasicInfo', JOBOBJECT_BASIC_ACCOUNTING_INFORMATION),
+ ('IoInfo', IO_COUNTERS)]
+
+# see http://msdn.microsoft.com/en-us/library/ms684147%28VS.85%29.aspx
+class JOBOBJECT_BASIC_LIMIT_INFORMATION(Structure):
+ _fields_ = [('PerProcessUserTimeLimit', LARGE_INTEGER),
+ ('PerJobUserTimeLimit', LARGE_INTEGER),
+ ('LimitFlags', DWORD),
+ ('MinimumWorkingSetSize', SIZE_T),
+ ('MaximumWorkingSetSize', SIZE_T),
+ ('ActiveProcessLimit', DWORD),
+ ('Affinity', ULONG_PTR),
+ ('PriorityClass', DWORD),
+ ('SchedulingClass', DWORD)
+ ]
+
+# see http://msdn.microsoft.com/en-us/library/ms684156%28VS.85%29.aspx
+class JOBOBJECT_EXTENDED_LIMIT_INFORMATION(Structure):
+ _fields_ = [('BasicLimitInformation', JOBOBJECT_BASIC_LIMIT_INFORMATION),
+ ('IoInfo', IO_COUNTERS),
+ ('ProcessMemoryLimit', SIZE_T),
+ ('JobMemoryLimit', SIZE_T),
+ ('PeakProcessMemoryUsed', SIZE_T),
+ ('PeakJobMemoryUsed', SIZE_T)]
+
+# XXX Magical numbers like 8 should be documented
+JobObjectBasicAndIoAccountingInformation = 8
+
+# ...like magical number 9 comes from
+# http://community.flexerasoftware.com/archive/index.php?t-181670.html
+# I wish I had a more canonical source
+JobObjectExtendedLimitInformation = 9
+
+class JobObjectInfo(object):
+ mapping = { 'JobObjectBasicAndIoAccountingInformation': 8,
+ 'JobObjectExtendedLimitInformation': 9
+ }
+ structures = { 8: JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION,
+ 9: JOBOBJECT_EXTENDED_LIMIT_INFORMATION
+ }
+ def __init__(self, _class):
+ if isinstance(_class, basestring):
+ assert _class in self.mapping, 'Class should be one of %s; you gave %s' % (self.mapping, _class)
+ _class = self.mapping[_class]
+ assert _class in self.structures, 'Class should be one of %s; you gave %s' % (self.structures, _class)
+ self.code = _class
+ self.info = self.structures[_class]()
+
+
+QueryInformationJobObjectProto = WINFUNCTYPE(
+ BOOL, # Return type
+ HANDLE, # hJob
+ DWORD, # JobObjectInfoClass
+ LPVOID, # lpJobObjectInfo
+ DWORD, # cbJobObjectInfoLength
+ LPDWORD # lpReturnLength
+ )
+
+QueryInformationJobObjectFlags = (
+ (1, 'hJob'),
+ (1, 'JobObjectInfoClass'),
+ (1, 'lpJobObjectInfo'),
+ (1, 'cbJobObjectInfoLength'),
+ (1, 'lpReturnLength', None)
+ )
+
+_QueryInformationJobObject = QueryInformationJobObjectProto(
+ ('QueryInformationJobObject', windll.kernel32),
+ QueryInformationJobObjectFlags
+ )
+
+class SubscriptableReadOnlyStruct(object):
+ def __init__(self, struct):
+ self._struct = struct
+
+ def _delegate(self, name):
+ result = getattr(self._struct, name)
+ if isinstance(result, Structure):
+ return SubscriptableReadOnlyStruct(result)
+ return result
+
+ def __getitem__(self, name):
+ match = [fname for fname, ftype in self._struct._fields_
+ if fname == name]
+ if match:
+ return self._delegate(name)
+ raise KeyError(name)
+
+ def __getattr__(self, name):
+ return self._delegate(name)
+
+def QueryInformationJobObject(hJob, JobObjectInfoClass):
+ jobinfo = JobObjectInfo(JobObjectInfoClass)
+ result = _QueryInformationJobObject(
+ hJob=hJob,
+ JobObjectInfoClass=jobinfo.code,
+ lpJobObjectInfo=addressof(jobinfo.info),
+ cbJobObjectInfoLength=sizeof(jobinfo.info)
+ )
+ if not result:
+ raise WinError()
+ return SubscriptableReadOnlyStruct(jobinfo.info)
+
+def test_qijo():
+ from killableprocess import Popen
+
+ popen = Popen('c:\\windows\\notepad.exe')
+
+ try:
+ result = QueryInformationJobObject(0, 8)
+ raise AssertionError('throw should occur')
+ except WindowsError, e:
+ pass
+
+ try:
+ result = QueryInformationJobObject(0, 1)
+ raise AssertionError('throw should occur')
+ except NotImplementedError, e:
+ pass
+
+ result = QueryInformationJobObject(popen._job, 8)
+ if result['BasicInfo']['ActiveProcesses'] != 1:
+ raise AssertionError('expected ActiveProcesses to be 1')
+ popen.kill()
+
+ result = QueryInformationJobObject(popen._job, 8)
+ if result.BasicInfo.ActiveProcesses != 0:
+ raise AssertionError('expected ActiveProcesses to be 0')
+
+if __name__ == '__main__':
+ print "testing."
+ test_qijo()
+ print "success!"
diff --git a/tools/addon-sdk-1.7/python-lib/mozrunner/winprocess.py b/tools/addon-sdk-1.7/python-lib/mozrunner/winprocess.py
new file mode 100644
index 0000000..4bea3fc
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/mozrunner/winprocess.py
@@ -0,0 +1,383 @@
+# A module to expose various thread/process/job related structures and
+# methods from kernel32
+#
+# The MIT License
+#
+# Copyright (c) 2003-2004 by Peter Astrand <astrand@lysator.liu.se>
+#
+# Additions and modifications written by Benjamin Smedberg
+# <benjamin@smedbergs.us> are Copyright (c) 2006 by the Mozilla Foundation
+# <http://www.mozilla.org/>
+#
+# More Modifications
+# Copyright (c) 2006-2007 by Mike Taylor <bear@code-bear.com>
+# Copyright (c) 2007-2008 by Mikeal Rogers <mikeal@mozilla.com>
+#
+# By obtaining, using, and/or copying this software and/or its
+# associated documentation, you agree that you have read, understood,
+# and will comply with the following terms and conditions:
+#
+# Permission to use, copy, modify, and distribute this software and
+# its associated documentation for any purpose and without fee is
+# hereby granted, provided that the above copyright notice appears in
+# all copies, and that both that copyright notice and this permission
+# notice appear in supporting documentation, and that the name of the
+# author not be used in advertising or publicity pertaining to
+# distribution of the software without specific, written prior
+# permission.
+#
+# THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+from ctypes import c_void_p, POINTER, sizeof, Structure, windll, WinError, WINFUNCTYPE
+from ctypes.wintypes import BOOL, BYTE, DWORD, HANDLE, LPCWSTR, LPWSTR, UINT, WORD, \
+ c_buffer, c_ulong, byref
+from qijo import QueryInformationJobObject
+
+LPVOID = c_void_p
+LPBYTE = POINTER(BYTE)
+LPDWORD = POINTER(DWORD)
+LPBOOL = POINTER(BOOL)
+
+def ErrCheckBool(result, func, args):
+ """errcheck function for Windows functions that return a BOOL True
+ on success"""
+ if not result:
+ raise WinError()
+ return args
+
+
+# AutoHANDLE
+
+class AutoHANDLE(HANDLE):
+ """Subclass of HANDLE which will call CloseHandle() on deletion."""
+
+ CloseHandleProto = WINFUNCTYPE(BOOL, HANDLE)
+ CloseHandle = CloseHandleProto(("CloseHandle", windll.kernel32))
+ CloseHandle.errcheck = ErrCheckBool
+
+ def Close(self):
+ if self.value and self.value != HANDLE(-1).value:
+ self.CloseHandle(self)
+ self.value = 0
+
+ def __del__(self):
+ self.Close()
+
+ def __int__(self):
+ return self.value
+
+def ErrCheckHandle(result, func, args):
+ """errcheck function for Windows functions that return a HANDLE."""
+ if not result:
+ raise WinError()
+ return AutoHANDLE(result)
+
+# PROCESS_INFORMATION structure
+
+class PROCESS_INFORMATION(Structure):
+ _fields_ = [("hProcess", HANDLE),
+ ("hThread", HANDLE),
+ ("dwProcessID", DWORD),
+ ("dwThreadID", DWORD)]
+
+ def __init__(self):
+ Structure.__init__(self)
+
+ self.cb = sizeof(self)
+
+LPPROCESS_INFORMATION = POINTER(PROCESS_INFORMATION)
+
+# STARTUPINFO structure
+
+class STARTUPINFO(Structure):
+ _fields_ = [("cb", DWORD),
+ ("lpReserved", LPWSTR),
+ ("lpDesktop", LPWSTR),
+ ("lpTitle", LPWSTR),
+ ("dwX", DWORD),
+ ("dwY", DWORD),
+ ("dwXSize", DWORD),
+ ("dwYSize", DWORD),
+ ("dwXCountChars", DWORD),
+ ("dwYCountChars", DWORD),
+ ("dwFillAttribute", DWORD),
+ ("dwFlags", DWORD),
+ ("wShowWindow", WORD),
+ ("cbReserved2", WORD),
+ ("lpReserved2", LPBYTE),
+ ("hStdInput", HANDLE),
+ ("hStdOutput", HANDLE),
+ ("hStdError", HANDLE)
+ ]
+LPSTARTUPINFO = POINTER(STARTUPINFO)
+
+SW_HIDE = 0
+
+STARTF_USESHOWWINDOW = 0x01
+STARTF_USESIZE = 0x02
+STARTF_USEPOSITION = 0x04
+STARTF_USECOUNTCHARS = 0x08
+STARTF_USEFILLATTRIBUTE = 0x10
+STARTF_RUNFULLSCREEN = 0x20
+STARTF_FORCEONFEEDBACK = 0x40
+STARTF_FORCEOFFFEEDBACK = 0x80
+STARTF_USESTDHANDLES = 0x100
+
+# EnvironmentBlock
+
+class EnvironmentBlock:
+ """An object which can be passed as the lpEnv parameter of CreateProcess.
+ It is initialized with a dictionary."""
+
+ def __init__(self, dict):
+ if not dict:
+ self._as_parameter_ = None
+ else:
+ values = ["%s=%s" % (key, value)
+ for (key, value) in dict.iteritems()]
+ values.append("")
+ self._as_parameter_ = LPCWSTR("\0".join(values))
+
+# CreateProcess()
+
+CreateProcessProto = WINFUNCTYPE(BOOL, # Return type
+ LPCWSTR, # lpApplicationName
+ LPWSTR, # lpCommandLine
+ LPVOID, # lpProcessAttributes
+ LPVOID, # lpThreadAttributes
+ BOOL, # bInheritHandles
+ DWORD, # dwCreationFlags
+ LPVOID, # lpEnvironment
+ LPCWSTR, # lpCurrentDirectory
+ LPSTARTUPINFO, # lpStartupInfo
+ LPPROCESS_INFORMATION # lpProcessInformation
+ )
+
+CreateProcessFlags = ((1, "lpApplicationName", None),
+ (1, "lpCommandLine"),
+ (1, "lpProcessAttributes", None),
+ (1, "lpThreadAttributes", None),
+ (1, "bInheritHandles", True),
+ (1, "dwCreationFlags", 0),
+ (1, "lpEnvironment", None),
+ (1, "lpCurrentDirectory", None),
+ (1, "lpStartupInfo"),
+ (2, "lpProcessInformation"))
+
+def ErrCheckCreateProcess(result, func, args):
+ ErrCheckBool(result, func, args)
+ # return a tuple (hProcess, hThread, dwProcessID, dwThreadID)
+ pi = args[9]
+ return AutoHANDLE(pi.hProcess), AutoHANDLE(pi.hThread), pi.dwProcessID, pi.dwThreadID
+
+CreateProcess = CreateProcessProto(("CreateProcessW", windll.kernel32),
+ CreateProcessFlags)
+CreateProcess.errcheck = ErrCheckCreateProcess
+
+# flags for CreateProcess
+CREATE_BREAKAWAY_FROM_JOB = 0x01000000
+CREATE_DEFAULT_ERROR_MODE = 0x04000000
+CREATE_NEW_CONSOLE = 0x00000010
+CREATE_NEW_PROCESS_GROUP = 0x00000200
+CREATE_NO_WINDOW = 0x08000000
+CREATE_SUSPENDED = 0x00000004
+CREATE_UNICODE_ENVIRONMENT = 0x00000400
+
+# flags for job limit information
+# see http://msdn.microsoft.com/en-us/library/ms684147%28VS.85%29.aspx
+JOB_OBJECT_LIMIT_BREAKAWAY_OK = 0x00000800
+JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK = 0x00001000
+
+# XXX these flags should be documented
+DEBUG_ONLY_THIS_PROCESS = 0x00000002
+DEBUG_PROCESS = 0x00000001
+DETACHED_PROCESS = 0x00000008
+
+# CreateJobObject()
+
+CreateJobObjectProto = WINFUNCTYPE(HANDLE, # Return type
+ LPVOID, # lpJobAttributes
+ LPCWSTR # lpName
+ )
+
+CreateJobObjectFlags = ((1, "lpJobAttributes", None),
+ (1, "lpName", None))
+
+CreateJobObject = CreateJobObjectProto(("CreateJobObjectW", windll.kernel32),
+ CreateJobObjectFlags)
+CreateJobObject.errcheck = ErrCheckHandle
+
+# AssignProcessToJobObject()
+
+AssignProcessToJobObjectProto = WINFUNCTYPE(BOOL, # Return type
+ HANDLE, # hJob
+ HANDLE # hProcess
+ )
+AssignProcessToJobObjectFlags = ((1, "hJob"),
+ (1, "hProcess"))
+AssignProcessToJobObject = AssignProcessToJobObjectProto(
+ ("AssignProcessToJobObject", windll.kernel32),
+ AssignProcessToJobObjectFlags)
+AssignProcessToJobObject.errcheck = ErrCheckBool
+
+# GetCurrentProcess()
+# because os.getPid() is way too easy
+GetCurrentProcessProto = WINFUNCTYPE(HANDLE # Return type
+ )
+GetCurrentProcessFlags = ()
+GetCurrentProcess = GetCurrentProcessProto(
+ ("GetCurrentProcess", windll.kernel32),
+ GetCurrentProcessFlags)
+GetCurrentProcess.errcheck = ErrCheckHandle
+
+# IsProcessInJob()
+try:
+ IsProcessInJobProto = WINFUNCTYPE(BOOL, # Return type
+ HANDLE, # Process Handle
+ HANDLE, # Job Handle
+ LPBOOL # Result
+ )
+ IsProcessInJobFlags = ((1, "ProcessHandle"),
+ (1, "JobHandle", HANDLE(0)),
+ (2, "Result"))
+ IsProcessInJob = IsProcessInJobProto(
+ ("IsProcessInJob", windll.kernel32),
+ IsProcessInJobFlags)
+ IsProcessInJob.errcheck = ErrCheckBool
+except AttributeError:
+ # windows 2k doesn't have this API
+ def IsProcessInJob(process):
+ return False
+
+
+# ResumeThread()
+
+def ErrCheckResumeThread(result, func, args):
+ if result == -1:
+ raise WinError()
+
+ return args
+
+ResumeThreadProto = WINFUNCTYPE(DWORD, # Return type
+ HANDLE # hThread
+ )
+ResumeThreadFlags = ((1, "hThread"),)
+ResumeThread = ResumeThreadProto(("ResumeThread", windll.kernel32),
+ ResumeThreadFlags)
+ResumeThread.errcheck = ErrCheckResumeThread
+
+# TerminateProcess()
+
+TerminateProcessProto = WINFUNCTYPE(BOOL, # Return type
+ HANDLE, # hProcess
+ UINT # uExitCode
+ )
+TerminateProcessFlags = ((1, "hProcess"),
+ (1, "uExitCode", 127))
+TerminateProcess = TerminateProcessProto(
+ ("TerminateProcess", windll.kernel32),
+ TerminateProcessFlags)
+TerminateProcess.errcheck = ErrCheckBool
+
+# TerminateJobObject()
+
+TerminateJobObjectProto = WINFUNCTYPE(BOOL, # Return type
+ HANDLE, # hJob
+ UINT # uExitCode
+ )
+TerminateJobObjectFlags = ((1, "hJob"),
+ (1, "uExitCode", 127))
+TerminateJobObject = TerminateJobObjectProto(
+ ("TerminateJobObject", windll.kernel32),
+ TerminateJobObjectFlags)
+TerminateJobObject.errcheck = ErrCheckBool
+
+# WaitForSingleObject()
+
+WaitForSingleObjectProto = WINFUNCTYPE(DWORD, # Return type
+ HANDLE, # hHandle
+ DWORD, # dwMilliseconds
+ )
+WaitForSingleObjectFlags = ((1, "hHandle"),
+ (1, "dwMilliseconds", -1))
+WaitForSingleObject = WaitForSingleObjectProto(
+ ("WaitForSingleObject", windll.kernel32),
+ WaitForSingleObjectFlags)
+
+INFINITE = -1
+WAIT_TIMEOUT = 0x0102
+WAIT_OBJECT_0 = 0x0
+WAIT_ABANDONED = 0x0080
+WAIT_FAILED = 0xFFFFFFFF
+
+# GetExitCodeProcess()
+
+GetExitCodeProcessProto = WINFUNCTYPE(BOOL, # Return type
+ HANDLE, # hProcess
+ LPDWORD, # lpExitCode
+ )
+GetExitCodeProcessFlags = ((1, "hProcess"),
+ (2, "lpExitCode"))
+GetExitCodeProcess = GetExitCodeProcessProto(
+ ("GetExitCodeProcess", windll.kernel32),
+ GetExitCodeProcessFlags)
+GetExitCodeProcess.errcheck = ErrCheckBool
+
+def CanCreateJobObject():
+ currentProc = GetCurrentProcess()
+ if IsProcessInJob(currentProc):
+ jobinfo = QueryInformationJobObject(HANDLE(0), 'JobObjectExtendedLimitInformation')
+ limitflags = jobinfo['BasicLimitInformation']['LimitFlags']
+ return bool(limitflags & JOB_OBJECT_LIMIT_BREAKAWAY_OK) or bool(limitflags & JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK)
+ else:
+ return True
+
+### testing functions
+
+def parent():
+ print 'Starting parent'
+ currentProc = GetCurrentProcess()
+ if IsProcessInJob(currentProc):
+ print >> sys.stderr, "You should not be in a job object to test"
+ sys.exit(1)
+ assert CanCreateJobObject()
+ print 'File: %s' % __file__
+ command = [sys.executable, __file__, '-child']
+ print 'Running command: %s' % command
+ process = Popen(command)
+ process.kill()
+ code = process.returncode
+ print 'Child code: %s' % code
+ assert code == 127
+
+def child():
+ print 'Starting child'
+ currentProc = GetCurrentProcess()
+ injob = IsProcessInJob(currentProc)
+ print "Is in a job?: %s" % injob
+ can_create = CanCreateJobObject()
+ print 'Can create job?: %s' % can_create
+ process = Popen('c:\\windows\\notepad.exe')
+ assert process._job
+ jobinfo = QueryInformationJobObject(process._job, 'JobObjectExtendedLimitInformation')
+ print 'Job info: %s' % jobinfo
+ limitflags = jobinfo['BasicLimitInformation']['LimitFlags']
+ print 'LimitFlags: %s' % limitflags
+ process.kill()
+
+if __name__ == '__main__':
+ import sys
+ from killableprocess import Popen
+ nargs = len(sys.argv[1:])
+ if nargs:
+ if nargs != 1 or sys.argv[1] != '-child':
+ raise AssertionError('Wrong flags; run like `python /path/to/winprocess.py`')
+ child()
+ else:
+ parent()
diff --git a/tools/addon-sdk-1.7/python-lib/mozrunner/wpk.py b/tools/addon-sdk-1.7/python-lib/mozrunner/wpk.py
new file mode 100644
index 0000000..6c92f5d
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/mozrunner/wpk.py
@@ -0,0 +1,80 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from ctypes import sizeof, windll, addressof, c_wchar, create_unicode_buffer
+from ctypes.wintypes import DWORD, HANDLE
+
+PROCESS_TERMINATE = 0x0001
+PROCESS_QUERY_INFORMATION = 0x0400
+PROCESS_VM_READ = 0x0010
+
+def get_pids(process_name):
+ BIG_ARRAY = DWORD * 4096
+ processes = BIG_ARRAY()
+ needed = DWORD()
+
+ pids = []
+ result = windll.psapi.EnumProcesses(processes,
+ sizeof(processes),
+ addressof(needed))
+ if not result:
+ return pids
+
+ num_results = needed.value / sizeof(DWORD)
+
+ for i in range(num_results):
+ pid = processes[i]
+ process = windll.kernel32.OpenProcess(PROCESS_QUERY_INFORMATION |
+ PROCESS_VM_READ,
+ 0, pid)
+ if process:
+ module = HANDLE()
+ result = windll.psapi.EnumProcessModules(process,
+ addressof(module),
+ sizeof(module),
+ addressof(needed))
+ if result:
+ name = create_unicode_buffer(1024)
+ result = windll.psapi.GetModuleBaseNameW(process, module,
+ name, len(name))
+ # TODO: This might not be the best way to
+ # match a process name; maybe use a regexp instead.
+ if name.value.startswith(process_name):
+ pids.append(pid)
+ windll.kernel32.CloseHandle(module)
+ windll.kernel32.CloseHandle(process)
+
+ return pids
+
+def kill_pid(pid):
+ process = windll.kernel32.OpenProcess(PROCESS_TERMINATE, 0, pid)
+ if process:
+ windll.kernel32.TerminateProcess(process, 0)
+ windll.kernel32.CloseHandle(process)
+
+if __name__ == '__main__':
+ import subprocess
+ import time
+
+ # This test just opens a new notepad instance and kills it.
+
+ name = 'notepad'
+
+ old_pids = set(get_pids(name))
+ subprocess.Popen([name])
+ time.sleep(0.25)
+ new_pids = set(get_pids(name)).difference(old_pids)
+
+ if len(new_pids) != 1:
+ raise Exception('%s was not opened or get_pids() is '
+ 'malfunctioning' % name)
+
+ kill_pid(tuple(new_pids)[0])
+
+ newest_pids = set(get_pids(name)).difference(old_pids)
+
+ if len(newest_pids) != 0:
+ raise Exception('kill_pid() is malfunctioning')
+
+ print "Test passed."
diff --git a/tools/addon-sdk-1.7/python-lib/plural-rules-generator.py b/tools/addon-sdk-1.7/python-lib/plural-rules-generator.py
new file mode 100644
index 0000000..5776fd8
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/plural-rules-generator.py
@@ -0,0 +1,174 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Program used to generate /packages/api-utils/lib/l10n/plural-rules.js
+# Fetch unicode.org data in order to build functions specific to each language
+# that will return for a given integer, its plural form name.
+# Plural form names are: zero, one, two, few, many, other.
+#
+# More information here:
+# http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
+# http://cldr.unicode.org/index/cldr-spec/plural-rules
+
+# Usage:
+# $ python plural-rules-generator.py > ../packages/api-utils/lib/l10n/plural-rules.js
+
+import urllib2
+import xml.dom.minidom
+import json
+import re
+
+PRINT_CONDITIONS_IN_COMMENTS = False
+
+UNICODE_ORG_XML_URL = "http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml"
+
+CONDITION_RE = r'n( mod \d+)? (is|in|within|(not in))( not)? ([^\s]+)'
+
+# For a given regexp.MatchObject `g` for `CONDITION_RE`,
+# returns the equivalent JS piece of code
+# i.e. maps pseudo conditional language from unicode.org XML to JS code
+def parseCondition(g):
+ lvalue = "n"
+ if g.group(1):
+ lvalue = "(n %% %d)" % int(g.group(1).replace("mod ", ""))
+
+ operator = g.group(2)
+ if g.group(4):
+ operator += " not"
+
+ rvalue = g.group(5)
+
+ if operator == "is":
+ return "%s == %s" % (lvalue, rvalue)
+ if operator == "is not":
+ return "%s != %s" % (lvalue, rvalue)
+
+ # "in", "within" or "not in" case:
+ notPrefix = ""
+ if operator == "not in":
+ notPrefix = "!"
+
+ # `rvalue` is a comma seperated list of either:
+ # - numbers: 42
+ # - ranges: 42..72
+ sections = rvalue.split(',')
+
+ if ".." not in rvalue:
+ # If we don't have range, but only a list of integer,
+ # we can simplify the generated code by using `isIn`
+ # n in 1,3,6,42
+ return "%sisIn(%s, [%s])" % (notPrefix, lvalue, ", ".join(sections))
+
+ # n in 1..42
+ # n in 1..3,42
+ subCondition = []
+ integers = []
+ for sub in sections:
+ if ".." in sub:
+ left, right = sub.split("..")
+ subCondition.append("isBetween(%s, %d, %d)" % (
+ lvalue,
+ int(left),
+ int(right)
+ ))
+ else:
+ integers.append(int(sub))
+ if len(integers) > 1:
+ subCondition.append("isIn(%s, [%s])" % (lvalue, ", ".join(integers)))
+ elif len(integers) == 1:
+ subCondition.append("(%s == %s)" % (lvalue, integers[0]))
+ return "%s(%s)" % (notPrefix, " || ".join(subCondition))
+
+def computeRules():
+ # Fetch plural rules data directly from unicode.org website:
+ url = UNICODE_ORG_XML_URL
+ f = urllib2.urlopen(url)
+ doc = xml.dom.minidom.parse(f)
+
+ # Read XML document and extract locale to rules mapping
+ localesMapping = {}
+ algorithms = {}
+ for index,pluralRules in enumerate(doc.getElementsByTagName("pluralRules")):
+ if not index in algorithms:
+ algorithms[index] = {}
+ for locale in pluralRules.getAttribute("locales").split():
+ localesMapping[locale] = index
+ for rule in pluralRules.childNodes:
+ if rule.nodeType != rule.ELEMENT_NODE or rule.tagName != "pluralRule":
+ continue
+ pluralForm = rule.getAttribute("count")
+ algorithm = rule.firstChild.nodeValue
+ algorithms[index][pluralForm] = algorithm
+
+ # Go through all rules and compute a Javascript code for each of them
+ rules = {}
+ for index,rule in algorithms.iteritems():
+ lines = []
+ for pluralForm in rule:
+ condition = rule[pluralForm]
+ originalCondition = str(condition)
+
+ # Convert pseudo language to JS code
+ condition = rule[pluralForm].lower()
+ condition = re.sub(CONDITION_RE, parseCondition, condition)
+ condition = re.sub(r'or', "||", condition)
+ condition = re.sub(r'and', "&&", condition)
+
+ # Prints original condition in unicode.org pseudo language
+ if PRINT_CONDITIONS_IN_COMMENTS:
+ lines.append( '// %s' % originalCondition )
+
+ lines.append( 'if (%s)' % condition )
+ lines.append( ' return "%s";' % pluralForm )
+
+ rules[index] = "\n ".join(lines)
+ return localesMapping, rules
+
+
+localesMapping, rules = computeRules()
+
+rulesLines = []
+for index in rules:
+ lines = rules[index]
+ rulesLines.append('"%d": function (n) {' % index)
+ rulesLines.append(' %s' % lines)
+ rulesLines.append(' return "other"')
+ rulesLines.append('},')
+
+print """/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// This file is automatically generated with /python-lib/plural-rules-generator.py
+// Fetching data from: %s
+
+// Mapping of short locale name == to == > rule index in following list
+const LOCALES_TO_RULES = %s;
+
+// Utility functions for plural rules methods
+function isIn(n, list) list.indexOf(n) !== -1;
+function isBetween(n, start, end) start <= n && n <= end;
+
+// List of all plural rules methods, that maps an integer to the plural form name to use
+const RULES = {
+ %s
+};
+
+/**
+ * Return a function that gives the plural form name for a given integer
+ * for the specified `locale`
+ * let fun = getRulesForLocale('en');
+ * fun(1) -> 'one'
+ * fun(0) -> 'other'
+ * fun(1000) -> 'other'
+ */
+exports.getRulesForLocale = function getRulesForLocale(locale) {
+ let index = LOCALES_TO_RULES[locale];
+ if (!(index in RULES))
+ throw new Error('Plural form unknown for locale \"' + locale + '\"');
+ return RULES[index];
+}
+""" % (UNICODE_ORG_XML_URL,
+ json.dumps(localesMapping, sort_keys=True, indent=2),
+ "\n ".join(rulesLines))
diff --git a/tools/addon-sdk-1.7/python-lib/simplejson/LICENSE.txt b/tools/addon-sdk-1.7/python-lib/simplejson/LICENSE.txt
new file mode 100644
index 0000000..ad95f29
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/simplejson/LICENSE.txt
@@ -0,0 +1,19 @@
+Copyright (c) 2006 Bob Ippolito
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/tools/addon-sdk-1.7/python-lib/simplejson/__init__.py b/tools/addon-sdk-1.7/python-lib/simplejson/__init__.py
new file mode 100644
index 0000000..adcce7e
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/simplejson/__init__.py
@@ -0,0 +1,376 @@
+r"""
+A simple, fast, extensible JSON encoder and decoder
+
+JSON (JavaScript Object Notation) <http://json.org> is a subset of
+JavaScript syntax (ECMA-262 3rd edition) used as a lightweight data
+interchange format.
+
+simplejson exposes an API familiar to uses of the standard library
+marshal and pickle modules.
+
+Encoding basic Python object hierarchies::
+
+ >>> import simplejson
+ >>> simplejson.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
+ '["foo", {"bar": ["baz", null, 1.0, 2]}]'
+ >>> print simplejson.dumps("\"foo\bar")
+ "\"foo\bar"
+ >>> print simplejson.dumps(u'\u1234')
+ "\u1234"
+ >>> print simplejson.dumps('\\')
+ "\\"
+ >>> print simplejson.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=True)
+ {"a": 0, "b": 0, "c": 0}
+ >>> from StringIO import StringIO
+ >>> io = StringIO()
+ >>> simplejson.dump(['streaming API'], io)
+ >>> io.getvalue()
+ '["streaming API"]'
+
+Compact encoding::
+
+ >>> import simplejson
+ >>> simplejson.dumps([1,2,3,{'4': 5, '6': 7}], separators=(',',':'))
+ '[1,2,3,{"4":5,"6":7}]'
+
+Pretty printing::
+
+ >>> import simplejson
+ >>> print simplejson.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4)
+ {
+ "4": 5,
+ "6": 7
+ }
+
+Decoding JSON::
+
+ >>> import simplejson
+ >>> simplejson.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
+ [u'foo', {u'bar': [u'baz', None, 1.0, 2]}]
+ >>> simplejson.loads('"\\"foo\\bar"')
+ u'"foo\x08ar'
+ >>> from StringIO import StringIO
+ >>> io = StringIO('["streaming API"]')
+ >>> simplejson.load(io)
+ [u'streaming API']
+
+Specializing JSON object decoding::
+
+ >>> import simplejson
+ >>> def as_complex(dct):
+ ... if '__complex__' in dct:
+ ... return complex(dct['real'], dct['imag'])
+ ... return dct
+ ...
+ >>> simplejson.loads('{"__complex__": true, "real": 1, "imag": 2}',
+ ... object_hook=as_complex)
+ (1+2j)
+ >>> import decimal
+ >>> simplejson.loads('1.1', parse_float=decimal.Decimal)
+ Decimal("1.1")
+
+Extending JSONEncoder::
+
+ >>> import simplejson
+ >>> class ComplexEncoder(simplejson.JSONEncoder):
+ ... def default(self, obj):
+ ... if isinstance(obj, complex):
+ ... return [obj.real, obj.imag]
+ ... return simplejson.JSONEncoder.default(self, obj)
+ ...
+ >>> dumps(2 + 1j, cls=ComplexEncoder)
+ '[2.0, 1.0]'
+ >>> ComplexEncoder().encode(2 + 1j)
+ '[2.0, 1.0]'
+ >>> list(ComplexEncoder().iterencode(2 + 1j))
+ ['[', '2.0', ', ', '1.0', ']']
+
+
+Using simplejson from the shell to validate and
+pretty-print::
+
+ $ echo '{"json":"obj"}' | python -msimplejson.tool
+ {
+ "json": "obj"
+ }
+ $ echo '{ 1.2:3.4}' | python -msimplejson.tool
+ Expecting property name: line 1 column 2 (char 2)
+
+Note that the JSON produced by this module's default settings
+is a subset of YAML, so it may be used as a serializer for that as well.
+"""
+__version__ = '1.9.2'
+__all__ = [
+ 'dump', 'dumps', 'load', 'loads',
+ 'JSONDecoder', 'JSONEncoder',
+]
+
+if __name__ == '__main__':
+ import warnings
+ warnings.warn('python -msimplejson is deprecated, use python -msiplejson.tool', DeprecationWarning)
+ from simplejson.decoder import JSONDecoder
+ from simplejson.encoder import JSONEncoder
+else:
+ from decoder import JSONDecoder
+ from encoder import JSONEncoder
+
+_default_encoder = JSONEncoder(
+ skipkeys=False,
+ ensure_ascii=True,
+ check_circular=True,
+ allow_nan=True,
+ indent=None,
+ separators=None,
+ encoding='utf-8',
+ default=None,
+)
+
+def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
+ allow_nan=True, cls=None, indent=None, separators=None,
+ encoding='utf-8', default=None, **kw):
+ """
+ Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
+ ``.write()``-supporting file-like object).
+
+ If ``skipkeys`` is ``True`` then ``dict`` keys that are not basic types
+ (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
+ will be skipped instead of raising a ``TypeError``.
+
+ If ``ensure_ascii`` is ``False``, then the some chunks written to ``fp``
+ may be ``unicode`` instances, subject to normal Python ``str`` to
+ ``unicode`` coercion rules. Unless ``fp.write()`` explicitly
+ understands ``unicode`` (as in ``codecs.getwriter()``) this is likely
+ to cause an error.
+
+ If ``check_circular`` is ``False``, then the circular reference check
+ for container types will be skipped and a circular reference will
+ result in an ``OverflowError`` (or worse).
+
+ If ``allow_nan`` is ``False``, then it will be a ``ValueError`` to
+ serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``)
+ in strict compliance of the JSON specification, instead of using the
+ JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
+
+ If ``indent`` is a non-negative integer, then JSON array elements and object
+ members will be pretty-printed with that indent level. An indent level
+ of 0 will only insert newlines. ``None`` is the most compact representation.
+
+ If ``separators`` is an ``(item_separator, dict_separator)`` tuple
+ then it will be used instead of the default ``(', ', ': ')`` separators.
+ ``(',', ':')`` is the most compact JSON representation.
+
+ ``encoding`` is the character encoding for str instances, default is UTF-8.
+
+ ``default(obj)`` is a function that should return a serializable version
+ of obj or raise TypeError. The default simply raises TypeError.
+
+ To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
+ ``.default()`` method to serialize additional types), specify it with
+ the ``cls`` kwarg.
+ """
+ # cached encoder
+ if (skipkeys is False and ensure_ascii is True and
+ check_circular is True and allow_nan is True and
+ cls is None and indent is None and separators is None and
+ encoding == 'utf-8' and default is None and not kw):
+ iterable = _default_encoder.iterencode(obj)
+ else:
+ if cls is None:
+ cls = JSONEncoder
+ iterable = cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,
+ check_circular=check_circular, allow_nan=allow_nan, indent=indent,
+ separators=separators, encoding=encoding,
+ default=default, **kw).iterencode(obj)
+ # could accelerate with writelines in some versions of Python, at
+ # a debuggability cost
+ for chunk in iterable:
+ fp.write(chunk)
+
+
+def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
+ allow_nan=True, cls=None, indent=None, separators=None,
+ encoding='utf-8', default=None, **kw):
+ """
+ Serialize ``obj`` to a JSON formatted ``str``.
+
+ If ``skipkeys`` is ``True`` then ``dict`` keys that are not basic types
+ (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
+ will be skipped instead of raising a ``TypeError``.
+
+ If ``ensure_ascii`` is ``False``, then the return value will be a
+ ``unicode`` instance subject to normal Python ``str`` to ``unicode``
+ coercion rules instead of being escaped to an ASCII ``str``.
+
+ If ``check_circular`` is ``False``, then the circular reference check
+ for container types will be skipped and a circular reference will
+ result in an ``OverflowError`` (or worse).
+
+ If ``allow_nan`` is ``False``, then it will be a ``ValueError`` to
+ serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``) in
+ strict compliance of the JSON specification, instead of using the
+ JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
+
+ If ``indent`` is a non-negative integer, then JSON array elements and
+ object members will be pretty-printed with that indent level. An indent
+ level of 0 will only insert newlines. ``None`` is the most compact
+ representation.
+
+ If ``separators`` is an ``(item_separator, dict_separator)`` tuple
+ then it will be used instead of the default ``(', ', ': ')`` separators.
+ ``(',', ':')`` is the most compact JSON representation.
+
+ ``encoding`` is the character encoding for str instances, default is UTF-8.
+
+ ``default(obj)`` is a function that should return a serializable version
+ of obj or raise TypeError. The default simply raises TypeError.
+
+ To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
+ ``.default()`` method to serialize additional types), specify it with
+ the ``cls`` kwarg.
+ """
+ # cached encoder
+ if (skipkeys is False and ensure_ascii is True and
+ check_circular is True and allow_nan is True and
+ cls is None and indent is None and separators is None and
+ encoding == 'utf-8' and default is None and not kw):
+ return _default_encoder.encode(obj)
+ if cls is None:
+ cls = JSONEncoder
+ return cls(
+ skipkeys=skipkeys, ensure_ascii=ensure_ascii,
+ check_circular=check_circular, allow_nan=allow_nan, indent=indent,
+ separators=separators, encoding=encoding, default=default,
+ **kw).encode(obj)
+
+
+_default_decoder = JSONDecoder(encoding=None, object_hook=None)
+
+
+def load(fp, encoding=None, cls=None, object_hook=None, parse_float=None,
+ parse_int=None, parse_constant=None, **kw):
+ """
+ Deserialize ``fp`` (a ``.read()``-supporting file-like object containing
+ a JSON document) to a Python object.
+
+ If the contents of ``fp`` is encoded with an ASCII based encoding other
+ than utf-8 (e.g. latin-1), then an appropriate ``encoding`` name must
+ be specified. Encodings that are not ASCII based (such as UCS-2) are
+ not allowed, and should be wrapped with
+ ``codecs.getreader(fp)(encoding)``, or simply decoded to a ``unicode``
+ object and passed to ``loads()``
+
+ ``object_hook`` is an optional function that will be called with the
+ result of any object literal decode (a ``dict``). The return value of
+ ``object_hook`` will be used instead of the ``dict``. This feature
+ can be used to implement custom decoders (e.g. JSON-RPC class hinting).
+
+ To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
+ kwarg.
+ """
+ return loads(fp.read(),
+ encoding=encoding, cls=cls, object_hook=object_hook,
+ parse_float=parse_float, parse_int=parse_int,
+ parse_constant=parse_constant, **kw)
+
+
+def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,
+ parse_int=None, parse_constant=None, **kw):
+ """
+ Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON
+ document) to a Python object.
+
+ If ``s`` is a ``str`` instance and is encoded with an ASCII based encoding
+ other than utf-8 (e.g. latin-1) then an appropriate ``encoding`` name
+ must be specified. Encodings that are not ASCII based (such as UCS-2)
+ are not allowed and should be decoded to ``unicode`` first.
+
+ ``object_hook`` is an optional function that will be called with the
+ result of any object literal decode (a ``dict``). The return value of
+ ``object_hook`` will be used instead of the ``dict``. This feature
+ can be used to implement custom decoders (e.g. JSON-RPC class hinting).
+
+ ``parse_float``, if specified, will be called with the string
+ of every JSON float to be decoded. By default this is equivalent to
+ float(num_str). This can be used to use another datatype or parser
+ for JSON floats (e.g. decimal.Decimal).
+
+ ``parse_int``, if specified, will be called with the string
+ of every JSON int to be decoded. By default this is equivalent to
+ int(num_str). This can be used to use another datatype or parser
+ for JSON integers (e.g. float).
+
+ ``parse_constant``, if specified, will be called with one of the
+ following strings: -Infinity, Infinity, NaN, null, true, false.
+ This can be used to raise an exception if invalid JSON numbers
+ are encountered.
+
+ To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
+ kwarg.
+ """
+ if (cls is None and encoding is None and object_hook is None and
+ parse_int is None and parse_float is None and
+ parse_constant is None and not kw):
+ return _default_decoder.decode(s)
+ if cls is None:
+ cls = JSONDecoder
+ if object_hook is not None:
+ kw['object_hook'] = object_hook
+ if parse_float is not None:
+ kw['parse_float'] = parse_float
+ if parse_int is not None:
+ kw['parse_int'] = parse_int
+ if parse_constant is not None:
+ kw['parse_constant'] = parse_constant
+ return cls(encoding=encoding, **kw).decode(s)
+
+
+#
+# Compatibility cruft from other libraries
+#
+
+
+def decode(s):
+ """
+ demjson, python-cjson API compatibility hook. Use loads(s) instead.
+ """
+ import warnings
+ warnings.warn("simplejson.loads(s) should be used instead of decode(s)",
+ DeprecationWarning)
+ return loads(s)
+
+
+def encode(obj):
+ """
+ demjson, python-cjson compatibility hook. Use dumps(s) instead.
+ """
+ import warnings
+ warnings.warn("simplejson.dumps(s) should be used instead of encode(s)",
+ DeprecationWarning)
+ return dumps(obj)
+
+
+def read(s):
+ """
+ jsonlib, JsonUtils, python-json, json-py API compatibility hook.
+ Use loads(s) instead.
+ """
+ import warnings
+ warnings.warn("simplejson.loads(s) should be used instead of read(s)",
+ DeprecationWarning)
+ return loads(s)
+
+
+def write(obj):
+ """
+ jsonlib, JsonUtils, python-json, json-py API compatibility hook.
+ Use dumps(s) instead.
+ """
+ import warnings
+ warnings.warn("simplejson.dumps(s) should be used instead of write(s)",
+ DeprecationWarning)
+ return dumps(obj)
+
+
+if __name__ == '__main__':
+ import simplejson.tool
+ simplejson.tool.main()
diff --git a/tools/addon-sdk-1.7/python-lib/simplejson/decoder.py b/tools/addon-sdk-1.7/python-lib/simplejson/decoder.py
new file mode 100644
index 0000000..baf10e9
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/simplejson/decoder.py
@@ -0,0 +1,343 @@
+"""
+Implementation of JSONDecoder
+"""
+import re
+import sys
+
+from simplejson.scanner import Scanner, pattern
+try:
+ from simplejson._speedups import scanstring as c_scanstring
+except ImportError:
+ pass
+
+FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL
+
+def _floatconstants():
+ import struct
+ import sys
+ _BYTES = '7FF80000000000007FF0000000000000'.decode('hex')
+ if sys.byteorder != 'big':
+ _BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1]
+ nan, inf = struct.unpack('dd', _BYTES)
+ return nan, inf, -inf
+
+NaN, PosInf, NegInf = _floatconstants()
+
+
+def linecol(doc, pos):
+ lineno = doc.count('\n', 0, pos) + 1
+ if lineno == 1:
+ colno = pos
+ else:
+ colno = pos - doc.rindex('\n', 0, pos)
+ return lineno, colno
+
+
+def errmsg(msg, doc, pos, end=None):
+ lineno, colno = linecol(doc, pos)
+ if end is None:
+ return '%s: line %d column %d (char %d)' % (msg, lineno, colno, pos)
+ endlineno, endcolno = linecol(doc, end)
+ return '%s: line %d column %d - line %d column %d (char %d - %d)' % (
+ msg, lineno, colno, endlineno, endcolno, pos, end)
+
+
+_CONSTANTS = {
+ '-Infinity': NegInf,
+ 'Infinity': PosInf,
+ 'NaN': NaN,
+ 'true': True,
+ 'false': False,
+ 'null': None,
+}
+
+def JSONConstant(match, context, c=_CONSTANTS):
+ s = match.group(0)
+ fn = getattr(context, 'parse_constant', None)
+ if fn is None:
+ rval = c[s]
+ else:
+ rval = fn(s)
+ return rval, None
+pattern('(-?Infinity|NaN|true|false|null)')(JSONConstant)
+
+
+def JSONNumber(match, context):
+ match = JSONNumber.regex.match(match.string, *match.span())
+ integer, frac, exp = match.groups()
+ if frac or exp:
+ fn = getattr(context, 'parse_float', None) or float
+ res = fn(integer + (frac or '') + (exp or ''))
+ else:
+ fn = getattr(context, 'parse_int', None) or int
+ res = fn(integer)
+ return res, None
+pattern(r'(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?')(JSONNumber)
+
+
+STRINGCHUNK = re.compile(r'(.*?)(["\\\x00-\x1f])', FLAGS)
+BACKSLASH = {
+ '"': u'"', '\\': u'\\', '/': u'/',
+ 'b': u'\b', 'f': u'\f', 'n': u'\n', 'r': u'\r', 't': u'\t',
+}
+
+DEFAULT_ENCODING = "utf-8"
+
+def py_scanstring(s, end, encoding=None, strict=True, _b=BACKSLASH, _m=STRINGCHUNK.match):
+ if encoding is None:
+ encoding = DEFAULT_ENCODING
+ chunks = []
+ _append = chunks.append
+ begin = end - 1
+ while 1:
+ chunk = _m(s, end)
+ if chunk is None:
+ raise ValueError(
+ errmsg("Unterminated string starting at", s, begin))
+ end = chunk.end()
+ content, terminator = chunk.groups()
+ if content:
+ if not isinstance(content, unicode):
+ content = unicode(content, encoding)
+ _append(content)
+ if terminator == '"':
+ break
+ elif terminator != '\\':
+ if strict:
+ raise ValueError(errmsg("Invalid control character %r at", s, end))
+ else:
+ _append(terminator)
+ continue
+ try:
+ esc = s[end]
+ except IndexError:
+ raise ValueError(
+ errmsg("Unterminated string starting at", s, begin))
+ if esc != 'u':
+ try:
+ m = _b[esc]
+ except KeyError:
+ raise ValueError(
+ errmsg("Invalid \\escape: %r" % (esc,), s, end))
+ end += 1
+ else:
+ esc = s[end + 1:end + 5]
+ next_end = end + 5
+ msg = "Invalid \\uXXXX escape"
+ try:
+ if len(esc) != 4:
+ raise ValueError
+ uni = int(esc, 16)
+ if 0xd800 <= uni <= 0xdbff and sys.maxunicode > 65535:
+ msg = "Invalid \\uXXXX\\uXXXX surrogate pair"
+ if not s[end + 5:end + 7] == '\\u':
+ raise ValueError
+ esc2 = s[end + 7:end + 11]
+ if len(esc2) != 4:
+ raise ValueError
+ uni2 = int(esc2, 16)
+ uni = 0x10000 + (((uni - 0xd800) << 10) | (uni2 - 0xdc00))
+ next_end += 6
+ m = unichr(uni)
+ except ValueError:
+ raise ValueError(errmsg(msg, s, end))
+ end = next_end
+ _append(m)
+ return u''.join(chunks), end
+
+
+# Use speedup
+try:
+ scanstring = c_scanstring
+except NameError:
+ scanstring = py_scanstring
+
+def JSONString(match, context):
+ encoding = getattr(context, 'encoding', None)
+ strict = getattr(context, 'strict', True)
+ return scanstring(match.string, match.end(), encoding, strict)
+pattern(r'"')(JSONString)
+
+
+WHITESPACE = re.compile(r'\s*', FLAGS)
+
+def JSONObject(match, context, _w=WHITESPACE.match):
+ pairs = {}
+ s = match.string
+ end = _w(s, match.end()).end()
+ nextchar = s[end:end + 1]
+ # Trivial empty object
+ if nextchar == '}':
+ return pairs, end + 1
+ if nextchar != '"':
+ raise ValueError(errmsg("Expecting property name", s, end))
+ end += 1
+ encoding = getattr(context, 'encoding', None)
+ strict = getattr(context, 'strict', True)
+ iterscan = JSONScanner.iterscan
+ while True:
+ key, end = scanstring(s, end, encoding, strict)
+ end = _w(s, end).end()
+ if s[end:end + 1] != ':':
+ raise ValueError(errmsg("Expecting : delimiter", s, end))
+ end = _w(s, end + 1).end()
+ try:
+ value, end = iterscan(s, idx=end, context=context).next()
+ except StopIteration:
+ raise ValueError(errmsg("Expecting object", s, end))
+ pairs[key] = value
+ end = _w(s, end).end()
+ nextchar = s[end:end + 1]
+ end += 1
+ if nextchar == '}':
+ break
+ if nextchar != ',':
+ raise ValueError(errmsg("Expecting , delimiter", s, end - 1))
+ end = _w(s, end).end()
+ nextchar = s[end:end + 1]
+ end += 1
+ if nextchar != '"':
+ raise ValueError(errmsg("Expecting property name", s, end - 1))
+ object_hook = getattr(context, 'object_hook', None)
+ if object_hook is not None:
+ pairs = object_hook(pairs)
+ return pairs, end
+pattern(r'{')(JSONObject)
+
+
+def JSONArray(match, context, _w=WHITESPACE.match):
+ values = []
+ s = match.string
+ end = _w(s, match.end()).end()
+ # Look-ahead for trivial empty array
+ nextchar = s[end:end + 1]
+ if nextchar == ']':
+ return values, end + 1
+ iterscan = JSONScanner.iterscan
+ while True:
+ try:
+ value, end = iterscan(s, idx=end, context=context).next()
+ except StopIteration:
+ raise ValueError(errmsg("Expecting object", s, end))
+ values.append(value)
+ end = _w(s, end).end()
+ nextchar = s[end:end + 1]
+ end += 1
+ if nextchar == ']':
+ break
+ if nextchar != ',':
+ raise ValueError(errmsg("Expecting , delimiter", s, end))
+ end = _w(s, end).end()
+ return values, end
+pattern(r'\[')(JSONArray)
+
+
+ANYTHING = [
+ JSONObject,
+ JSONArray,
+ JSONString,
+ JSONConstant,
+ JSONNumber,
+]
+
+JSONScanner = Scanner(ANYTHING)
+
+
+class JSONDecoder(object):
+ """
+ Simple JSON <http://json.org> decoder
+
+ Performs the following translations in decoding by default:
+
+ +---------------+-------------------+
+ | JSON | Python |
+ +===============+===================+
+ | object | dict |
+ +---------------+-------------------+
+ | array | list |
+ +---------------+-------------------+
+ | string | unicode |
+ +---------------+-------------------+
+ | number (int) | int, long |
+ +---------------+-------------------+
+ | number (real) | float |
+ +---------------+-------------------+
+ | true | True |
+ +---------------+-------------------+
+ | false | False |
+ +---------------+-------------------+
+ | null | None |
+ +---------------+-------------------+
+
+ It also understands ``NaN``, ``Infinity``, and ``-Infinity`` as
+ their corresponding ``float`` values, which is outside the JSON spec.
+ """
+
+ _scanner = Scanner(ANYTHING)
+ __all__ = ['__init__', 'decode', 'raw_decode']
+
+ def __init__(self, encoding=None, object_hook=None, parse_float=None,
+ parse_int=None, parse_constant=None, strict=True):
+ """
+ ``encoding`` determines the encoding used to interpret any ``str``
+ objects decoded by this instance (utf-8 by default). It has no
+ effect when decoding ``unicode`` objects.
+
+ Note that currently only encodings that are a superset of ASCII work,
+ strings of other encodings should be passed in as ``unicode``.
+
+ ``object_hook``, if specified, will be called with the result
+ of every JSON object decoded and its return value will be used in
+ place of the given ``dict``. This can be used to provide custom
+ deserializations (e.g. to support JSON-RPC class hinting).
+
+ ``parse_float``, if specified, will be called with the string
+ of every JSON float to be decoded. By default this is equivalent to
+ float(num_str). This can be used to use another datatype or parser
+ for JSON floats (e.g. decimal.Decimal).
+
+ ``parse_int``, if specified, will be called with the string
+ of every JSON int to be decoded. By default this is equivalent to
+ int(num_str). This can be used to use another datatype or parser
+ for JSON integers (e.g. float).
+
+ ``parse_constant``, if specified, will be called with one of the
+ following strings: -Infinity, Infinity, NaN, null, true, false.
+ This can be used to raise an exception if invalid JSON numbers
+ are encountered.
+ """
+ self.encoding = encoding
+ self.object_hook = object_hook
+ self.parse_float = parse_float
+ self.parse_int = parse_int
+ self.parse_constant = parse_constant
+ self.strict = strict
+
+ def decode(self, s, _w=WHITESPACE.match):
+ """
+ Return the Python representation of ``s`` (a ``str`` or ``unicode``
+ instance containing a JSON document)
+ """
+ obj, end = self.raw_decode(s, idx=_w(s, 0).end())
+ end = _w(s, end).end()
+ if end != len(s):
+ raise ValueError(errmsg("Extra data", s, end, len(s)))
+ return obj
+
+ def raw_decode(self, s, **kw):
+ """
+ Decode a JSON document from ``s`` (a ``str`` or ``unicode`` beginning
+ with a JSON document) and return a 2-tuple of the Python
+ representation and the index in ``s`` where the document ended.
+
+ This can be used to decode a JSON document from a string that may
+ have extraneous data at the end.
+ """
+ kw.setdefault('context', self)
+ try:
+ obj, end = self._scanner.iterscan(s, **kw).next()
+ except StopIteration:
+ raise ValueError("No JSON object could be decoded")
+ return obj, end
+
+__all__ = ['JSONDecoder']
diff --git a/tools/addon-sdk-1.7/python-lib/simplejson/encoder.py b/tools/addon-sdk-1.7/python-lib/simplejson/encoder.py
new file mode 100644
index 0000000..772a261
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/simplejson/encoder.py
@@ -0,0 +1,385 @@
+"""
+Implementation of JSONEncoder
+"""
+import re
+
+try:
+ from simplejson._speedups import encode_basestring_ascii as c_encode_basestring_ascii
+except ImportError:
+ pass
+
+ESCAPE = re.compile(r'[\x00-\x1f\\"\b\f\n\r\t]')
+ESCAPE_ASCII = re.compile(r'([\\"]|[^\ -~])')
+HAS_UTF8 = re.compile(r'[\x80-\xff]')
+ESCAPE_DCT = {
+ '\\': '\\\\',
+ '"': '\\"',
+ '\b': '\\b',
+ '\f': '\\f',
+ '\n': '\\n',
+ '\r': '\\r',
+ '\t': '\\t',
+}
+for i in range(0x20):
+ ESCAPE_DCT.setdefault(chr(i), '\\u%04x' % (i,))
+
+# Assume this produces an infinity on all machines (probably not guaranteed)
+INFINITY = float('1e66666')
+FLOAT_REPR = repr
+
+def floatstr(o, allow_nan=True):
+ # Check for specials. Note that this type of test is processor- and/or
+ # platform-specific, so do tests which don't depend on the internals.
+
+ if o != o:
+ text = 'NaN'
+ elif o == INFINITY:
+ text = 'Infinity'
+ elif o == -INFINITY:
+ text = '-Infinity'
+ else:
+ return FLOAT_REPR(o)
+
+ if not allow_nan:
+ raise ValueError("Out of range float values are not JSON compliant: %r"
+ % (o,))
+
+ return text
+
+
+def encode_basestring(s):
+ """
+ Return a JSON representation of a Python string
+ """
+ def replace(match):
+ return ESCAPE_DCT[match.group(0)]
+ return '"' + ESCAPE.sub(replace, s) + '"'
+
+
+def py_encode_basestring_ascii(s):
+ if isinstance(s, str) and HAS_UTF8.search(s) is not None:
+ s = s.decode('utf-8')
+ def replace(match):
+ s = match.group(0)
+ try:
+ return ESCAPE_DCT[s]
+ except KeyError:
+ n = ord(s)
+ if n < 0x10000:
+ return '\\u%04x' % (n,)
+ else:
+ # surrogate pair
+ n -= 0x10000
+ s1 = 0xd800 | ((n >> 10) & 0x3ff)
+ s2 = 0xdc00 | (n & 0x3ff)
+ return '\\u%04x\\u%04x' % (s1, s2)
+ return '"' + str(ESCAPE_ASCII.sub(replace, s)) + '"'
+
+
+try:
+ encode_basestring_ascii = c_encode_basestring_ascii
+except NameError:
+ encode_basestring_ascii = py_encode_basestring_ascii
+
+
+class JSONEncoder(object):
+ """
+ Extensible JSON <http://json.org> encoder for Python data structures.
+
+ Supports the following objects and types by default:
+
+ +-------------------+---------------+
+ | Python | JSON |
+ +===================+===============+
+ | dict | object |
+ +-------------------+---------------+
+ | list, tuple | array |
+ +-------------------+---------------+
+ | str, unicode | string |
+ +-------------------+---------------+
+ | int, long, float | number |
+ +-------------------+---------------+
+ | True | true |
+ +-------------------+---------------+
+ | False | false |
+ +-------------------+---------------+
+ | None | null |
+ +-------------------+---------------+
+
+ To extend this to recognize other objects, subclass and implement a
+ ``.default()`` method with another method that returns a serializable
+ object for ``o`` if possible, otherwise it should call the superclass
+ implementation (to raise ``TypeError``).
+ """
+ __all__ = ['__init__', 'default', 'encode', 'iterencode']
+ item_separator = ', '
+ key_separator = ': '
+ def __init__(self, skipkeys=False, ensure_ascii=True,
+ check_circular=True, allow_nan=True, sort_keys=False,
+ indent=None, separators=None, encoding='utf-8', default=None):
+ """
+ Constructor for JSONEncoder, with sensible defaults.
+
+ If skipkeys is False, then it is a TypeError to attempt
+ encoding of keys that are not str, int, long, float or None. If
+ skipkeys is True, such items are simply skipped.
+
+ If ensure_ascii is True, the output is guaranteed to be str
+ objects with all incoming unicode characters escaped. If
+ ensure_ascii is false, the output will be unicode object.
+
+ If check_circular is True, then lists, dicts, and custom encoded
+ objects will be checked for circular references during encoding to
+ prevent an infinite recursion (which would cause an OverflowError).
+ Otherwise, no such check takes place.
+
+ If allow_nan is True, then NaN, Infinity, and -Infinity will be
+ encoded as such. This behavior is not JSON specification compliant,
+ but is consistent with most JavaScript based encoders and decoders.
+ Otherwise, it will be a ValueError to encode such floats.
+
+ If sort_keys is True, then the output of dictionaries will be
+ sorted by key; this is useful for regression tests to ensure
+ that JSON serializations can be compared on a day-to-day basis.
+
+ If indent is a non-negative integer, then JSON array
+ elements and object members will be pretty-printed with that
+ indent level. An indent level of 0 will only insert newlines.
+ None is the most compact representation.
+
+ If specified, separators should be a (item_separator, key_separator)
+ tuple. The default is (', ', ': '). To get the most compact JSON
+ representation you should specify (',', ':') to eliminate whitespace.
+
+ If specified, default is a function that gets called for objects
+ that can't otherwise be serialized. It should return a JSON encodable
+ version of the object or raise a ``TypeError``.
+
+ If encoding is not None, then all input strings will be
+ transformed into unicode using that encoding prior to JSON-encoding.
+ The default is UTF-8.
+ """
+
+ self.skipkeys = skipkeys
+ self.ensure_ascii = ensure_ascii
+ self.check_circular = check_circular
+ self.allow_nan = allow_nan
+ self.sort_keys = sort_keys
+ self.indent = indent
+ self.current_indent_level = 0
+ if separators is not None:
+ self.item_separator, self.key_separator = separators
+ if default is not None:
+ self.default = default
+ self.encoding = encoding
+
+ def _newline_indent(self):
+ return '\n' + (' ' * (self.indent * self.current_indent_level))
+
+ def _iterencode_list(self, lst, markers=None):
+ if not lst:
+ yield '[]'
+ return
+ if markers is not None:
+ markerid = id(lst)
+ if markerid in markers:
+ raise ValueError("Circular reference detected")
+ markers[markerid] = lst
+ yield '['
+ if self.indent is not None:
+ self.current_indent_level += 1
+ newline_indent = self._newline_indent()
+ separator = self.item_separator + newline_indent
+ yield newline_indent
+ else:
+ newline_indent = None
+ separator = self.item_separator
+ first = True
+ for value in lst:
+ if first:
+ first = False
+ else:
+ yield separator
+ for chunk in self._iterencode(value, markers):
+ yield chunk
+ if newline_indent is not None:
+ self.current_indent_level -= 1
+ yield self._newline_indent()
+ yield ']'
+ if markers is not None:
+ del markers[markerid]
+
+ def _iterencode_dict(self, dct, markers=None):
+ if not dct:
+ yield '{}'
+ return
+ if markers is not None:
+ markerid = id(dct)
+ if markerid in markers:
+ raise ValueError("Circular reference detected")
+ markers[markerid] = dct
+ yield '{'
+ key_separator = self.key_separator
+ if self.indent is not None:
+ self.current_indent_level += 1
+ newline_indent = self._newline_indent()
+ item_separator = self.item_separator + newline_indent
+ yield newline_indent
+ else:
+ newline_indent = None
+ item_separator = self.item_separator
+ first = True
+ if self.ensure_ascii:
+ encoder = encode_basestring_ascii
+ else:
+ encoder = encode_basestring
+ allow_nan = self.allow_nan
+ if self.sort_keys:
+ keys = dct.keys()
+ keys.sort()
+ items = [(k, dct[k]) for k in keys]
+ else:
+ items = dct.iteritems()
+ _encoding = self.encoding
+ _do_decode = (_encoding is not None
+ and not (_encoding == 'utf-8'))
+ for key, value in items:
+ if isinstance(key, str):
+ if _do_decode:
+ key = key.decode(_encoding)
+ elif isinstance(key, basestring):
+ pass
+ # JavaScript is weakly typed for these, so it makes sense to
+ # also allow them. Many encoders seem to do something like this.
+ elif isinstance(key, float):
+ key = floatstr(key, allow_nan)
+ elif isinstance(key, (int, long)):
+ key = str(key)
+ elif key is True:
+ key = 'true'
+ elif key is False:
+ key = 'false'
+ elif key is None:
+ key = 'null'
+ elif self.skipkeys:
+ continue
+ else:
+ raise TypeError("key %r is not a string" % (key,))
+ if first:
+ first = False
+ else:
+ yield item_separator
+ yield encoder(key)
+ yield key_separator
+ for chunk in self._iterencode(value, markers):
+ yield chunk
+ if newline_indent is not None:
+ self.current_indent_level -= 1
+ yield self._newline_indent()
+ yield '}'
+ if markers is not None:
+ del markers[markerid]
+
+ def _iterencode(self, o, markers=None):
+ if isinstance(o, basestring):
+ if self.ensure_ascii:
+ encoder = encode_basestring_ascii
+ else:
+ encoder = encode_basestring
+ _encoding = self.encoding
+ if (_encoding is not None and isinstance(o, str)
+ and not (_encoding == 'utf-8')):
+ o = o.decode(_encoding)
+ yield encoder(o)
+ elif o is None:
+ yield 'null'
+ elif o is True:
+ yield 'true'
+ elif o is False:
+ yield 'false'
+ elif isinstance(o, (int, long)):
+ yield str(o)
+ elif isinstance(o, float):
+ yield floatstr(o, self.allow_nan)
+ elif isinstance(o, (list, tuple)):
+ for chunk in self._iterencode_list(o, markers):
+ yield chunk
+ elif isinstance(o, dict):
+ for chunk in self._iterencode_dict(o, markers):
+ yield chunk
+ else:
+ if markers is not None:
+ markerid = id(o)
+ if markerid in markers:
+ raise ValueError("Circular reference detected")
+ markers[markerid] = o
+ for chunk in self._iterencode_default(o, markers):
+ yield chunk
+ if markers is not None:
+ del markers[markerid]
+
+ def _iterencode_default(self, o, markers=None):
+ newobj = self.default(o)
+ return self._iterencode(newobj, markers)
+
+ def default(self, o):
+ """
+ Implement this method in a subclass such that it returns
+ a serializable object for ``o``, or calls the base implementation
+ (to raise a ``TypeError``).
+
+ For example, to support arbitrary iterators, you could
+ implement default like this::
+
+ def default(self, o):
+ try:
+ iterable = iter(o)
+ except TypeError:
+ pass
+ else:
+ return list(iterable)
+ return JSONEncoder.default(self, o)
+ """
+ raise TypeError("%r is not JSON serializable" % (o,))
+
+ def encode(self, o):
+ """
+ Return a JSON string representation of a Python data structure.
+
+ >>> JSONEncoder().encode({"foo": ["bar", "baz"]})
+ '{"foo": ["bar", "baz"]}'
+ """
+ # This is for extremely simple cases and benchmarks.
+ if isinstance(o, basestring):
+ if isinstance(o, str):
+ _encoding = self.encoding
+ if (_encoding is not None
+ and not (_encoding == 'utf-8')):
+ o = o.decode(_encoding)
+ if self.ensure_ascii:
+ return encode_basestring_ascii(o)
+ else:
+ return encode_basestring(o)
+ # This doesn't pass the iterator directly to ''.join() because the
+ # exceptions aren't as detailed. The list call should be roughly
+ # equivalent to the PySequence_Fast that ''.join() would do.
+ chunks = list(self.iterencode(o))
+ return ''.join(chunks)
+
+ def iterencode(self, o):
+ """
+ Encode the given object and yield each string
+ representation as available.
+
+ For example::
+
+ for chunk in JSONEncoder().iterencode(bigobject):
+ mysocket.write(chunk)
+ """
+ if self.check_circular:
+ markers = {}
+ else:
+ markers = None
+ return self._iterencode(o, markers)
+
+__all__ = ['JSONEncoder']
diff --git a/tools/addon-sdk-1.7/python-lib/simplejson/scanner.py b/tools/addon-sdk-1.7/python-lib/simplejson/scanner.py
new file mode 100644
index 0000000..2a18390
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/simplejson/scanner.py
@@ -0,0 +1,67 @@
+"""
+Iterator based sre token scanner
+"""
+import re
+from re import VERBOSE, MULTILINE, DOTALL
+import sre_parse
+import sre_compile
+import sre_constants
+from sre_constants import BRANCH, SUBPATTERN
+
+__all__ = ['Scanner', 'pattern']
+
+FLAGS = (VERBOSE | MULTILINE | DOTALL)
+
+class Scanner(object):
+ def __init__(self, lexicon, flags=FLAGS):
+ self.actions = [None]
+ # Combine phrases into a compound pattern
+ s = sre_parse.Pattern()
+ s.flags = flags
+ p = []
+ for idx, token in enumerate(lexicon):
+ phrase = token.pattern
+ try:
+ subpattern = sre_parse.SubPattern(s,
+ [(SUBPATTERN, (idx + 1, sre_parse.parse(phrase, flags)))])
+ except sre_constants.error:
+ raise
+ p.append(subpattern)
+ self.actions.append(token)
+
+ s.groups = len(p) + 1 # NOTE(guido): Added to make SRE validation work
+ p = sre_parse.SubPattern(s, [(BRANCH, (None, p))])
+ self.scanner = sre_compile.compile(p)
+
+ def iterscan(self, string, idx=0, context=None):
+ """
+ Yield match, end_idx for each match
+ """
+ match = self.scanner.scanner(string, idx).match
+ actions = self.actions
+ lastend = idx
+ end = len(string)
+ while True:
+ m = match()
+ if m is None:
+ break
+ matchbegin, matchend = m.span()
+ if lastend == matchend:
+ break
+ action = actions[m.lastindex]
+ if action is not None:
+ rval, next_pos = action(m, context)
+ if next_pos is not None and next_pos != matchend:
+ # "fast forward" the scanner
+ matchend = next_pos
+ match = self.scanner.scanner(string, matchend).match
+ yield rval, matchend
+ lastend = matchend
+
+
+def pattern(pattern, flags=FLAGS):
+ def decorator(fn):
+ fn.pattern = pattern
+ fn.regex = re.compile(pattern, flags)
+ return fn
+ return decorator \ No newline at end of file
diff --git a/tools/addon-sdk-1.7/python-lib/simplejson/tool.py b/tools/addon-sdk-1.7/python-lib/simplejson/tool.py
new file mode 100644
index 0000000..caa1818
--- /dev/null
+++ b/tools/addon-sdk-1.7/python-lib/simplejson/tool.py
@@ -0,0 +1,44 @@
+r"""
+Using simplejson from the shell to validate and
+pretty-print::
+
+ $ echo '{"json":"obj"}' | python -msimplejson
+ {
+ "json": "obj"
+ }
+ $ echo '{ 1.2:3.4}' | python -msimplejson
+ Expecting property name: line 1 column 2 (char 2)
+
+Note that the JSON produced by this module's default settings
+is a subset of YAML, so it may be used as a serializer for that as well.
+"""
+import simplejson
+
+#
+# Pretty printer:
+# curl http://mochikit.com/examples/ajax_tables/domains.json | python -msimplejson.tool
+#
+
+def main():
+ import sys
+ if len(sys.argv) == 1:
+ infile = sys.stdin
+ outfile = sys.stdout
+ elif len(sys.argv) == 2:
+ infile = open(sys.argv[1], 'rb')
+ outfile = sys.stdout
+ elif len(sys.argv) == 3:
+ infile = open(sys.argv[1], 'rb')
+ outfile = open(sys.argv[2], 'wb')
+ else:
+ raise SystemExit("%s [infile [outfile]]" % (sys.argv[0],))
+ try:
+ obj = simplejson.load(infile)
+ except ValueError, e:
+ raise SystemExit(e)
+ simplejson.dump(obj, outfile, sort_keys=True, indent=4)
+ outfile.write('\n')
+
+
+if __name__ == '__main__':
+ main()