Browse files

add 1.9rc1 docset

  • Loading branch information...
1 parent 98c522c commit 5511ccc0d2885cce59600d3f428e7bb6da99964b @wbamberg wbamberg committed Jul 31, 2012
Showing with 4,019 additions and 1,569 deletions.
  1. +8 −4 dev-guide-source/cfx-tool.md
  2. +1 −0 dev-guide-source/credits.md
  3. +3 −85 dev-guide-source/guides/content-scripts/{access.md → accessing-the-dom.md}
  4. +246 −0 dev-guide-source/guides/content-scripts/communicating-with-other-scripts.md
  5. +7 −5 dev-guide-source/guides/content-scripts/index.md
  6. +44 −0 dev-guide-source/guides/content-scripts/using-postmessage.md
  7. +16 −6 dev-guide-source/guides/index.md
  8. +1 −2 dev-guide-source/guides/library-detector.md
  9. +2 −2 dev-guide-source/tutorials/adding-menus.md
  10. +5 −10 dev-guide-source/tutorials/adding-toolbar-button.md
  11. +1 −1 dev-guide-source/tutorials/annotator/widget.md
  12. +17 −17 dev-guide-source/tutorials/getting-started-with-cfx.md
  13. +1 −1 dev-guide-source/tutorials/logging.md
  14. +1 −1 dev-guide-source/tutorials/modifying-web-pages-tab.md
  15. +1 −1 dev-guide-source/tutorials/modifying-web-pages-url.md
  16. +1 −1 dev-guide-source/tutorials/reusable-modules.md
  17. +28 −31 dev-guide-source/tutorials/unit-testing.md
  18. +14 −7 dev-guide/cfx-tool.html
  19. +7 −3 dev-guide/console.html
  20. +8 −3 dev-guide/credits.html
  21. +7 −3 dev-guide/glossary.html
  22. +7 −3 dev-guide/guides/commonjs.html
  23. +12 −87 dev-guide/guides/content-scripts/{access.html → accessing-the-dom.html}
  24. +537 −0 dev-guide/guides/content-scripts/communicating-with-other-scripts.html
  25. +14 −8 dev-guide/guides/content-scripts/index.html
  26. +7 −3 dev-guide/guides/content-scripts/loading.html
  27. +7 −3 dev-guide/guides/content-scripts/reddit-example.html
  28. +7 −3 dev-guide/guides/content-scripts/using-port.html
  29. +45 −3 dev-guide/guides/content-scripts/using-postmessage.html
  30. +7 −3 dev-guide/guides/events.html
  31. +7 −3 dev-guide/guides/firefox-compatibility.html
  32. +24 −11 dev-guide/guides/index.html
  33. +8 −5 dev-guide/guides/library-detector.html
  34. +7 −3 dev-guide/guides/module-search.html
  35. +7 −3 dev-guide/guides/program-id.html
  36. +7 −3 dev-guide/guides/sdk-vs-xul.html
  37. +7 −3 dev-guide/guides/two-types-of-scripts.html
  38. +7 −3 dev-guide/guides/xul-migration.html
  39. +7 −3 dev-guide/high-level-apis.html
  40. +7 −3 dev-guide/index.html
  41. +7 −3 dev-guide/low-level-apis.html
  42. +7 −3 dev-guide/package-spec.html
  43. +7 −3 dev-guide/third-party-apis.html
  44. +7 −3 dev-guide/tutorials/add-a-context-menu-item.html
  45. +9 −5 dev-guide/tutorials/adding-menus.html
  46. +12 −12 dev-guide/tutorials/adding-toolbar-button.html
  47. +7 −3 dev-guide/tutorials/annotator/creating.html
  48. +7 −3 dev-guide/tutorials/annotator/displaying.html
  49. +7 −3 dev-guide/tutorials/annotator/index.html
  50. +7 −3 dev-guide/tutorials/annotator/overview.html
  51. +7 −3 dev-guide/tutorials/annotator/storing.html
  52. +8 −4 dev-guide/tutorials/annotator/widget.html
  53. +7 −3 dev-guide/tutorials/chrome.html
  54. +7 −3 dev-guide/tutorials/display-a-popup.html
  55. +23 −19 dev-guide/tutorials/getting-started-with-cfx.html
  56. +7 −3 dev-guide/tutorials/index.html
  57. +7 −3 dev-guide/tutorials/installation.html
  58. +7 −3 dev-guide/tutorials/l10n.html
  59. +7 −3 dev-guide/tutorials/list-open-tabs.html
  60. +7 −3 dev-guide/tutorials/listen-for-page-load.html
  61. +7 −3 dev-guide/tutorials/load-and-unload.html
  62. +8 −4 dev-guide/tutorials/logging.html
  63. +7 −3 dev-guide/tutorials/mobile.html
  64. +8 −4 dev-guide/tutorials/modifying-web-pages-tab.html
  65. +8 −4 dev-guide/tutorials/modifying-web-pages-url.html
  66. +7 −3 dev-guide/tutorials/open-a-web-page.html
  67. +8 −4 dev-guide/tutorials/reusable-modules.html
  68. +7 −3 dev-guide/tutorials/troubleshooting.html
  69. +35 −34 dev-guide/tutorials/unit-testing.html
  70. +7 −3 index.html
  71. +7 −3 packages/addon-kit/addon-page.html
  72. +35 −7 packages/addon-kit/clipboard.html
  73. +7 −3 packages/addon-kit/context-menu.html
  74. +7 −3 packages/addon-kit/hotkeys.html
  75. +7 −3 packages/addon-kit/index.html
  76. +7 −3 packages/addon-kit/l10n.html
  77. +7 −3 packages/addon-kit/notifications.html
  78. +7 −3 packages/addon-kit/page-mod.html
  79. +7 −3 packages/addon-kit/page-worker.html
  80. +7 −3 packages/addon-kit/panel.html
  81. +7 −3 packages/addon-kit/passwords.html
  82. +7 −3 packages/addon-kit/private-browsing.html
  83. +7 −3 packages/addon-kit/request.html
  84. +7 −3 packages/addon-kit/selection.html
  85. +7 −3 packages/addon-kit/self.html
  86. +7 −3 packages/addon-kit/simple-prefs.html
  87. +7 −3 packages/addon-kit/simple-storage.html
  88. +7 −3 packages/addon-kit/tabs.html
  89. +7 −3 packages/addon-kit/timers.html
  90. +7 −3 packages/addon-kit/widget.html
  91. +55 −3 packages/addon-kit/windows.html
  92. +7 −3 packages/api-utils/api-utils.html
  93. +7 −3 packages/api-utils/app-strings.html
  94. +403 −0 packages/api-utils/base64.html
  95. +7 −3 packages/api-utils/byte-streams.html
  96. +7 −3 packages/api-utils/collection.html
  97. +7 −3 packages/api-utils/content.html
  98. +7 −3 packages/api-utils/content/loader.html
  99. +7 −3 packages/api-utils/content/proxy.html
  100. +7 −3 packages/api-utils/content/symbiont.html
  101. +7 −3 packages/api-utils/content/worker.html
  102. +7 −3 packages/api-utils/cortex.html
  103. +7 −3 packages/api-utils/cuddlefish.html
  104. +7 −3 packages/api-utils/environment.html
  105. +7 −3 packages/api-utils/errors.html
  106. +7 −3 packages/api-utils/event/core.html
  107. +7 −3 packages/api-utils/event/target.html
  108. +7 −3 packages/api-utils/events.html
  109. +7 −3 packages/api-utils/file.html
  110. +7 −3 packages/api-utils/frame/utils.html
  111. +7 −3 packages/api-utils/globals.html
  112. +7 −3 packages/api-utils/heritage.html
  113. +7 −3 packages/api-utils/hidden-frame.html
  114. +7 −3 packages/api-utils/httpd.html
  115. +13 −5 packages/api-utils/index.html
  116. +7 −3 packages/api-utils/light-traits.html
  117. +7 −3 packages/api-utils/list.html
  118. +786 −0 packages/api-utils/loader.html
  119. +7 −3 packages/api-utils/match-pattern.html
  120. +7 −3 packages/api-utils/memory.html
  121. +7 −3 packages/api-utils/message-manager.html
  122. +7 −3 packages/api-utils/namespace.html
  123. +7 −3 packages/api-utils/observer-service.html
  124. +7 −3 packages/api-utils/plain-text-console.html
  125. +23 −3 packages/api-utils/preferences-service.html
  126. +7 −3 packages/api-utils/promise.html
  127. +7 −3 packages/api-utils/querystring.html
  128. +7 −3 packages/api-utils/runtime.html
  129. +7 −3 packages/api-utils/sandbox.html
  130. +7 −3 packages/api-utils/tab-browser.html
  131. +704 −0 packages/api-utils/test/assert.html
  132. +7 −3 packages/api-utils/text-streams.html
  133. +7 −3 packages/api-utils/traceback.html
  134. +7 −3 packages/api-utils/traits.html
  135. +0 −811 packages/api-utils/unit-test.html
  136. +19 −32 packages/api-utils/unload.html
  137. +73 −3 packages/api-utils/url.html
  138. +7 −3 packages/api-utils/uuid.html
  139. +9 −4 packages/api-utils/window-utils.html
  140. +14 −7 packages/api-utils/window/utils.html
  141. +7 −3 packages/api-utils/xhr.html
  142. +7 −3 packages/api-utils/xpcom.html
  143. +7 −3 packages/api-utils/xul-app.html
  144. +1 −1 packages/index.json
  145. +7 −3 packages/test-harness/harness.html
  146. +7 −3 packages/test-harness/index.html
  147. +7 −3 packages/test-harness/run-tests.html
  148. +7 −5 static-files/css/base.css
  149. +9 −1 static-files/css/sdk-docs.css
  150. +3 −5 static-files/js/main.js
  151. +1 −1 status.md5
