| Index: extensions/renderer/messaging_bindings.cc
|
| diff --git a/extensions/renderer/messaging_bindings.cc b/extensions/renderer/messaging_bindings.cc
|
| index 777f24f433f7b7ab1897ea05e2dcf0868276ddda..b3247ecb5bbeff3f86ffb90147cc883b7d2c334c 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();
|
| + 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,15 @@ 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));
|
| }
|
| }
|
|
|
|
|