Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(767)

Side by Side Diff: chrome/common/extensions/docs/static/messaging.html

Issue 6574031: Merge 75894 - Fix typo in Message Passing sample code.... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/648/src/
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/docs/messaging.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <div id="pageData-name" class="pageData">Message Passing</div> 1 <div id="pageData-name" class="pageData">Message Passing</div>
2 <div id="pageData-showTOC" class="pageData">true</div> 2 <div id="pageData-showTOC" class="pageData">true</div>
3 3
4 <p> 4 <p>
5 Since content scripts run in the context of a web page and not the extension, 5 Since content scripts run in the context of a web page and not the extension,
6 they often need some way of communicating with the rest of the extension. For 6 they often need some way of communicating with the rest of the extension. For
7 example, an RSS reader extension might use content scripts to detect the 7 example, an RSS reader extension might use content scripts to detect the
8 presence of an RSS feed on a page, then notify the background page in order to 8 presence of an RSS feed on a page, then notify the background page in order to
9 display a page action icon for that page. 9 display a page action icon for that page.
10 10
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 messages: 115 messages:
116 <pre> 116 <pre>
117 contentscript.js 117 contentscript.js
118 ================ 118 ================
119 var port = chrome.extension.connect({name: "knockknock"}); 119 var port = chrome.extension.connect({name: "knockknock"});
120 port.postMessage({joke: "Knock knock"}); 120 port.postMessage({joke: "Knock knock"});
121 port.onMessage.addListener(function(msg) { 121 port.onMessage.addListener(function(msg) {
122 if (msg.question == "Who's there?") 122 if (msg.question == "Who's there?")
123 port.postMessage({answer: "Madame"}); 123 port.postMessage({answer: "Madame"});
124 else if (msg.question == "Madame who?") 124 else if (msg.question == "Madame who?")
125 port.postMessage({answer: "Madame... Bovary"); 125 port.postMessage({answer: "Madame... Bovary"});
126 }); 126 });
127 </pre> 127 </pre>
128 128
129 <p> 129 <p>
130 Sending a request from the extension to a content script looks very similar, 130 Sending a request from the extension to a content script looks very similar,
131 except that you need to specify which tab to connect to. Simply replace the 131 except that you need to specify which tab to connect to. Simply replace the
132 call to connect in the above example with 132 call to connect in the above example with
133 <a href="tabs.html#method-connect">chrome.tabs.connect(tabId, {name: 133 <a href="tabs.html#method-connect">chrome.tabs.connect(tabId, {name:
134 "knockknock"})</a>. 134 "knockknock"})</a>.
135 135
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extension s/docs/examples/api/messaging/">examples/api/messaging</a> 270 <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extension s/docs/examples/api/messaging/">examples/api/messaging</a>
271 directory. 271 directory.
272 Also see the 272 Also see the
273 <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extension s/docs/examples/howto/contentscript_xhr">contentscript_xhr</a> example, 273 <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extension s/docs/examples/howto/contentscript_xhr">contentscript_xhr</a> example,
274 in which a content script and its parent extension exchange messages, 274 in which a content script and its parent extension exchange messages,
275 so that the parent extension can perform 275 so that the parent extension can perform
276 cross-site requests on behalf of the content script. 276 cross-site requests on behalf of the content script.
277 For more examples and for help in viewing the source code, see 277 For more examples and for help in viewing the source code, see
278 <a href="samples.html">Samples</a>. 278 <a href="samples.html">Samples</a>.
279 </p> 279 </p>
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/messaging.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698