Chromium Code Reviews| Index: extensions/renderer/messaging_bindings.cc |
| diff --git a/extensions/renderer/messaging_bindings.cc b/extensions/renderer/messaging_bindings.cc |
| index 777f24f433f7b7ab1897ea05e2dcf0868276ddda..def497c33535bc0af504003a48e98a0e98f94f6f 100644 |
| --- a/extensions/renderer/messaging_bindings.cc |
| +++ b/extensions/renderer/messaging_bindings.cc |
| @@ -128,8 +128,6 @@ class PortTracker { |
| base::LazyInstance<PortTracker> g_port_tracker = LAZY_INSTANCE_INITIALIZER; |
| const char kPortClosedError[] = "Attempting to use a disconnected port object"; |
| -const char kReceivingEndDoesntExistError[] = |
| - "Could not establish connection. Receiving end does not exist."; |
| class ExtensionImpl : public ObjectBackedNativeHandler { |
| public: |
| @@ -207,10 +205,10 @@ class ExtensionImpl : public ObjectBackedNativeHandler { |
| // Send via the RenderThread because the RenderFrame might be closing. |
| bool notify_browser = args[1].As<v8::Boolean>()->Value(); |
| - if (notify_browser) { |
| - content::RenderThread::Get()->Send( |
| - new ExtensionHostMsg_CloseChannel(port_id, std::string())); |
| - } |
| + content::RenderFrame* renderframe = context()->GetRenderFrame(); |
|
Devlin
2015/10/30 01:49:39
nit: I think render_frame is more common.
robwu
2015/11/02 19:08:34
Indeed, but this file only uses |renderframe| (2x
|
| + if (notify_browser && renderframe) |
| + renderframe->Send(new ExtensionHostMsg_CloseMessagePort( |
| + renderframe->GetRoutingID(), port_id, true)); |
| ClearPortDataAndNotifyDispatcher(port_id); |
| } |
| @@ -238,12 +236,11 @@ class ExtensionImpl : public ObjectBackedNativeHandler { |
| // Releases the reference to |port_id| for this context, and clears all port |
| // data if there are no more references. |
| void ReleasePort(int port_id) { |
| + content::RenderFrame* renderframe = context()->GetRenderFrame(); |
| if (g_port_tracker.Get().RemoveReference(context(), port_id) && |
| - !g_port_tracker.Get().HasPort(port_id)) { |
| - // Send via the RenderThread because the RenderFrame might be closing. |
| - content::RenderThread::Get()->Send( |
| - new ExtensionHostMsg_CloseChannel(port_id, std::string())); |
| - ClearPortDataAndNotifyDispatcher(port_id); |
| + !g_port_tracker.Get().HasPort(port_id) && renderframe) { |
| + renderframe->Send(new ExtensionHostMsg_CloseMessagePort( |
| + renderframe->GetRoutingID(), port_id, false)); |
| } |
| } |
| @@ -284,23 +281,6 @@ void DispatchOnConnectToScriptContext( |
| const std::string& tls_channel_id, |
| bool* port_created, |
| ScriptContext* script_context) { |
| - // Only dispatch the events if this is the requested target frame (0 = main |
| - // frame; positive = child frame). |
| - content::RenderFrame* renderframe = script_context->GetRenderFrame(); |
| - if (info.target_frame_id == 0 && renderframe->GetWebFrame()->parent() != NULL) |
| - return; |
| - if (info.target_frame_id > 0 && |
| - renderframe->GetRoutingID() != info.target_frame_id) |
| - return; |
| - |
| - // Bandaid fix for crbug.com/520303. |
| - // TODO(rdevlin.cronin): Fix this properly by routing messages to the correct |
| - // RenderFrame from the browser (same with |target_frame_id| in fact). |
| - if (info.target_tab_id != -1 && |
| - info.target_tab_id != ExtensionFrameHelper::Get(renderframe)->tab_id()) { |
| - return; |
| - } |
| - |
| v8::Isolate* isolate = script_context->isolate(); |
| v8::HandleScope handle_scope(isolate); |
| @@ -470,11 +450,14 @@ void MessagingBindings::DispatchOnConnect( |
| base::Bind(&DispatchOnConnectToScriptContext, target_port_id, |
| channel_name, &source, info, tls_channel_id, &port_created)); |
| - // If we didn't create a port, notify the other end of the channel (treat it |
| - // as a disconnect). |
| - if (!port_created) { |
| - content::RenderThread::Get()->Send(new ExtensionHostMsg_CloseChannel( |
| - target_port_id, kReceivingEndDoesntExistError)); |
| + int routing_id = restrict_to_render_frame ? |
| + restrict_to_render_frame->GetRoutingID() : MSG_ROUTING_NONE; |
| + if (port_created) { |
| + content::RenderThread::Get()->Send(new ExtensionHostMsg_OpenMessagePort( |
| + routing_id, target_port_id)); |
| + } else { |
| + content::RenderThread::Get()->Send(new ExtensionHostMsg_CloseMessagePort( |
| + routing_id, target_port_id, false)); |
| } |
| } |