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

Unified Diff: extensions/renderer/resources/messaging.js

Issue 1136953017: Add fallback mechanism to release Extension ports if the JS context has been destroyed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tweak Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: extensions/renderer/resources/messaging.js
diff --git a/extensions/renderer/resources/messaging.js b/extensions/renderer/resources/messaging.js
index 9fc29d49752b1e788edc7015cf1c8e4725e5f5e6..5ff748e3c5a2bf172ff6ca3d16bc033eb0758fa8 100644
--- a/extensions/renderer/resources/messaging.js
+++ b/extensions/renderer/resources/messaging.js
@@ -128,12 +128,18 @@
// doesn't keep a reference to it, we need to clean up the port. Do
// so by attaching to the garbage collection of the responseCallback
// using some native hackery.
+ //
+ // If the context is destroyed before this has a chance to execute,
+ // BindToGC knows to release |portId| (important for updating C++ state
+ // both in this renderer and on the other end). We don't need to clear
+ // any JavaScript state, as calling destroy_() would usually do - but
+ // the context has been destroyed, so there isn't any JS state to clear.
messagingNatives.BindToGC(responseCallback, function() {
if (port) {
privates(port).impl.destroy_();
port = null;
}
- });
+ }, portId);
var rv = requestEvent.dispatch(request, sender, responseCallback);
if (isSendMessage) {
responseCallbackPreserved =

Powered by Google App Engine
This is Rietveld 408576698