| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // chrome.runtime.messaging API implementation. | 5 // chrome.runtime.messaging API implementation. |
| 6 | 6 |
| 7 // TODO(kalman): factor requiring chrome out of here. | 7 // TODO(kalman): factor requiring chrome out of here. |
| 8 var chrome = requireNative('chrome').GetChrome(); | 8 var chrome = requireNative('chrome').GetChrome(); |
| 9 var lastError = require('lastError'); | 9 var lastError = require('lastError'); |
| 10 var logActivity = requireNative('activityLogger'); | 10 var logActivity = requireNative('activityLogger'); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // We nulled out port when sending the response, and now the page | 121 // We nulled out port when sending the response, and now the page |
| 122 // is trying to send another response for the same request. | 122 // is trying to send another response for the same request. |
| 123 handleSendRequestError(isSendMessage, responseCallbackPreserved, | 123 handleSendRequestError(isSendMessage, responseCallbackPreserved, |
| 124 sourceExtensionId, targetExtensionId); | 124 sourceExtensionId, targetExtensionId); |
| 125 } | 125 } |
| 126 }; | 126 }; |
| 127 // In case the extension never invokes the responseCallback, and also | 127 // In case the extension never invokes the responseCallback, and also |
| 128 // doesn't keep a reference to it, we need to clean up the port. Do | 128 // doesn't keep a reference to it, we need to clean up the port. Do |
| 129 // so by attaching to the garbage collection of the responseCallback | 129 // so by attaching to the garbage collection of the responseCallback |
| 130 // using some native hackery. | 130 // using some native hackery. |
| 131 // |
| 132 // If the context is destroyed before this has a chance to execute, |
| 133 // BindToGC knows to release |portId| (important for updating C++ state |
| 134 // both in this renderer and on the other end). We don't need to clear |
| 135 // any JavaScript state, as calling destroy_() would usually do - but |
| 136 // the context has been destroyed, so there isn't any JS state to clear. |
| 131 messagingNatives.BindToGC(responseCallback, function() { | 137 messagingNatives.BindToGC(responseCallback, function() { |
| 132 if (port) { | 138 if (port) { |
| 133 privates(port).impl.destroy_(); | 139 privates(port).impl.destroy_(); |
| 134 port = null; | 140 port = null; |
| 135 } | 141 } |
| 136 }); | 142 }, portId); |
| 137 var rv = requestEvent.dispatch(request, sender, responseCallback); | 143 var rv = requestEvent.dispatch(request, sender, responseCallback); |
| 138 if (isSendMessage) { | 144 if (isSendMessage) { |
| 139 responseCallbackPreserved = | 145 responseCallbackPreserved = |
| 140 rv && rv.results && $Array.indexOf(rv.results, true) > -1; | 146 rv && rv.results && $Array.indexOf(rv.results, true) > -1; |
| 141 if (!responseCallbackPreserved && port) { | 147 if (!responseCallbackPreserved && port) { |
| 142 // If they didn't access the response callback, they're not | 148 // If they didn't access the response callback, they're not |
| 143 // going to send a response, so clean up the port immediately. | 149 // going to send a response, so clean up the port immediately. |
| 144 privates(port).impl.destroy_(); | 150 privates(port).impl.destroy_(); |
| 145 port = null; | 151 port = null; |
| 146 } | 152 } |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 exports.kNativeMessageChannel = kNativeMessageChannel; | 335 exports.kNativeMessageChannel = kNativeMessageChannel; |
| 330 exports.createPort = createPort; | 336 exports.createPort = createPort; |
| 331 exports.sendMessageImpl = sendMessageImpl; | 337 exports.sendMessageImpl = sendMessageImpl; |
| 332 exports.sendMessageUpdateArguments = sendMessageUpdateArguments; | 338 exports.sendMessageUpdateArguments = sendMessageUpdateArguments; |
| 333 | 339 |
| 334 // For C++ code to call. | 340 // For C++ code to call. |
| 335 exports.hasPort = hasPort; | 341 exports.hasPort = hasPort; |
| 336 exports.dispatchOnConnect = dispatchOnConnect; | 342 exports.dispatchOnConnect = dispatchOnConnect; |
| 337 exports.dispatchOnDisconnect = dispatchOnDisconnect; | 343 exports.dispatchOnDisconnect = dispatchOnDisconnect; |
| 338 exports.dispatchOnMessage = dispatchOnMessage; | 344 exports.dispatchOnMessage = dispatchOnMessage; |
| OLD | NEW |