View
12 dev-guide-source/cfx-tool.md
@@ -292,10 +292,14 @@ modules called "test_myCode.js" or "testMyCode.js".</span>
Called with no options this command will look for a file called `package.json`
in the current directory. If `package.json` exists, `cfx` will load the
-corresponding add-on and run its tests by loading from the `tests` directory
-any modules that start with the word `test-` and calling each of their exported
-functions, passing them a [test runner](packages/api-utils/unit-test.html)
-object as an argument.
+corresponding add-on, load from the `tests` directory
+any modules that start with the word `test-` and run the unit tests
+they contain.
+
+See the
+[tutorial on unit testing](dev-guide/tutorials/unit-testing.html) and the
+[reference documentation for the `assert` module](packages/api-utils/test/assert.html)
+for details.
#### Supported Options #####
View
1 dev-guide-source/credits.md
@@ -64,3 +64,4 @@ We'd like to thank our many Jetpack project contributors! They include:
* [David Guo](https://github.com/dglol)
* [Nils Maier](https://github.com/nmaier)
* [Louis-Rémi Babé](https://github.com/louisremi)
+* [Matthias Tylkowski](https://github.com/tylkomat)
View
88 ...e-source/guides/content-scripts/access.md → ...ides/content-scripts/accessing-the-dom.md
@@ -2,15 +2,10 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
-# Content Script Access #
+# Accessing the DOM #
-This page talks about the access content scripts have to:
-
-* DOM objects in the pages they are attached to
-* other content scripts
-* other scripts loaded by the page they are attached to
-
-## Access to the DOM ##
+This page talks about the access content scripts have to DOM objects
+in the pages they are attached to.
Content scripts need to be able to access DOM objects in arbitrary web
pages, but this could cause two potential security problems:
@@ -127,80 +122,3 @@ Greasemonkey's unsafeWindow, and the
[warnings for that](http://wiki.greasespot.net/UnsafeWindow) apply equally
here. Also, `unsafeWindow` isn't a supported API, so it could be removed or
changed in a future version of the SDK.
-
-## Access to Other Content Scripts ##
-
-Content scripts loaded into the same document can interact
-with each other directly as well as with the web content itself. However,
-content scripts which have been loaded into different documents
-cannot interact with each other.
-
-For example:
-
-* if an add-on creates a single `panel` object and loads several content
-scripts into the panel, then they can interact with each other
-
-* if an add-on creates two `panel` objects and loads a script into each
-one, they can't interact with each other.
-
-* if an add-on creates a single `page-mod` object and loads several content
-scripts into the page mod, then only content scripts associated with the
-same page can interact with each other: if two different matching pages are
-loaded, content scripts attached to page A cannot interact with those attached
-to page B.
-
-The web content has no access to objects created by the content script, unless
-the content script explicitly makes them available.
-
-## Access to Page Scripts ##
-
-You can communicate between the content script and page scripts using
-[`postMessage()`](https://developer.mozilla.org/en/DOM/window.postMessage),
-but there's a twist: in early versions of the SDK, the global `postMessage()`
-function in content scripts was used for communicating between the content
-script and the main add-on code. Although this has been
-[deprecated in favor of `self.postMessage`](https://wiki.mozilla.org/Labs/Jetpack/Release_Notes/1.0b5#Major_Changes),
-the old globals are still supported, so you can't currently use
-`window.postMessage()`. You must use `document.defaultView.postMessage()`
-instead.
-
-The following page script uses
-[`window.addEventListener`](https://developer.mozilla.org/en/DOM/element.addEventListener)
-to listen for messages:
-
-<script type="syntaxhighlighter" class="brush: html"><![CDATA[
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html lang='en' xml:lang='en' xmlns="http://www.w3.org/1999/xhtml">
-
- <head>
- <script>
- window.addEventListener("message", function(event) {
- window.alert(event.data);
- }, false);
- &lt;/script>
-
- </head>
-
-</html>
-
-</script>
-
-Content scripts can send it messages using `document.defaultView.postMessage()`:
-
- var widgets = require("widget");
- var tabs = require("tabs");
- var data = require("self").data;
-
- var widget = widgets.Widget({
- id: "postMessage",
- label: "demonstrate document.defaultView.postMessage",
- contentURL: "http://www.mozilla.org/favicon.ico",
- onClick: function() {
- tabs.activeTab.attach({
- contentScript: "document.defaultView.postMessage('hi there!', '*');"
- });
- }
- });
-
- tabs.open(data.url("listener.html"));
View
246 dev-guide-source/guides/content-scripts/communicating-with-other-scripts.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/. -->
+
+# Communicating With Other Scripts #
+
+This section of the guide explains how content scripts can
+communicate with:
+
+* [your `main.js` file](dev-guide/guides/content-scripts/communicating-with-other-scripts.html#main.js),
+or any other modules in your add-on
+* [other content scripts loaded by your add-on](dev-guide/guides/content-scripts/communicating-with-other-scripts.html#Content Scripts)
+* [page scripts](dev-guide/guides/content-scripts/communicating-with-other-scripts.html#Page Scripts) (that is, scripts embedded in the web page or
+included using `<script>` tags)
+
+## main.js ##
+
+Your content scripts can communicate with your add-on's "main.js"
+(or any other modules you're written for your add-on) by sending it messages,
+using either the `port.emit()` API or the `postMessage()` API. See the
+articles on
+[using `postMessage()`](dev-guide/guides/content-scripts/using-postmessage.html)
+and
+[using `port`](dev-guide/guides/content-scripts//using-port.html) for details.
+
+## Content Scripts ##
+
+Content scripts loaded into the same document can interact
+with each other directly as well as with the web content itself. However,
+content scripts which have been loaded into different documents
+cannot interact with each other.
+
+For example:
+
+* if an add-on creates a single `panel` object and loads several content
+scripts into the panel, then they can interact with each other
+* if an add-on creates two `panel` objects and loads a script into each
+one, they can't interact with each other.
+* if an add-on creates a single `page-mod` object and loads several content
+scripts into the page mod, then only content scripts associated with the
+same page can interact with each other: if two different matching pages are
+loaded, content scripts attached to page A cannot interact with those attached
+to page B.
+
+The web content has no access to objects created by the content script, unless
+the content script explicitly makes them available.
+
+## Page Scripts ##
+
+If a page includes its own scripts using `<script>` tags,
+either embedded in the page or linked to it using the `src` attribute, there
+are a couple of ways a content script can communicate with it:
+
+* using the [DOM `postMessage()` API](dev-guide/guides/content-scripts/communicating-with-other-scripts.html#Using the DOM postMessage API)
+* using [custom DOM events](dev-guide/guides/content-scripts/communicating-with-other-scripts.html#Using Custom DOM Events)
+
+### Using the DOM postMessage API ###
+
+You can communicate between the content script and page scripts using
+[`window.postMessage()`](https://developer.mozilla.org/en/DOM/window.postMessage),
+but there's a twist: in early versions of the SDK, the global `postMessage()`
+function in content scripts was used for communicating between the content
+script and the main add-on code. Although this has been
+[deprecated in favor of `self.postMessage`](https://wiki.mozilla.org/Labs/Jetpack/Release_Notes/1.0b5#Major_Changes),
+the old globals are still supported, so you can't currently use
+`window.postMessage()`. You must use `document.defaultView.postMessage()`
+instead.
+
+#### Messaging From Content Script To Page Script ####
+
+Suppose we have a page called "listen.html" hosted at "my-domain.org", and we want to send messages
+from the add-on to a script embedded in that page.
+
+In the main add-on code, we have a
+[`page-mod`](packages/addon-kit/page-mod.html) that attaches the content script
+"talk.js" to the right page:
+
+ var data = require("self").data;
+
+ var pageMod = require("page-mod");
+ pageMod.PageMod({
+ include: "http://my-domain.org/listen.html",
+ contentScriptFile: data.url("talk.js")
+ });
+
+The "talk.js" content script uses `document.defaultView.postMessage()` to send
+the message to the page:
+
+ document.defaultView.postMessage("Message from content script", "http://my-domain.org/");
+
+The second argument may be '*' which will allow communication with any domain.
+
+Finally, "listen.html" uses `window.addEventListener()` to listen for
+messages from the content script:
+
+<script type="syntaxhighlighter" class="brush: html"><![CDATA[
+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+ &lt;head&gt;&lt;/head&gt;
+ &lt;body&gt;
+ &lt;script&gt;
+ window.addEventListener('message', function(event) {
+ window.alert(event.data);
+ }, false);
+ &lt;/script&gt;
+ &lt;/body&gt;
+
+&lt;/html&gt;
+]]>
+</script>
+
+#### Messaging From Page Script To Content Script ####
+
+Sending messages from the page script to the content script is just
+the same, but in reverse.
+
+Here "main.js" creates a [`page-mod`](packages/addon-kit/page-mod.html)
+that attaches "listen.js" to the web page:
+
+ var data = require("self").data;
+
+ var pageMod = require("page-mod");
+ pageMod.PageMod({
+ include: "http://my-domain.org/talk.html",
+ contentScriptFile: data.url("listen.js")
+ });
+
+The web page "talk.html" embeds a script that uses `window.postMessage()`
+to send the content script a message when the user clicks a button:
+
+<script type="syntaxhighlighter" class="brush: html"><![CDATA[
+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+ &lt;head&gt;&lt;/head&gt;
+ &lt;body&gt;
+ &lt;script&gt;
+ function sendMessage() {
+ window.postMessage("Message from page script", "http://my-domain.org/");
+ }
+ &lt;/script&gt;
+ &lt;button onclick="sendMessage()"&gt;Send Message&lt;/button&gt;
+ &lt;/body&gt;
+
+&lt;/html&gt;
+</script>
+
+Finally, the content script "listen.js" uses
+`document.defaultView.addEventListener()` to listen for messages from the page
+script:
+
+ document.defaultView.addEventListener('message', function(event) {
+ console.log(event.data);
+ console.log(event.origin);
+ }, false);
+
+### Using Custom DOM Events ###
+
+As an alternative to using `postMessage()` you can use
+[custom DOM events](https://developer.mozilla.org/en/DOM/CustomEvent)
+to communicate between page scripts and content scripts.
+
+#### Messaging From Content Script To Page Script ####
+
+Here's an example showing how to use custom DOM events to send a message
+from a content script to a page script.
+
+First, "main.js" will create a [`page-mod`](packages/addon-kit/page-mod.html)
+that will attach "talk.js" to the target web page:
+
+ var data = require("self").data;
+
+ var pageMod = require("page-mod");
+ pageMod.PageMod({
+ include: "http://my-domain.org/listen.html",
+ contentScriptFile: data.url("talk.js")
+ });
+
+Next, "talk.js" creates and dispatches a custom event, passing the payload
+in the `detail` parameter to `initCustomEvent()`:
+
+<!-- This comment is used to terminate the Markdown list above -->
+
+ var event = document.createEvent('CustomEvent');
+ event.initCustomEvent("addon-message", true, true, { hello: 'world' });
+ document.documentElement.dispatchEvent(event);
+
+Finally "listen.html" listens for the new event and examines its
+`detail` attribute to retrieve the payload:
+
+<script type="syntaxhighlighter" class="brush: html"><![CDATA[
+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+ &lt;head&gt;&lt;/head&gt;
+ &lt;body&gt;
+ &lt;script&gt;
+ document.documentElement.addEventListener("addon-message", function(event) {
+ window.alert(JSON.stringify(event.detail))
+ }, false);
+ &lt;/script&gt;
+ &lt;/body&gt;
+&lt;/html&gt;
+</script>
+
+#### Messaging From Page Script to Content Script ####
+
+Sending messages using custom DOM events from the page script
+to the content script is just the same, but in reverse.
+
+Again, "main.js" creates a [`page-mod`](packages/addon-kit/page-mod.html)
+to target the page we are interested in:
+
+ var data = require("self").data;
+
+ var pageMod = require("page-mod");
+ pageMod.PageMod({
+ include: "http://my-domain.org/talk.html",
+ contentScriptFile: data.url("listen.js")
+ });
+
+The web page "talk.html" creates and dispatches a custom DOM event,
+using `initCustomEvent()`'s `detail` parameter to supply the payload:
+
+<script type="syntaxhighlighter" class="brush: html"><![CDATA[
+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+ &lt;head&gt;&lt;/head&gt;
+ &lt;body&gt;
+ &lt;script&gt;
+ function sendMessage() {
+ var event = document.createEvent('CustomEvent');
+ event.initCustomEvent("addon-message", true, true, { hello: 'world' });
+ document.documentElement.dispatchEvent(event);
+ }
+ &lt;/script&gt;
+ &lt;button onclick="sendMessage()"&gt;Send Message&lt;/button&gt;
+ &lt;/body&gt;
+&lt;/html&gt;
+</script>
+
+Finally, the content script "listen.js" listens for the new event
+and retrieves the payload from its `detail` attribute:
+
+ document.documentElement.addEventListener("addon-message", function(event) {
+ console.log(JSON.stringify(event.detail));
+ }, false);
+
View
12 dev-guide-source/guides/content-scripts/index.md
@@ -41,8 +41,8 @@ _content scripts_.
A single add-on may use multiple content scripts, and content scripts loaded
into the same context can interact directly with each other as well as with
the web content itself. See the chapter on
-<a href="dev-guide/guides/content-scripts/access.html">
-content script access</a>.
+<a href="dev-guide/guides/content-scripts/communicating-with-other-scripts.html">
+communicating with other scripts</a>.
The add-on script and content script can't directly access each other's state.
Instead, you can define your own events which each side can emit, and the
@@ -78,9 +78,11 @@ The next few chapters explain content scripts in detail:
* [Loading Content Scripts](dev-guide/guides/content-scripts/loading.html):
how to attach content scripts to web pages, and how to control the point at
which they are executed
-* [Content Script Access](dev-guide/guides/content-scripts/access.html):
-detail about the access content scripts get to the DOM, to other content scripts,
-and to scripts loaded by the page itself
+* [Accessing the DOM](dev-guide/guides/content-scripts/accessing-the-dom.html):
+detail about the access content scripts get to the DOM
+* [Communicating With Other Scripts](dev-guide/guides/content-scripts/communicating-with-other-scripts.html):
+detail about how content scripts can communicate with "main.js", with other
+content scripts, and with scripts loaded by the web page itself
* [Communicating Using <code>port</code>](dev-guide/guides/content-scripts/using-port.html):
how to communicate between your add-on and its content scripts using the
<code>port</code> object
View
44 dev-guide-source/guides/content-scripts/using-postmessage.md
@@ -59,6 +59,50 @@ argument to the constructor:
}
});
+## Timing Issues Using postMessage ##
+
+Content scripts are loaded according to the value of the
+[`contentScriptWhen`](dev-guide/guides/content-scripts/loading.html)
+option: until that point is reached, any attempt to send a message to
+the script using `postMessage()` will trigger an exception, probably
+the unintuitive message:
+
+<span class="aside">
+This is a generic message which is emitted whenever we try to
+send a message to a content script, but can't find the worker
+which is supposed to receive it.
+</span>
+
+<pre>
+Error: The page has been destroyed and can no longer be used.
+</pre>
+
+So code like this, where we create a panel and then
+synchronously send it a message using `postMessage()`, will not work:
+
+ var data = require("self").data;
+
+ var panel = require("panel").Panel({
+ contentURL: "http://www.bbc.co.uk/mobile/index.html",
+ contentScriptFile: data.url("panel.js")
+ });
+
+ panel.postMessage("hi from main.js");
+
+[`port.emit()`](dev-guide/guides/content-scripts/using-port.html)
+queues messages until the content script is ready to receive them,
+so the equivalent code using `port.emit()` will work:
+
+ var data = require("self").data;
+
+ var panel = require("panel").Panel({
+ contentURL: "http://www.bbc.co.uk/mobile/index.html",
+ contentScriptFile: data.url("panel.js")
+ });
+
+ panel.port.emit("hi from main.js");
+
+
## Message Events Versus User-Defined Events ##
You can use message events as an alternative to user-defined events:
View
22 dev-guide-source/guides/index.md
@@ -102,28 +102,38 @@ This page lists more theoretical in-depth articles about the SDK.
<tr>
<td>
- <h4><a href="dev-guide/guides/content-scripts/access.html">Content script access</a></h4>
- Detailed information on the objects available to content scripts,
- the differences between content scripts and normal page scripts,
- and how to communicate between content scripts and page scripts.
+ <h4><a href="dev-guide/guides/content-scripts/accessing-the-dom.html">Accessing the DOM</a></h4>
+ Detail about the access content scripts get to the DOM.
</td>
<td>
+ <h4><a href="dev-guide/guides/content-scripts/communicating-with-other-scripts.html">Communicating with other scripts</a></h4>
+ Detail about how content scripts can communicate with "main.js", with other
+ content scripts, and with scripts loaded by the web page itself.
+ </td>
+
+ </tr>
+
+ <tr>
+
+ <td>
<h4><a href="dev-guide/guides/content-scripts/using-port.html">Using "port"</a></h4>
Communicating between a content script and the rest of your add-on
using the <code>port</code> object.
</td>
- </tr>
- <tr>
<td>
<h4><a href="dev-guide/guides/content-scripts/using-postmessage.html">Using "postMessage()"</a></h4>
Communicating between a content script and the rest of your add-on
using the <code>postMessage()</code> API, and a comparison between
this technique and the <code>port</code> object.
</td>
+ </tr>
+
+ <tr>
+
<td>
<h4><a href="dev-guide/guides/content-scripts/reddit-example.html">Reddit example</a></h4>
A simple add-on which uses content scripts.
View
3 dev-guide-source/guides/library-detector.md
@@ -69,8 +69,7 @@ of the box for that window.
The test objects in the original script need access to the DOM window object,
so in the SDK port, they need to run in a content script. In fact, they need
access to the un-proxied DOM window, so they can see the objects added by
-libraries, so we’ll need to use the experimental
-[unsafeWindow](dev-guide/guides/content-scripts/access.html) object.
+libraries, so we’ll need to use the experimental [unsafeWindow](dev-guide/guides/content-scripts/accessing-the-dom.html#unsafeWindow)
The main add-on script, `main.js`, will use a
[`page-mod`](packages/addon-kit/page-mod.html)
View
4 dev-guide-source/tutorials/adding-menus.md
@@ -70,8 +70,8 @@ this minimal set:
appear
Next, create a new add-on. Make a directory called 'clickme' wherever you
-like, navigate to it and run `cfx init`. Open `lib/main.js` and replace its contents
-with this:
+like, navigate to it and run `cfx init`. Open `lib/main.js` and add the
+following code:
var menuitem = require("menuitems").Menuitem({
id: "clickme",
View
15 dev-guide-source/tutorials/adding-toolbar-button.md
@@ -14,17 +14,12 @@ and learned the
To add a button to the toolbar, use the
[`widget`](packages/addon-kit/widget.html) module.
-The default add-on created by `cfx init`
-uses a widget, so we'll start with that as an example. If you haven't already
-followed the tutorial introducing
-[`cfx init`](dev-guide/tutorials/getting-started-with-cfx.html#cfx-init),
-do that now, then come back here.
+Create a new directory, navigate to it, and execute `cfx init`.
+Then open the file called "main.js" in the "lib" directory and
+add the following code to it:
-Create a new directory, navigate to it, and execute `cfx init`. Then open the file called
-"main.js" in the "lib" directory:
-
- const widgets = require("widget");
- const tabs = require("tabs");
+ var widgets = require("widget");
+ var tabs = require("tabs");
var widget = widgets.Widget({
id: "mozilla-link",
View
2 dev-guide-source/tutorials/annotator/widget.md
@@ -57,7 +57,7 @@ You can copy the widget's icons from here:
## main.js ##
-Now in the `lib` directory open `main.js` and replace its contents with this:
+Now in the `lib` directory open `main.js` and add the following code:
var widgets = require('widget');
var data = require('self').data;
View
34 dev-guide-source/tutorials/getting-started-with-cfx.md
@@ -63,8 +63,23 @@ You'll see some output like this:
Use `cfx run` to run a new instance of Firefox with your add-on installed.
This is the command you'll use to test out your add-on while developing it.
-`cfx init` actually creates a very basic add-on, so to see `cfx run` in action
-we don't need to write any code. Just type:
+The main code for an add-on is always kept in a file called `main.js` in your
+add-on's `lib` directory. Open the `main.js` for this add-on, and
+add the following code:
+
+ var widgets = require("widget");
+ var 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/");
+ }
+ });
+
+Now type:
<pre>
cfx run
@@ -85,21 +100,6 @@ bottom-right corner of the browser you'll see an icon with the Firefox
logo. Click the icon, and a new tab will open with
[http://www.mozilla.org/](http://www.mozilla.org/) loaded into it.
-The main code for an add-on is always kept in a file called `main.js` in your
-add-on's `lib` directory. Open the `main.js` for this add-on:
-
- 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/");
- }
- });
-
This add-on uses two SDK modules: the
[`widget`](packages/addon-kit/widget.html) module, which enables you
to add buttons to the browser, and the
View
2 dev-guide-source/tutorials/logging.md
@@ -27,7 +27,7 @@ Try it out:
* create a new directory, and navigate to it
* execute `cfx init`
-* open "lib/main.js" and replace its contents with the line above
+* open "lib/main.js" and add the line above
* execute `cfx run`, then `cfx run` again
Firefox will start, and the following line will appear in the command
View
2 dev-guide-source/tutorials/modifying-web-pages-tab.md
@@ -41,7 +41,7 @@ a red border around the page. Try it out:
* create a new directory and navigate to it
* run `cfx init`
-* open the `lib/main.js` file, and replace its contents with the code above
+* open the `lib/main.js` file, and add the code above
* run `cfx run`, then run `cfx run` again
You should see the Mozilla icon appear in the bottom-right corner of the
View
2 dev-guide-source/tutorials/modifying-web-pages-url.md
@@ -40,7 +40,7 @@ Try it out:
* create a new directory and navigate to it
* run `cfx init`
-* open the `lib/main.js` file, and replace its contents with the code above
+* open the `lib/main.js` file, and add the code above
* run `cfx run`, then run `cfx run` again
* open [ietf.org](http://www.ietf.org) in the browser window that opens
View
2 dev-guide-source/tutorials/reusable-modules.md
@@ -70,7 +70,7 @@ Try it out:
* create a new directory called "whereami" and navigate to it
* execute `cfx init`
-* open "lib/main.js" and replace its contents with the code above
+* open "lib/main.js" and add the code above
* execute `cfx run`, then `cfx run` again
You should see a button added to the "Add-on Bar" at the bottom of
View
59 dev-guide-source/tutorials/unit-testing.md
@@ -81,41 +81,38 @@ In its place create a file called `test-base64.js` with the following
contents:
<pre><code>
-var base64 = require("base64")
+var base64 = require("base64");
-function test_atob(test) {
- test.assertEqual(base64.atob("aGVsbG8="), "hello");
- test.done();
+exports["test atob"] = function(assert) {
+ assert.ok(base64.atob("aGVsbG8=") == "hello", "atob works");
}
-function test_btoa(test) {
- test.assertEqual(base64.btoa("hello"), "aGVsbG8=");
- test.done();
+exports["test btoa"] = function(assert) {
+ assert.ok(base64.btoa("hello") == "aGVsbG8=", "btoa works");
}
-function test_empty_string(test) {
- test.assertRaises(function() {
- base64.atob();
- },
- "String contains an invalid character");
-};
+exports["test empty string"] = function(assert) {
+ assert.throws(function() {
+ base64.atob();
+ },
+ "empty string check works");
+}
-exports.test_atob = test_atob;
-exports.test_btoa = test_btoa;
-exports.test_empty_string = test_empty_string;
+require("test").run(exports);
</code></pre>
This file: exports three functions, each of which expects to receive a single
-argument which is a `test` object. `test` is supplied by the
-[`unit-test`](packages/api-utils/unit-test.html) module and provides
-functions to simplify unit testing.
+argument which is an `assert` object. `assert` is supplied by the
+[`test/assert`](packages/api-utils/test/assert.html) module and implements
+the [CommonJS Unit Testing specification](http://wiki.commonjs.org/wiki/Unit_Testing/1.1).
-* The first two functions call `atob()` and `btoa()` and use [`test.assertEqual()`](packages/api-utils/unit-test.html#assertEqual(a, b, message))
+* The first two functions call `atob()` and `btoa()` and use
+[`assert.ok()`](packages/api-utils/test/assert.html)
to check that the output is as expected.
* The second function tests the module's error-handling code by passing an
empty string into `atob()` and using
-[`test.assertRaises()`](packages/api-utils/unit-test.html#assertRaises(func, predicate, message))
+[`assert.throws()`](packages/api-utils/test/assert.html)
to check that the expected exception is raised.
At this point your add-on ought to look like this:
@@ -137,16 +134,16 @@ Now execute `cfx --verbose test` from the add-on's root directory.
You should see something like this:
<pre>
-Running tests on Firefox 10.0/Gecko 10.0 ({ec8030f7-c20a-464f-9b0e-13a3a9e97384}) under darwin/x86.
-info: executing 'test-base64.test_atob'
-info: pass: a == b == "hello"
-info: executing 'test-base64.test_btoa'
-info: pass: a == b == "aGVsbG8="
-info: executing 'test-base64.test_empty_string'
-info: pass: a == b == "String contains an invalid character"
+Running tests on Firefox 13.0/Gecko 13.0 ({ec8030f7-c20a-464f-9b0e-13a3a9e97384}) under darwin/x86.
+info: executing 'test-base64.test atob'
+info: pass: atob works
+info: executing 'test-base64.test btoa'
+info: pass: btoa works
+info: executing 'test-base64.test empty string'
+info: pass: empty string check works
3 of 3 tests passed.
-Total time: 1.691787 seconds
+Total time: 5.172589 seconds
Program terminated successfully.
</pre>
@@ -159,8 +156,8 @@ modules called "test_myCode.js" or "testMyCode.js".</span>
* looks in the `test` directory of your
package
* loads any modules whose names start with the word `test-`
-* calls all their exported functions, passing them a `test` object
-implementation as their only argument.
+* calls each exported function whose name starts with "test", passing it
+an [`assert`](packages/api-utils/test/assert.html) object as its only argument.
Obviously, you don't have to pass the `--verbose` option to `cfx` if you don't
want to; doing so just makes the output easier to read.
View
21 dev-guide/cfx-tool.html
@@ -50,7 +50,7 @@
<h1>
<a href="../dev-guide/index.html">Add-on SDK<span></span></a>
</h1>
- <div id="version">Version 1.8</div>
+ <div id="version">Version 1.9</div>
</div>
</div>
@@ -332,10 +332,13 @@
modules called "test_myCode.js" or "testMyCode.js".</span></p>
<p>Called with no options this command will look for a file called <code>package.json</code>
in the current directory. If <code>package.json</code> exists, <code>cfx</code> will load the
-corresponding add-on and run its tests by loading from the <code>tests</code> directory
-any modules that start with the word <code>test-</code> and calling each of their exported
-functions, passing them a <a href="../packages/api-utils/unit-test.html">test runner</a>
-object as an argument.</p>
+corresponding add-on, load from the <code>tests</code> directory
+any modules that start with the word <code>test-</code> and run the unit tests
+they contain.</p>
+<p>See the
+<a href="../dev-guide/tutorials/unit-testing.html">tutorial on unit testing</a> and the
+<a href="../packages/api-utils/test/assert.html">reference documentation for the <code>assert</code> module</a>
+for details.</p>
<h4>Supported Options</h4>
<p>As with <code>cfx run</code> you can use options to control which host application binary
version to use, and to select a profile.</p>
@@ -953,6 +956,8 @@
<a href="../packages/api-utils/app-strings.html">app-strings</a>
+<a href="../packages/api-utils/base64.html">base64</a>
+
<a href="../packages/api-utils/byte-streams.html">byte-streams</a>
<a href="../packages/api-utils/collection.html">collection</a>
@@ -997,6 +1002,8 @@
<a href="../packages/api-utils/list.html">list</a>
+<a href="../packages/api-utils/loader.html">loader</a>
+
<a href="../packages/api-utils/match-pattern.html">match-pattern</a>
<a href="../packages/api-utils/memory.html">memory</a>
@@ -1021,14 +1028,14 @@
<a href="../packages/api-utils/tab-browser.html">tab-browser</a>
+<a href="../packages/api-utils/test/assert.html">test/assert</a>
+
<a href="../packages/api-utils/text-streams.html">text-streams</a>
<a href="../packages/api-utils/traceback.html">traceback</a>
<a href="../packages/api-utils/traits.html">traits</a>
-<a href="../packages/api-utils/unit-test.html">unit-test</a>
-
<a href="../packages/api-utils/unload.html">unload</a>
<a href="../packages/api-utils/url.html">url</a>
View
10 dev-guide/console.html
@@ -50,7 +50,7 @@
<h1>
<a href="../dev-guide/index.html">Add-on SDK<span></span></a>
</h1>
- <div id="version">Version 1.8</div>
+ <div id="version">Version 1.9</div>
</div>
</div>
@@ -181,6 +181,8 @@
<a href="../packages/api-utils/app-strings.html">app-strings</a>
+<a href="../packages/api-utils/base64.html">base64</a>
+
<a href="../packages/api-utils/byte-streams.html">byte-streams</a>
<a href="../packages/api-utils/collection.html">collection</a>
@@ -225,6 +227,8 @@
<a href="../packages/api-utils/list.html">list</a>
+<a href="../packages/api-utils/loader.html">loader</a>
+
<a href="../packages/api-utils/match-pattern.html">match-pattern</a>
<a href="../packages/api-utils/memory.html">memory</a>
@@ -249,14 +253,14 @@
<a href="../packages/api-utils/tab-browser.html">tab-browser</a>
+<a href="../packages/api-utils/test/assert.html">test/assert</a>
+
<a href="../packages/api-utils/text-streams.html">text-streams</a>
<a href="../packages/api-utils/traceback.html">traceback</a>
<a href="../packages/api-utils/traits.html">traits</a>
-<a href="../packages/api-utils/unit-test.html">unit-test</a>
-
<a href="../packages/api-utils/unload.html">unload</a>
<a href="../packages/api-utils/url.html">url</a>
View
11 dev-guide/credits.html
@@ -50,7 +50,7 @@
<h1>
<a href="../dev-guide/index.html">Add-on SDK<span></span></a>
</h1>
- <div id="version">Version 1.8</div>
+ <div id="version">Version 1.9</div>
</div>
</div>
@@ -125,6 +125,7 @@
<li><a href="https://github.com/dglol">David Guo</a></li>
<li><a href="https://github.com/nmaier">Nils Maier</a></li>
<li><a href="https://github.com/louisremi">Louis-Rémi Babé</a></li>
+<li><a href="https://github.com/tylkomat">Matthias Tylkowski</a></li>
</ul></div>
</div>
@@ -217,6 +218,8 @@
<a href="../packages/api-utils/app-strings.html">app-strings</a>
+<a href="../packages/api-utils/base64.html">base64</a>
+
<a href="../packages/api-utils/byte-streams.html">byte-streams</a>
<a href="../packages/api-utils/collection.html">collection</a>
@@ -261,6 +264,8 @@
<a href="../packages/api-utils/list.html">list</a>
+<a href="../packages/api-utils/loader.html">loader</a>
+
<a href="../packages/api-utils/match-pattern.html">match-pattern</a>
<a href="../packages/api-utils/memory.html">memory</a>
@@ -285,14 +290,14 @@
<a href="../packages/api-utils/tab-browser.html">tab-browser</a>
+<a href="../packages/api-utils/test/assert.html">test/assert</a>
+
<a href="../packages/api-utils/text-streams.html">text-streams</a>
<a href="../packages/api-utils/traceback.html">traceback</a>
<a href="../packages/api-utils/traits.html">traits</a>
-<a href="../packages/api-utils/unit-test.html">unit-test</a>
-
<a href="../packages/api-utils/unload.html">unload</a>
<a href="../packages/api-utils/url.html">url</a>
View
10 dev-guide/glossary.html
@@ -50,7 +50,7 @@
<h1>
<a href="../dev-guide/index.html">Add-on SDK<span></span></a>
</h1>
- <div id="version">Version 1.8</div>
+ <div id="version">Version 1.9</div>
</div>
</div>
@@ -207,6 +207,8 @@
<a href="../packages/api-utils/app-strings.html">app-strings</a>
+<a href="../packages/api-utils/base64.html">base64</a>
+
<a href="../packages/api-utils/byte-streams.html">byte-streams</a>
<a href="../packages/api-utils/collection.html">collection</a>
@@ -251,6 +253,8 @@
<a href="../packages/api-utils/list.html">list</a>
+<a href="../packages/api-utils/loader.html">loader</a>
+
<a href="../packages/api-utils/match-pattern.html">match-pattern</a>
<a href="../packages/api-utils/memory.html">memory</a>
@@ -275,14 +279,14 @@
<a href="../packages/api-utils/tab-browser.html">tab-browser</a>
+<a href="../packages/api-utils/test/assert.html">test/assert</a>
+
<a href="../packages/api-utils/text-streams.html">text-streams</a>
<a href="../packages/api-utils/traceback.html">traceback</a>
<a href="../packages/api-utils/traits.html">traits</a>
-<a href="../packages/api-utils/unit-test.html">unit-test</a>
-
<a href="../packages/api-utils/unload.html">unload</a>
<a href="../packages/api-utils/url.html">url</a>
View
10 dev-guide/guides/commonjs.html
@@ -50,7 +50,7 @@
<h1>
<a href="../../dev-guide/index.html">Add-on SDK<span></span></a>
</h1>
- <div id="version">Version 1.8</div>
+ <div id="version">Version 1.9</div>
</div>
</div>
@@ -284,6 +284,8 @@
<a href="../../packages/api-utils/app-strings.html">app-strings</a>
+<a href="../../packages/api-utils/base64.html">base64</a>
+
<a href="../../packages/api-utils/byte-streams.html">byte-streams</a>
<a href="../../packages/api-utils/collection.html">collection</a>
@@ -328,6 +330,8 @@
<a href="../../packages/api-utils/list.html">list</a>
+<a href="../../packages/api-utils/loader.html">loader</a>
+
<a href="../../packages/api-utils/match-pattern.html">match-pattern</a>
<a href="../../packages/api-utils/memory.html">memory</a>
@@ -352,14 +356,14 @@
<a href="../../packages/api-utils/tab-browser.html">tab-browser</a>
+<a href="../../packages/api-utils/test/assert.html">test/assert</a>
+
<a href="../../packages/api-utils/text-streams.html">text-streams</a>
<a href="../../packages/api-utils/traceback.html">traceback</a>
<a href="../../packages/api-utils/traits.html">traits</a>
-<a href="../../packages/api-utils/unit-test.html">unit-test</a>
-
<a href="../../packages/api-utils/unload.html">unload</a>
<a href="../../packages/api-utils/url.html">url</a>
View
99 dev-guide/guides/content-scripts/access.html → ...es/content-scripts/accessing-the-dom.html
@@ -26,7 +26,7 @@
<![endif]-->
<link href="../../../static-files/media/favicon.png" type="image/x-icon" rel="shortcut icon">
- <title>Content Script Access - Add-on SDK Documentation</title>
+ <title>Accessing the DOM - Add-on SDK Documentation</title>
</head>
<body>
@@ -50,7 +50,7 @@
<h1>
<a href="../../../dev-guide/index.html">Add-on SDK<span></span></a>
</h1>
- <div id="version">Version 1.8</div>
+ <div id="version">Version 1.9</div>
</div>
</div>
@@ -64,14 +64,9 @@
- License, v. 2.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>Content Script Access</h1>
-<p>This page talks about the access content scripts have to:</p>
-<ul>
-<li>DOM objects in the pages they are attached to</li>
-<li>other content scripts</li>
-<li>other scripts loaded by the page they are attached to</li>
-</ul>
-<h2>Access to the DOM</h2>
+<h1>Accessing the DOM</h1>
+<p>This page talks about the access content scripts have to DOM objects
+in the pages they are attached to.</p>
<p>Content scripts need to be able to access DOM objects in arbitrary web
pages, but this could cause two potential security problems:</p>
<ol>
@@ -174,81 +169,7 @@
Greasemonkey's unsafeWindow, and the
<a href="http://wiki.greasespot.net/UnsafeWindow">warnings for that</a> apply equally
here. Also, <code>unsafeWindow</code> isn't a supported API, so it could be removed or
-changed in a future version of the SDK.</p>
-<h2>Access to Other Content Scripts</h2>
-<p>Content scripts loaded into the same document can interact
-with each other directly as well as with the web content itself. However,
-content scripts which have been loaded into different documents
-cannot interact with each other.</p>
-<p>For example:</p>
-<ul>
-<li>
-<p>if an add-on creates a single <code>panel</code> object and loads several content
-scripts into the panel, then they can interact with each other</p>
-</li>
-<li>
-<p>if an add-on creates two <code>panel</code> objects and loads a script into each
-one, they can't interact with each other.</p>
-</li>
-<li>
-<p>if an add-on creates a single <code>page-mod</code> object and loads several content
-scripts into the page mod, then only content scripts associated with the
-same page can interact with each other: if two different matching pages are
-loaded, content scripts attached to page A cannot interact with those attached
-to page B.</p>
-</li>
-</ul>
-<p>The web content has no access to objects created by the content script, unless
-the content script explicitly makes them available.</p>
-<h2>Access to Page Scripts</h2>
-<p>You can communicate between the content script and page scripts using
-<a href="https://developer.mozilla.org/en/DOM/window.postMessage"><code>postMessage()</code></a>,
-but there's a twist: in early versions of the SDK, the global <code>postMessage()</code>
-function in content scripts was used for communicating between the content
-script and the main add-on code. Although this has been
-<a href="https://wiki.mozilla.org/Labs/Jetpack/Release_Notes/1.0b5#Major_Changes">deprecated in favor of <code>self.postMessage</code></a>,
-the old globals are still supported, so you can't currently use
-<code>window.postMessage()</code>. You must use <code>document.defaultView.postMessage()</code>
-instead.</p>
-<p>The following page script uses
-<a href="https://developer.mozilla.org/en/DOM/element.addEventListener"><code>window.addEventListener</code></a>
-to listen for messages:</p>
-<script type="syntaxhighlighter" class="brush: html"><![CDATA[
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html lang='en' xml:lang='en' xmlns="http://www.w3.org/1999/xhtml">
-
-<head>
- <script>
- window.addEventListener("message", function(event) {
- window.alert(event.data);
- }, false);
- &lt;/script>
-
-</head>
-
-</html>
-
-</script>
-
-<p>Content scripts can send it messages using <code>document.defaultView.postMessage()</code>:</p>
-<pre><code>var widgets = require("widget");
-var tabs = require("tabs");
-var data = require("self").data;
-
-var widget = widgets.Widget({
- id: "postMessage",
- label: "demonstrate document.defaultView.postMessage",
- contentURL: "http://www.mozilla.org/favicon.ico",
- onClick: function() {
- tabs.activeTab.attach({
- contentScript: "document.defaultView.postMessage('hi there!', '*');"
- });
- }
-});
-
-tabs.open(data.url("listener.html"));
-</code></pre></div>
+changed in a future version of the SDK.</p></div>
</div>
<div id="sidebar" class="column">
@@ -340,6 +261,8 @@
<a href="../../../packages/api-utils/app-strings.html">app-strings</a>
+<a href="../../../packages/api-utils/base64.html">base64</a>
+
<a href="../../../packages/api-utils/byte-streams.html">byte-streams</a>
<a href="../../../packages/api-utils/collection.html">collection</a>
@@ -384,6 +307,8 @@
<a href="../../../packages/api-utils/list.html">list</a>
+<a href="../../../packages/api-utils/loader.html">loader</a>
+
<a href="../../../packages/api-utils/match-pattern.html">match-pattern</a>
<a href="../../../packages/api-utils/memory.html">memory</a>
@@ -408,14 +333,14 @@
<a href="../../../packages/api-utils/tab-browser.html">tab-browser</a>
+<a href="../../../packages/api-utils/test/assert.html">test/assert</a>
+
<a href="../../../packages/api-utils/text-streams.html">text-streams</a>
<a href="../../../packages/api-utils/traceback.html">traceback</a>
<a href="../../../packages/api-utils/traits.html">traits</a>
-<a href="../../../packages/api-utils/unit-test.html">unit-test</a>
-
<a href="../../../packages/api-utils/unload.html">unload</a>
<a href="../../../packages/api-utils/url.html">url</a>
View
537 dev-guide/guides/content-scripts/communicating-with-other-scripts.html
@@ -0,0 +1,537 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+"http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en">
+<head>
+ <base>
+ <meta content="text/html; charset=utf-8" http-equiv="Content-type">
+ <script src="../../../static-files/syntaxhighlighter/scripts/shCore.js" type="text/javascript"></script>
+ <script src="../../../static-files/syntaxhighlighter/scripts/shBrushCss.js" type="text/javascript"></script>
+ <script src="../../../static-files/syntaxhighlighter/scripts/shBrushXml.js" type="text/javascript"></script>
+ <script src="../../../static-files/syntaxhighlighter/scripts/shBrushJScript.js" type="text/javascript"></script>
+ <link media="all" href="../../../static-files/css/base.css" type="text/css" rel="stylesheet">
+ <link media="all" href="../../../static-files/css/header.css" type="text/css" rel="stylesheet">
+ <link media="all" href="../../../static-files/css/footer.css" type="text/css" rel="stylesheet">
+ <link media="all" href="../../../static-files/css/sdk-docs.css" type="text/css" rel="stylesheet">
+ <link media="all" href="../../../static-files/css/api-reference.css" type="text/css" rel="stylesheet">
+ <link href="../../../static-files/syntaxhighlighter/styles/shCore.css" type="text/css" rel="stylesheet">
+ <link href="../../../static-files/syntaxhighlighter/styles/shThemeDefault.css" type="text/css" rel="stylesheet">
+ <!--[if IE]>
+ <style type="text/css">
+ .package-summary .module,
+ .package-entry .module,
+ .package-detail .module {
+ display: block;
+ }
+ </style>
+ <![endif]-->
+
+ <link href="../../../static-files/media/favicon.png" type="image/x-icon" rel="shortcut icon">
+ <title>Communicating With Other Scripts - Add-on SDK Documentation</title>
+</head>
+<body>
+
+<div id="global-header">
+ <div class="funnel">
+ <a href="http://www.mozilla.org/?ref=logo" id="mozilla-tab">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>
+ </div>
+</div>
+
+
+<div id="site-header">
+ <div class="funnel">
+ <h1>
+ <a href="../../../dev-guide/index.html">Add-on SDK<span></span></a>
+ </h1>
+ <div id="version">Version 1.9</div>
+ </div>
+</div>
+
+ <div id="container">
+
+ <div id="columns">
+
+ <div id="main-content-column" class="column">
+ <div id="toc"></div>
+ <div id="main-content"><!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.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>Communicating With Other Scripts</h1>
+<p>This section of the guide explains how content scripts can
+communicate with:</p>
+<ul>
+<li><a href="../../../dev-guide/guides/content-scripts/communicating-with-other-scripts.html#main.js">your <code>main.js</code> file</a>,
+or any other modules in your add-on</li>
+<li><a href="../../../dev-guide/guides/content-scripts/communicating-with-other-scripts.html#Content Scripts">other content scripts loaded by your add-on</a></li>
+<li><a href="../../../dev-guide/guides/content-scripts/communicating-with-other-scripts.html#Page Scripts">page scripts</a> (that is, scripts embedded in the web page or
+included using <code>&lt;script&gt;</code> tags) </li>
+</ul>
+<h2>main.js</h2>
+<p>Your content scripts can communicate with your add-on's "main.js"
+(or any other modules you're written for your add-on) by sending it messages,
+using either the <code>port.emit()</code> API or the <code>postMessage()</code> API. See the
+articles on
+<a href="../../../dev-guide/guides/content-scripts/using-postmessage.html">using <code>postMessage()</code></a>
+and
+<a href="../../../dev-guide/guides/content-scripts//using-port.html">using <code>port</code></a> for details.</p>
+<h2>Content Scripts</h2>
+<p>Content scripts loaded into the same document can interact
+with each other directly as well as with the web content itself. However,
+content scripts which have been loaded into different documents
+cannot interact with each other.</p>
+<p>For example:</p>
+<ul>
+<li>if an add-on creates a single <code>panel</code> object and loads several content
+scripts into the panel, then they can interact with each other</li>
+<li>if an add-on creates two <code>panel</code> objects and loads a script into each
+one, they can't interact with each other.</li>
+<li>if an add-on creates a single <code>page-mod</code> object and loads several content
+scripts into the page mod, then only content scripts associated with the
+same page can interact with each other: if two different matching pages are
+loaded, content scripts attached to page A cannot interact with those attached
+to page B.</li>
+</ul>
+<p>The web content has no access to objects created by the content script, unless
+the content script explicitly makes them available.</p>
+<h2>Page Scripts</h2>
+<p>If a page includes its own scripts using <code>&lt;script&gt;</code> tags,
+either embedded in the page or linked to it using the <code>src</code> attribute, there
+are a couple of ways a content script can communicate with it:</p>
+<ul>
+<li>using the <a href="../../../dev-guide/guides/content-scripts/communicating-with-other-scripts.html#Using the DOM postMessage API">DOM <code>postMessage()</code> API</a></li>
+<li>using <a href="../../../dev-guide/guides/content-scripts/communicating-with-other-scripts.html#Using Custom DOM Events">custom DOM events</a></li>
+</ul>
+<h3>Using the DOM postMessage API</h3>
+<p>You can communicate between the content script and page scripts using
+<a href="https://developer.mozilla.org/en/DOM/window.postMessage"><code>window.postMessage()</code></a>,
+but there's a twist: in early versions of the SDK, the global <code>postMessage()</code>
+function in content scripts was used for communicating between the content
+script and the main add-on code. Although this has been
+<a href="https://wiki.mozilla.org/Labs/Jetpack/Release_Notes/1.0b5#Major_Changes">deprecated in favor of <code>self.postMessage</code></a>,
+the old globals are still supported, so you can't currently use
+<code>window.postMessage()</code>. You must use <code>document.defaultView.postMessage()</code>
+instead.</p>
+<h4>Messaging From Content Script To Page Script</h4>
+<p>Suppose we have a page called "listen.html" hosted at "my-domain.org", and we want to send messages
+from the add-on to a script embedded in that page.</p>
+<p>In the main add-on code, we have a
+<a href="../../../packages/addon-kit/page-mod.html"><code>page-mod</code></a> that attaches the content script
+"talk.js" to the right page:</p>
+<pre><code>var data = require("self").data;
+
+var pageMod = require("page-mod");
+pageMod.PageMod({
+ include: "http://my-domain.org/listen.html",
+ contentScriptFile: data.url("talk.js")
+});
+</code></pre>
+<p>The "talk.js" content script uses <code>document.defaultView.postMessage()</code> to send
+the message to the page:</p>
+<pre><code>document.defaultView.postMessage("Message from content script", "http://my-domain.org/");
+</code></pre>
+<p>The second argument may be '*' which will allow communication with any domain.</p>
+<p>Finally, "listen.html" uses <code>window.addEventListener()</code> to listen for
+messages from the content script:</p>
+<script type="syntaxhighlighter" class="brush: html"><![CDATA[
+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+ &lt;head&gt;&lt;/head&gt;
+ &lt;body&gt;
+ &lt;script&gt;
+ window.addEventListener('message', function(event) {
+ window.alert(event.data);
+ }, false);
+ &lt;/script&gt;
+ &lt;/body&gt;
+
+&lt;/html&gt;
+]]>
+</script>
+
+<h4>Messaging From Page Script To Content Script</h4>
+<p>Sending messages from the page script to the content script is just
+the same, but in reverse.</p>
+<p>Here "main.js" creates a <a href="../../../packages/addon-kit/page-mod.html"><code>page-mod</code></a>
+that attaches "listen.js" to the web page:</p>
+<pre><code>var data = require("self").data;
+
+var pageMod = require("page-mod");
+pageMod.PageMod({
+ include: "http://my-domain.org/talk.html",
+ contentScriptFile: data.url("listen.js")
+});
+</code></pre>
+<p>The web page "talk.html" embeds a script that uses <code>window.postMessage()</code>
+to send the content script a message when the user clicks a button:</p>
+<script type="syntaxhighlighter" class="brush: html"><![CDATA[
+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+ &lt;head&gt;&lt;/head&gt;
+ &lt;body&gt;
+ &lt;script&gt;
+ function sendMessage() {
+ window.postMessage("Message from page script", "http://my-domain.org/");
+ }
+ &lt;/script&gt;
+ &lt;button onclick="sendMessage()"&gt;Send Message&lt;/button&gt;
+ &lt;/body&gt;
+
+&lt;/html&gt;
+</script>
+
+<p>Finally, the content script "listen.js" uses
+<code>document.defaultView.addEventListener()</code> to listen for messages from the page
+script:</p>
+<pre><code>document.defaultView.addEventListener('message', function(event) {
+ console.log(event.data);
+ console.log(event.origin);
+}, false);
+</code></pre>
+<h3>Using Custom DOM Events</h3>
+<p>As an alternative to using <code>postMessage()</code> you can use
+<a href="https://developer.mozilla.org/en/DOM/CustomEvent">custom DOM events</a>
+to communicate between page scripts and content scripts.</p>
+<h4>Messaging From Content Script To Page Script</h4>
+<p>Here's an example showing how to use custom DOM events to send a message
+from a content script to a page script.</p>
+<p>First, "main.js" will create a <a href="../../../packages/addon-kit/page-mod.html"><code>page-mod</code></a>
+that will attach "talk.js" to the target web page:</p>
+<pre><code>var data = require("self").data;
+
+var pageMod = require("page-mod");
+pageMod.PageMod({
+ include: "http://my-domain.org/listen.html",
+ contentScriptFile: data.url("talk.js")
+});
+</code></pre>
+<p>Next, "talk.js" creates and dispatches a custom event, passing the payload
+in the <code>detail</code> parameter to <code>initCustomEvent()</code>:</p>
+<!-- This comment is used to terminate the Markdown list above -->
+
+<pre><code>var event = document.createEvent('CustomEvent');
+event.initCustomEvent("addon-message", true, true, { hello: 'world' });
+document.documentElement.dispatchEvent(event);
+</code></pre>
+<p>Finally "listen.html" listens for the new event and examines its
+<code>detail</code> attribute to retrieve the payload:</p>
+<script type="syntaxhighlighter" class="brush: html"><![CDATA[
+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+ &lt;head&gt;&lt;/head&gt;
+ &lt;body&gt;
+ &lt;script&gt;
+ document.documentElement.addEventListener("addon-message", function(event) {
+ window.alert(JSON.stringify(event.detail))
+ }, false);
+ &lt;/script&gt;
+ &lt;/body&gt;
+&lt;/html&gt;
+</script>
+
+<h4>Messaging From Page Script to Content Script</h4>
+<p>Sending messages using custom DOM events from the page script
+to the content script is just the same, but in reverse.</p>
+<p>Again, "main.js" creates a <a href="../../../packages/addon-kit/page-mod.html"><code>page-mod</code></a>
+to target the page we are interested in:</p>
+<pre><code>var data = require("self").data;
+
+var pageMod = require("page-mod");
+pageMod.PageMod({
+ include: "http://my-domain.org/talk.html",
+ contentScriptFile: data.url("listen.js")
+});
+</code></pre>
+<p>The web page "talk.html" creates and dispatches a custom DOM event,
+using <code>initCustomEvent()</code>'s <code>detail</code> parameter to supply the payload:</p>
+<script type="syntaxhighlighter" class="brush: html"><![CDATA[
+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+ &lt;head&gt;&lt;/head&gt;
+ &lt;body&gt;
+ &lt;script&gt;
+ function sendMessage() {
+ var event = document.createEvent('CustomEvent');
+ event.initCustomEvent("addon-message", true, true, { hello: 'world' });
+ document.documentElement.dispatchEvent(event);
+ }
+ &lt;/script&gt;
+ &lt;button onclick="sendMessage()"&gt;Send Message&lt;/button&gt;
+ &lt;/body&gt;
+&lt;/html&gt;
+</script>
+
+<p>Finally, the content script "listen.js" listens for the new event
+and retrieves the payload from its <code>detail</code> attribute:</p>
+<pre><code>document.documentElement.addEventListener("addon-message", function(event) {
+ console.log(JSON.stringify(event.detail));
+}, false);
+</code></pre></div>
+ </div>
+
+ <div id="sidebar" class="column">
+ <div class="sidebar-section" id="addon-development">
+ <a href="../../../dev-guide/index.html"><h2 class="sidebar-section-header">Developer Guide</h2></a>
+ <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/index.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">
+<li style="display: block;" class="package-summary">
+<h4>
+<a href="../../../packages/addon-kit/index.html">addon-kit</a>
+</h4>
+
+<a href="../../../packages/addon-kit/addon-page.html">addon-page</a>
+
+<a href="../../../packages/addon-kit/clipboard.html">clipboard</a>
+
+<a href="../../../packages/addon-kit/context-menu.html">context-menu</a>
+
+<a href="../../../packages/addon-kit/hotkeys.html">hotkeys</a>
+
+<a href="../../../packages/addon-kit/l10n.html">l10n</a>
+
+<a href="../../../packages/addon-kit/notifications.html">notifications</a>
+
+<a href="../../../packages/addon-kit/page-mod.html">page-mod</a>
+
+<a href="../../../packages/addon-kit/page-worker.html">page-worker</a>
+
+<a href="../../../packages/addon-kit/panel.html">panel</a>
+
+<a href="../../../packages/addon-kit/passwords.html">passwords</a>
+
+<a href="../../../packages/addon-kit/private-browsing.html">private-browsing</a>
+
+<a href="../../../packages/addon-kit/request.html">request</a>
+
+<a href="../../../packages/addon-kit/selection.html">selection</a>
+
+<a href="../../../packages/addon-kit/self.html">self</a>
+
+<a href="../../../packages/addon-kit/simple-prefs.html">simple-prefs</a>
+
+<a href="../../../packages/addon-kit/simple-storage.html">simple-storage</a>
+
+<a href="../../../packages/addon-kit/tabs.html">tabs</a>
+
+<a href="../../../packages/addon-kit/timers.html">timers</a>
+
+<a href="../../../packages/addon-kit/widget.html">widget</a>
+
+<a href="../../../packages/addon-kit/windows.html">windows</a>
+</li>
+</ul>
+ </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">
+<li style="display: block;" class="package-summary">
+<h4>
+<a href="../../../packages/api-utils/index.html">api-utils</a>
+</h4>
+
+<a href="../../../packages/api-utils/api-utils.html">api-utils</a>
+
+<a href="../../../packages/api-utils/app-strings.html">app-strings</a>
+
+<a href="../../../packages/api-utils/base64.html">base64</a>
+
+<a href="../../../packages/api-utils/byte-streams.html">byte-streams</a>
+
+<a href="../../../packages/api-utils/collection.html">collection</a>
+
+<a href="../../../packages/api-utils/content.html">content</a>
+
+<a href="../../../packages/api-utils/content/loader.html">content/loader</a>
+
+<a href="../../../packages/api-utils/content/proxy.html">content/proxy</a>
+
+<a href="../../../packages/api-utils/content/symbiont.html">content/symbiont</a>
+
+<a href="../../../packages/api-utils/content/worker.html">content/worker</a>
+
+<a href="../../../packages/api-utils/cortex.html">cortex</a>
+
+<a href="../../../packages/api-utils/cuddlefish.html">cuddlefish</a>
+
+<a href="../../../packages/api-utils/environment.html">environment</a>
+
+<a href="../../../packages/api-utils/errors.html">errors</a>
+
+<a href="../../../packages/api-utils/event/core.html">event/core</a>
+
+<a href="../../../packages/api-utils/event/target.html">event/target</a>
+
+<a href="../../../packages/api-utils/events.html">events</a>
+
+<a href="../../../packages/api-utils/file.html">file</a>
+
+<a href="../../../packages/api-utils/frame/utils.html">frame/utils</a>
+
+<a href="../../../packages/api-utils/globals.html">globals</a>
+
+<a href="../../../packages/api-utils/heritage.html">heritage</a>
+
+<a href="../../../packages/api-utils/hidden-frame.html">hidden-frame</a>
+
+<a href="../../../packages/api-utils/httpd.html">httpd</a>
+
+<a href="../../../packages/api-utils/light-traits.html">light-traits</a>
+
+<a href="../../../packages/api-utils/list.html">list</a>
+
+<a href="../../../packages/api-utils/loader.html">loader</a>
+
+<a href="../../../packages/api-utils/match-pattern.html">match-pattern</a>
+
+<a href="../../../packages/api-utils/memory.html">memory</a>
+
+<a href="../../../packages/api-utils/message-manager.html">message-manager</a>
+
+<a href="../../../packages/api-utils/namespace.html">namespace</a>
+
+<a href="../../../packages/api-utils/observer-service.html">observer-service</a>
+
+<a href="../../../packages/api-utils/plain-text-console.html">plain-text-console</a>
+
+<a href="../../../packages/api-utils/preferences-service.html">preferences-service</a>
+
+<a href="../../../packages/api-utils/promise.html">promise</a>
+
+<a href="../../../packages/api-utils/querystring.html">querystring</a>
+
+<a href="../../../packages/api-utils/runtime.html">runtime</a>
+
+<a href="../../../packages/api-utils/sandbox.html">sandbox</a>
+
+<a href="../../../packages/api-utils/tab-browser.html">tab-browser</a>
+
+<a href="../../../packages/api-utils/test/assert.html">test/assert</a>
+
+<a href="../../../packages/api-utils/text-streams.html">text-streams</a>
+
+<a href="../../../packages/api-utils/traceback.html">traceback</a>
+
+<a href="../../../packages/api-utils/traits.html">traits</a>
+
+<a href="../../../packages/api-utils/unload.html">unload</a>
+
+<a href="../../../packages/api-utils/url.html">url</a>
+
+<a href="../../../packages/api-utils/uuid.html">uuid</a>
+
+<a href="../../../packages/api-utils/window/utils.html">window/utils</a>
+
+<a href="../../../packages/api-utils/window-utils.html">window-utils</a>
+
+<a href="../../../packages/api-utils/xhr.html">xhr</a>
+
+<a href="../../../packages/api-utils/xpcom.html">xpcom</a>
+
+<a href="../../../packages/api-utils/xul-app.html">xul-app</a>
+</li>
+
+<li style="display: block;" class="package-summary">
+<h4>
+<a href="../../../packages/test-harness/index.html">test-harness</a>
+</h4>
+
+<a href="../../../packages/test-harness/harness.html">harness</a>
+
+<a href="../../../packages/test-harness/run-tests.html">run-tests</a>
+</li>
+</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>
+
+ </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 id="footer">
+ <div class="section">
+ <img src="../../../static-files/media/footer-logo-med.png" alt="" 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 src="../../../static-files/js/jquery.js" type="text/javascript"></script>
+<script src="../../../static-files/js/main.js" type="text/javascript"></script>
+
+</body>
+
+</html>
View
22 dev-guide/guides/content-scripts/index.html
@@ -50,7 +50,7 @@
<h1>
<a href="../../../dev-guide/index.html">Add-on SDK<span></span></a>
</h1>
- <div id="version">Version 1.8</div>
+ <div id="version">Version 1.9</div>
</div>
</div>
@@ -94,8 +94,8 @@
<p>A single add-on may use multiple content scripts, and content scripts loaded
into the same context can interact directly with each other as well as with
the web content itself. See the chapter on
-<a href="../../../dev-guide/guides/content-scripts/access.html">
-content script access</a>.</p>
+<a href="../../../dev-guide/guides/content-scripts/communicating-with-other-scripts.html">
+communicating with other scripts</a>.</p>
<p>The add-on script and content script can't directly access each other's state.
Instead, you can define your own events which each side can emit, and the
other side can register listeners to handle them. The interfaces are similar
@@ -125,9 +125,11 @@
<li><a href="../../../dev-guide/guides/content-scripts/loading.html">Loading Content Scripts</a>:
how to attach content scripts to web pages, and how to control the point at
which they are executed</li></