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

Unified Diff: chrome/renderer/extensions/renderer_extension_bindings.cc

Issue 344044: Clean up extension message port data in the renderer. (Closed)
Patch Set: Created 11 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/extensions/renderer_extension_bindings.cc
diff --git a/chrome/renderer/extensions/renderer_extension_bindings.cc b/chrome/renderer/extensions/renderer_extension_bindings.cc
index de958d1323f97892cf8debe366ae70ca39f1ae47..61ab90dbe5b4e3e9ccad939476cefa70c7e5930c 100644
--- a/chrome/renderer/extensions/renderer_extension_bindings.cc
+++ b/chrome/renderer/extensions/renderer_extension_bindings.cc
@@ -37,10 +37,18 @@ struct ExtensionData {
};
std::map<int, PortData> ports; // port ID -> data
};
+bool HasPortData(int port_id) {
+ return Singleton<ExtensionData>::get()->ports.find(port_id) !=
+ Singleton<ExtensionData>::get()->ports.end();
+}
ExtensionData::PortData& GetPortData(int port_id) {
return Singleton<ExtensionData>::get()->ports[port_id];
}
+void ClearPortData(int port_id) {
+ Singleton<ExtensionData>::get()->ports.erase(port_id);
+}
+const char kPortClosedError[] = "Attempting to use a disconnected port object";
const char* kExtensionDeps[] = { EventBindings::kName };
class ExtensionImpl : public ExtensionBase {
@@ -99,6 +107,10 @@ class ExtensionImpl : public ExtensionBase {
if (args.Length() >= 2 && args[0]->IsInt32() && args[1]->IsString()) {
int port_id = args[0]->Int32Value();
+ if (!HasPortData(port_id)) {
+ return v8::ThrowException(v8::Exception::Error(
+ v8::String::New(kPortClosedError)));
+ }
std::string message = *v8::String::Utf8Value(args[1]->ToString());
renderview->Send(new ViewHostMsg_ExtensionPostMessage(
renderview->routing_id(), port_id, message));
@@ -110,10 +122,14 @@ class ExtensionImpl : public ExtensionBase {
static v8::Handle<v8::Value> CloseChannel(const v8::Arguments& args) {
if (args.Length() >= 1 && args[0]->IsInt32()) {
int port_id = args[0]->Int32Value();
+ if (!HasPortData(port_id)) {
Aaron Boodman 2009/10/31 19:21:22 Maybe we don't want to throw here? It seems nice t
Matt Perry 2009/11/03 00:39:36 Done.
+ return v8::ThrowException(v8::Exception::Error(
+ v8::String::New(kPortClosedError)));
+ }
// Send via the RenderThread because the RenderView might be closing.
EventBindings::GetRenderThread()->Send(
new ViewHostMsg_ExtensionCloseChannel(port_id));
- GetPortData(port_id).disconnected = true;
+ ClearPortData(port_id);
}
return v8::Undefined();
}
@@ -134,11 +150,11 @@ class ExtensionImpl : public ExtensionBase {
static v8::Handle<v8::Value> PortRelease(const v8::Arguments& args) {
if (args.Length() >= 1 && args[0]->IsInt32()) {
int port_id = args[0]->Int32Value();
- if (!GetPortData(port_id).disconnected &&
- --GetPortData(port_id).ref_count == 0) {
+ if (HasPortData(port_id) && --GetPortData(port_id).ref_count == 0) {
// Send via the RenderThread because the RenderView might be closing.
EventBindings::GetRenderThread()->Send(
new ViewHostMsg_ExtensionCloseChannel(port_id));
+ ClearPortData(port_id);
}
}
return v8::Undefined();
« 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