| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/extensions/extension_message_service.h" | 5 #include "chrome/browser/extensions/extension_message_service.h" |
| 6 | 6 |
| 7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/extensions/extension_process_manager.h" | 11 #include "chrome/browser/extensions/extension_process_manager.h" |
| 12 #include "chrome/browser/extensions/extension_tabs_module.h" | 12 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/tab_contents/tab_util.h" | 14 #include "chrome/browser/tab_contents/tab_util.h" |
| 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 17 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/extensions/extension_messages.h" |
| 18 #include "content/browser/child_process_security_policy.h" | 18 #include "content/browser/child_process_security_policy.h" |
| 19 #include "content/browser/renderer_host/render_process_host.h" | 19 #include "content/browser/renderer_host/render_process_host.h" |
| 20 #include "content/browser/renderer_host/render_view_host.h" | 20 #include "content/browser/renderer_host/render_view_host.h" |
| 21 #include "content/browser/tab_contents/tab_contents.h" | 21 #include "content/browser/tab_contents/tab_contents.h" |
| 22 #include "content/common/notification_service.h" | 22 #include "content/common/notification_service.h" |
| 23 | 23 |
| 24 // Since we have 2 ports for every channel, we just index channels by half the | 24 // Since we have 2 ports for every channel, we just index channels by half the |
| 25 // port ID. | 25 // port ID. |
| 26 #define GET_CHANNEL_ID(port_id) ((port_id) / 2) | 26 #define GET_CHANNEL_ID(port_id) ((port_id) / 2) |
| 27 #define GET_CHANNEL_OPENER_ID(channel_id) ((channel_id) * 2) | 27 #define GET_CHANNEL_OPENER_ID(channel_id) ((channel_id) * 2) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 const std::string& tab_json, | 63 const std::string& tab_json, |
| 64 const std::string& source_extension_id, | 64 const std::string& source_extension_id, |
| 65 const std::string& target_extension_id) { | 65 const std::string& target_extension_id) { |
| 66 ListValue args; | 66 ListValue args; |
| 67 args.Set(0, Value::CreateIntegerValue(dest_port_id)); | 67 args.Set(0, Value::CreateIntegerValue(dest_port_id)); |
| 68 args.Set(1, Value::CreateStringValue(channel_name)); | 68 args.Set(1, Value::CreateStringValue(channel_name)); |
| 69 args.Set(2, Value::CreateStringValue(tab_json)); | 69 args.Set(2, Value::CreateStringValue(tab_json)); |
| 70 args.Set(3, Value::CreateStringValue(source_extension_id)); | 70 args.Set(3, Value::CreateStringValue(source_extension_id)); |
| 71 args.Set(4, Value::CreateStringValue(target_extension_id)); | 71 args.Set(4, Value::CreateStringValue(target_extension_id)); |
| 72 CHECK(port.sender); | 72 CHECK(port.sender); |
| 73 port.sender->Send(new ViewMsg_ExtensionMessageInvoke(port.routing_id, | 73 port.sender->Send(new ExtensionMsg_MessageInvoke(port.routing_id, |
| 74 "", ExtensionMessageService::kDispatchOnConnect, args, GURL())); | 74 "", ExtensionMessageService::kDispatchOnConnect, args, GURL())); |
| 75 } | 75 } |
| 76 | 76 |
| 77 static void DispatchOnDisconnect( | 77 static void DispatchOnDisconnect( |
| 78 const ExtensionMessageService::MessagePort& port, int source_port_id, | 78 const ExtensionMessageService::MessagePort& port, int source_port_id, |
| 79 bool connection_error) { | 79 bool connection_error) { |
| 80 ListValue args; | 80 ListValue args; |
| 81 args.Set(0, Value::CreateIntegerValue(source_port_id)); | 81 args.Set(0, Value::CreateIntegerValue(source_port_id)); |
| 82 args.Set(1, Value::CreateBooleanValue(connection_error)); | 82 args.Set(1, Value::CreateBooleanValue(connection_error)); |
| 83 port.sender->Send(new ViewMsg_ExtensionMessageInvoke(port.routing_id, | 83 port.sender->Send(new ExtensionMsg_MessageInvoke(port.routing_id, |
| 84 "", ExtensionMessageService::kDispatchOnDisconnect, args, GURL())); | 84 "", ExtensionMessageService::kDispatchOnDisconnect, args, GURL())); |
| 85 } | 85 } |
| 86 | 86 |
| 87 static void DispatchOnMessage(const ExtensionMessageService::MessagePort& port, | 87 static void DispatchOnMessage(const ExtensionMessageService::MessagePort& port, |
| 88 const std::string& message, int source_port_id) { | 88 const std::string& message, int source_port_id) { |
| 89 ListValue args; | 89 ListValue args; |
| 90 args.Set(0, Value::CreateStringValue(message)); | 90 args.Set(0, Value::CreateStringValue(message)); |
| 91 args.Set(1, Value::CreateIntegerValue(source_port_id)); | 91 args.Set(1, Value::CreateIntegerValue(source_port_id)); |
| 92 port.sender->Send(new ViewMsg_ExtensionMessageInvoke(port.routing_id, | 92 port.sender->Send(new ExtensionMsg_MessageInvoke(port.routing_id, |
| 93 "", ExtensionMessageService::kDispatchOnMessage, args, GURL())); | 93 "", ExtensionMessageService::kDispatchOnMessage, args, GURL())); |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace | 96 } // namespace |
| 97 | 97 |
| 98 // static | 98 // static |
| 99 void ExtensionMessageService::AllocatePortIdPair(int* port1, int* port2) { | 99 void ExtensionMessageService::AllocatePortIdPair(int* port1, int* port2) { |
| 100 int channel_id = g_next_channel_id.GetNext(); | 100 int channel_id = g_next_channel_id.GetNext(); |
| 101 int port1_id = channel_id * 2; | 101 int port1_id = channel_id * 2; |
| 102 int port2_id = channel_id * 2 + 1; | 102 int port2_id = channel_id * 2 + 1; |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 356 |
| 357 if (current->second->opener.sender == sender) { | 357 if (current->second->opener.sender == sender) { |
| 358 CloseChannelImpl(current, GET_CHANNEL_OPENER_ID(current->first), | 358 CloseChannelImpl(current, GET_CHANNEL_OPENER_ID(current->first), |
| 359 notify_other_port); | 359 notify_other_port); |
| 360 } else if (current->second->receiver.sender == sender) { | 360 } else if (current->second->receiver.sender == sender) { |
| 361 CloseChannelImpl(current, GET_CHANNEL_RECEIVERS_ID(current->first), | 361 CloseChannelImpl(current, GET_CHANNEL_RECEIVERS_ID(current->first), |
| 362 notify_other_port); | 362 notify_other_port); |
| 363 } | 363 } |
| 364 } | 364 } |
| 365 } | 365 } |
| OLD | NEW |