summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xchrome/common/extensions/api/extension_api.json27
-rw-r--r--chrome/common/extensions/docs/extension.html151
-rw-r--r--chrome/renderer/resources/renderer_extension_bindings.js11
-rw-r--r--chrome/test/data/extensions/api_test/connect/page.js2
-rw-r--r--chrome/test/data/extensions/api_test/connect/test.html27
5 files changed, 179 insertions, 39 deletions
diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json
index 86e42d6..849ddbe6 100755
--- a/chrome/common/extensions/api/extension_api.json
+++ b/chrome/common/extensions/api/extension_api.json
@@ -3,6 +3,15 @@
"namespace": "extension",
"types": [
{
+ "id": "MessageSender",
+ "type": "object",
+ "description": "An object containing information about the script context that sent a message or request.",
+ "properties": {
+ "tab": {"$ref": "Tab", "optional": true, "description":"This property will <b>only</b> be present when the connection was opened from a tab or content script."},
+ "id": {"type": "string", "description": "The extension ID of the extension that opened the connection."}
+ }
+ },
+ {
"id": "Port",
"type": "object",
"description": "An object which allows two way communication with other pages.",
@@ -12,13 +21,9 @@
"onMessage": {"type": "object"},
"postMessage": {"type": "function"},
"sender": {
- "type": "object",
+ "$ref": "MessageSender",
"optional": true,
- "description": "This property will <b>only</b> be present on ports passed to onConnect/onConnectExternal listeners.",
- "properties": {
- "tab": {"$ref": "Tab", "optional": true, "description":"This property will <b>only</b> be present when the connection was opened from a tab or content script."},
- "id": {"type": "string", "description": "The extension ID of the extension that opened the connection."}
- }
+ "description": "This property will <b>only</b> be present on ports passed to onConnect/onConnectExternal listeners."
}
}
}
@@ -153,8 +158,9 @@
"type": "function",
"description": "Fired when a request is sent from either an extension process or a content script.",
"parameters": [
- { "type": "any", "name": "request" },
- { "type": "function", "name": "sendResponse", "description": "Function to call when you have a response. The argument should be any JSON-ifiable object, or undefined if there is no response." }
+ {"name": "request", "type": "any", "description": "The request sent by the calling script."},
+ {"name": "sender", "$ref": "MessageSender" },
+ {"name": "sendResponse", "type": "function", "description": "Function to call when you have a response. The argument should be any JSON-ifiable object, or undefined if there is no response." }
]
},
{
@@ -162,8 +168,9 @@
"type": "function",
"description": "Fired when a request is sent from another extension.",
"parameters": [
- { "type": "any", "name": "request" },
- { "type": "function", "name": "sendResponse", "description": "Function to call when you have a response. The argument should be any JSON-ifiable object, or undefined if there is no response." }
+ {"name": "request", "type": "any", "description": "The request sent by the calling script."},
+ {"name": "sender", "$ref": "MessageSender" },
+ {"name": "sendResponse", "type": "function", "description": "Function to call when you have a response. The argument should be any JSON-ifiable object, or undefined if there is no response." }
]
}
]
diff --git a/chrome/common/extensions/docs/extension.html b/chrome/common/extensions/docs/extension.html
index 3b55e9a..9c42063 100644
--- a/chrome/common/extensions/docs/extension.html
+++ b/chrome/common/extensions/docs/extension.html
@@ -217,8 +217,10 @@
<li>
<a href="#types">Types</a>
<ol>
- <li jsinstance="*0">
+ <li jsinstance="0">
<a href="#type-Port">Port</a>
+ </li><li jsinstance="*1">
+ <a href="#type-MessageSender">MessageSender</a>
</li>
</ol>
</li>
@@ -1511,7 +1513,7 @@ For details, see
<div class="summary">
<!-- Note: intentionally longer 80 columns -->
- <span class="subdued">chrome.extension.</span><span>onRequest</span><span class="subdued">.addListener</span>(function(<span>any request, function sendResponse</span>) <span class="subdued">{...}</span>);
+ <span class="subdued">chrome.extension.</span><span>onRequest</span><span class="subdued">.addListener</span>(function(<span>any request, MessageSender sender, function sendResponse</span>) <span class="subdued">{...}</span>);
</div>
<div class="description">
@@ -1547,6 +1549,47 @@ For details, see
</em>
</dt>
+ <dd class="todo" style="display: none; ">
+ Undocumented.
+ </dd>
+ <dd>The request sent by the calling script.</dd>
+
+ <!-- OBJECT PROPERTIES -->
+ <dd style="display: none; ">
+ <dl>
+ <div>
+ <div>
+ </div>
+ </div>
+ </dl>
+ </dd>
+ </div>
+ </div><div jsinstance="1">
+ <div>
+ <dt>
+ <var>sender</var>
+ <em>
+
+ <!-- TYPE -->
+ <div style="display:inline">
+ (
+ <span class="optional" style="display: none; ">optional</span>
+ <span id="typeTemplate">
+ <span>
+ <a href="extension.html#type-MessageSender">MessageSender</a>
+ </span>
+ <span style="display: none; ">
+ <span>
+ array of <span><span></span></span>
+ </span>
+ <span>paramType</span>
+ </span>
+ </span>
+ )
+ </div>
+
+ </em>
+ </dt>
<dd class="todo">
Undocumented.
</dd>
@@ -1564,7 +1607,7 @@ For details, see
</dl>
</dd>
</div>
- </div><div jsinstance="*1">
+ </div><div jsinstance="*2">
<div>
<dt>
<var>sendResponse</var>
@@ -1616,7 +1659,7 @@ For details, see
<div class="summary">
<!-- Note: intentionally longer 80 columns -->
- <span class="subdued">chrome.extension.</span><span>onRequestExternal</span><span class="subdued">.addListener</span>(function(<span>any request, function sendResponse</span>) <span class="subdued">{...}</span>);
+ <span class="subdued">chrome.extension.</span><span>onRequestExternal</span><span class="subdued">.addListener</span>(function(<span>any request, MessageSender sender, function sendResponse</span>) <span class="subdued">{...}</span>);
</div>
<div class="description">
@@ -1652,6 +1695,47 @@ For details, see
</em>
</dt>
+ <dd class="todo" style="display: none; ">
+ Undocumented.
+ </dd>
+ <dd>The request sent by the calling script.</dd>
+
+ <!-- OBJECT PROPERTIES -->
+ <dd style="display: none; ">
+ <dl>
+ <div>
+ <div>
+ </div>
+ </div>
+ </dl>
+ </dd>
+ </div>
+ </div><div jsinstance="1">
+ <div>
+ <dt>
+ <var>sender</var>
+ <em>
+
+ <!-- TYPE -->
+ <div style="display:inline">
+ (
+ <span class="optional" style="display: none; ">optional</span>
+ <span id="typeTemplate">
+ <span>
+ <a href="extension.html#type-MessageSender">MessageSender</a>
+ </span>
+ <span style="display: none; ">
+ <span>
+ array of <span><span></span></span>
+ </span>
+ <span>paramType</span>
+ </span>
+ </span>
+ )
+ </div>
+
+ </em>
+ </dt>
<dd class="todo">
Undocumented.
</dd>
@@ -1669,7 +1753,7 @@ For details, see
</dl>
</dd>
</div>
- </div><div jsinstance="*1">
+ </div><div jsinstance="*2">
<div>
<dt>
<var>sendResponse</var>
@@ -1725,7 +1809,7 @@ For details, see
<h3 id="types">Types</h3>
<!-- iterates over all types -->
- <div class="apiItem" jsinstance="*0">
+ <div class="apiItem" jsinstance="0">
<a name="type-Port"></a>
<h4>Port</h4>
@@ -1945,6 +2029,55 @@ For details, see
(
<span class="optional">optional</span>
<span id="typeTemplate">
+ <span>
+ <a href="extension.html#type-MessageSender">MessageSender</a>
+ </span>
+ <span style="display: none; ">
+ <span>
+ array of <span><span></span></span>
+ </span>
+ <span>paramType</span>
+ </span>
+ </span>
+ )
+ </div>
+
+ </em>
+ </dt>
+ <dd class="todo" style="display: none; ">
+ Undocumented.
+ </dd>
+ <dd>This property will <b>only</b> be present on ports passed to onConnect/onConnectExternal listeners.</dd>
+
+ <!-- OBJECT PROPERTIES -->
+ <dd style="display: none; ">
+ <dl>
+ <div>
+ <div>
+ </div>
+ </div>
+ </dl>
+ </dd>
+ </div>
+ </div>
+ </dl>
+ </dd>
+ </div>
+
+ </div><div class="apiItem" jsinstance="*1">
+ <a name="type-MessageSender"></a>
+ <h4>MessageSender</h4>
+
+ <div>
+ <dt>
+ <var style="display: none; ">paramName</var>
+ <em>
+
+ <!-- TYPE -->
+ <div style="display:inline">
+ (
+ <span class="optional" style="display: none; ">optional</span>
+ <span id="typeTemplate">
<span style="display: none; ">
<a> Type</a>
</span>
@@ -1963,7 +2096,7 @@ For details, see
<dd class="todo" style="display: none; ">
Undocumented.
</dd>
- <dd>This property will <b>only</b> be present on ports passed to onConnect/onConnectExternal listeners.</dd>
+ <dd>An object containing information about the script context that sent a message or request.</dd>
<!-- OBJECT PROPERTIES -->
<dd>
@@ -2054,10 +2187,6 @@ For details, see
</dl>
</dd>
</div>
- </div>
- </dl>
- </dd>
- </div>
</div> <!-- /apiItem -->
diff --git a/chrome/renderer/resources/renderer_extension_bindings.js b/chrome/renderer/resources/renderer_extension_bindings.js
index bf288bd..718c414 100644
--- a/chrome/renderer/resources/renderer_extension_bindings.js
+++ b/chrome/renderer/resources/renderer_extension_bindings.js
@@ -73,6 +73,10 @@ var chrome = chrome || {};
// the right event.
var isExternal = sourceExtensionId != chromeHidden.extensionId;
+ if (tab)
+ tab = JSON.parse(tab);
+ var sender = {tab: tab, id: sourceExtensionId};
+
// Special case for sendRequest/onRequest.
if (channelName == chromeHidden.kRequestChannel) {
var requestEvent = (isExternal ?
@@ -80,7 +84,7 @@ var chrome = chrome || {};
if (requestEvent.hasListeners()) {
var port = chromeHidden.Port.createPort(portId, channelName);
port.onMessage.addListener(function(request) {
- requestEvent.dispatch(request, function(response) {
+ requestEvent.dispatch(request, sender, function(response) {
port.postMessage(response);
});
});
@@ -92,10 +96,7 @@ var chrome = chrome || {};
chrome.extension.onConnectExternal : chrome.extension.onConnect);
if (connectEvent.hasListeners()) {
var port = chromeHidden.Port.createPort(portId, channelName);
- if (tab) {
- tab = JSON.parse(tab);
- }
- port.sender = {tab: tab, id: sourceExtensionId};
+ port.sender = sender;
// TODO(EXTENSIONS_DEPRECATED): port.tab is obsolete.
port.tab = port.sender.tab;
diff --git a/chrome/test/data/extensions/api_test/connect/page.js b/chrome/test/data/extensions/api_test/connect/page.js
index d70f415..2f737f70 100644
--- a/chrome/test/data/extensions/api_test/connect/page.js
+++ b/chrome/test/data/extensions/api_test/connect/page.js
@@ -5,6 +5,6 @@ chrome.extension.sendRequest({step: 1}, function(response) {
});
// For test sendRequest.
-chrome.extension.onRequest.addListener(function(request, sendResponse) {
+chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
sendResponse({success: (request.step2 == 1)});
});
diff --git a/chrome/test/data/extensions/api_test/connect/test.html b/chrome/test/data/extensions/api_test/connect/test.html
index 31868b4..b108a8d 100644
--- a/chrome/test/data/extensions/api_test/connect/test.html
+++ b/chrome/test/data/extensions/api_test/connect/test.html
@@ -2,22 +2,25 @@
chrome.test.runTests([
// Tests receiving a request from a content script and responding.
function onRequest() {
- chrome.extension.onRequest.addListener(function(request, sendResponse) {
- if (request.step == 1) {
- // Step 1: Page should send another request for step 2.
- sendResponse({nextStep: true});
- } else {
- // Step 2.
- chrome.test.assertEq(request.step, 2);
- sendResponse({});
- chrome.test.succeed();
- }
- });
+ chrome.extension.onRequest.addListener(
+ function(request, sender, sendResponse) {
+ chrome.test.assertTrue("url" in sender.tab, "no tab available.");
+ chrome.test.assertEq(sender.id, location.host);
+ if (request.step == 1) {
+ // Step 1: Page should send another request for step 2.
+ sendResponse({nextStep: true});
+ } else {
+ // Step 2.
+ chrome.test.assertEq(request.step, 2);
+ sendResponse({});
+ chrome.test.succeed();
+ }
+ });
},
// Tests sending a request to a tab and receiving a response.
function sendRequest() {
chrome.tabs.getSelected(null, function(tab) {
- chrome.test.log('Selected tab: ' + tab.url);
+ chrome.test.log("Selected tab: " + tab.url);
chrome.tabs.sendRequest(tab.id, {step2: 1}, function(response) {
chrome.test.assertTrue(response.success);
chrome.test.succeed();