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

Side by Side Diff: chrome/renderer/resources/extensions/messaging.js

Issue 83023014: Fix chrome.runtime.sendMessage background page memory leak. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | « no previous file | 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This contains unprivileged javascript APIs for extensions and apps. It 5 // This contains unprivileged javascript APIs for extensions and apps. It
6 // can be loaded by any extension-related context, such as content scripts or 6 // can be loaded by any extension-related context, such as content scripts or
7 // background pages. See user_script_slave.cc for script that is loaded by 7 // background pages. See user_script_slave.cc for script that is loaded by
8 // content scripts only. 8 // content scripts only.
9 9
10 // TODO(kalman): factor requiring chrome out of here. 10 // TODO(kalman): factor requiring chrome out of here.
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 if (chrome.extension) { 154 if (chrome.extension) {
155 requestEvent = isExternal ? chrome.extension.onRequestExternal 155 requestEvent = isExternal ? chrome.extension.onRequestExternal
156 : chrome.extension.onRequest; 156 : chrome.extension.onRequest;
157 } 157 }
158 } 158 }
159 if (!requestEvent) 159 if (!requestEvent)
160 return false; 160 return false;
161 if (!requestEvent.hasListeners()) 161 if (!requestEvent.hasListeners())
162 return false; 162 return false;
163 var port = createPort(portId, channelName); 163 var port = createPort(portId, channelName);
164 port.onMessage.addListener(function(request) { 164
165 function messageListener(request) {
165 var responseCallbackPreserved = false; 166 var responseCallbackPreserved = false;
166 var responseCallback = function(response) { 167 var responseCallback = function(response) {
167 if (port) { 168 if (port) {
168 port.postMessage(response); 169 port.postMessage(response);
169 port.destroy_(); 170 port.destroy_();
170 port = null; 171 port = null;
171 } else { 172 } else {
172 // We nulled out port when sending the response, and now the page 173 // We nulled out port when sending the response, and now the page
173 // is trying to send another response for the same request. 174 // is trying to send another response for the same request.
174 handleSendRequestError(isSendMessage, responseCallbackPreserved, 175 handleSendRequestError(isSendMessage, responseCallbackPreserved,
(...skipping 16 matching lines...) Expand all
191 var rv = requestEvent.dispatch(request, sender, responseCallback); 192 var rv = requestEvent.dispatch(request, sender, responseCallback);
192 responseCallbackPreserved = 193 responseCallbackPreserved =
193 rv && rv.results && $Array.indexOf(rv.results, true) > -1; 194 rv && rv.results && $Array.indexOf(rv.results, true) > -1;
194 if (!responseCallbackPreserved && port) { 195 if (!responseCallbackPreserved && port) {
195 // If they didn't access the response callback, they're not 196 // If they didn't access the response callback, they're not
196 // going to send a response, so clean up the port immediately. 197 // going to send a response, so clean up the port immediately.
197 port.destroy_(); 198 port.destroy_();
198 port = null; 199 port = null;
199 } 200 }
200 } 201 }
201 }); 202 }
203
204 port.onDestroy_ = function() {
205 port.onMessage.removeListener(messageListener);
206 };
207 port.onMessage.addListener(messageListener);
208
202 var eventName = (isSendMessage ? 209 var eventName = (isSendMessage ?
203 (isExternal ? 210 (isExternal ?
204 "runtime.onMessageExternal" : "runtime.onMessage") : 211 "runtime.onMessageExternal" : "runtime.onMessage") :
205 (isExternal ? 212 (isExternal ?
206 "extension.onRequestExternal" : "extension.onRequest")); 213 "extension.onRequestExternal" : "extension.onRequest"));
207 logActivity.LogEvent(targetExtensionId, 214 logActivity.LogEvent(targetExtensionId,
208 eventName, 215 eventName,
209 [sourceExtensionId, sourceUrl]); 216 [sourceExtensionId, sourceUrl]);
210 return true; 217 return true;
211 } 218 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 exports.Port = Port; 370 exports.Port = Port;
364 exports.createPort = createPort; 371 exports.createPort = createPort;
365 exports.sendMessageImpl = sendMessageImpl; 372 exports.sendMessageImpl = sendMessageImpl;
366 exports.sendMessageUpdateArguments = sendMessageUpdateArguments; 373 exports.sendMessageUpdateArguments = sendMessageUpdateArguments;
367 374
368 // For C++ code to call. 375 // For C++ code to call.
369 exports.hasPort = hasPort; 376 exports.hasPort = hasPort;
370 exports.dispatchOnConnect = dispatchOnConnect; 377 exports.dispatchOnConnect = dispatchOnConnect;
371 exports.dispatchOnDisconnect = dispatchOnDisconnect; 378 exports.dispatchOnDisconnect = dispatchOnDisconnect;
372 exports.dispatchOnMessage = dispatchOnMessage; 379 exports.dispatchOnMessage = dispatchOnMessage;
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698