| 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.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 struct ExtensionMessageService::MessageChannel { | 44 struct ExtensionMessageService::MessageChannel { |
| 45 ExtensionMessageService::MessagePort opener; | 45 ExtensionMessageService::MessagePort opener; |
| 46 ExtensionMessageService::MessagePort receiver; | 46 ExtensionMessageService::MessagePort receiver; |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 const char ExtensionMessageService::kDispatchOnConnect[] = | 49 const char ExtensionMessageService::kDispatchOnConnect[] = |
| 50 "Port.dispatchOnConnect"; | 50 "Port.dispatchOnConnect"; |
| 51 const char ExtensionMessageService::kDispatchOnDisconnect[] = | 51 const char ExtensionMessageService::kDispatchOnDisconnect[] = |
| 52 "Port.dispatchOnDisconnect"; | 52 "Port.dispatchOnDisconnect"; |
| 53 const char ExtensionMessageService::kDispatchOnMessage[] = |
| 54 "Port.dispatchOnMessage"; |
| 53 | 55 |
| 54 namespace { | 56 namespace { |
| 55 | 57 |
| 56 static base::AtomicSequenceNumber g_next_channel_id(base::LINKER_INITIALIZED); | 58 static base::AtomicSequenceNumber g_next_channel_id(base::LINKER_INITIALIZED); |
| 57 | 59 |
| 58 static void DispatchOnConnect(const ExtensionMessageService::MessagePort& port, | 60 static void DispatchOnConnect(const ExtensionMessageService::MessagePort& port, |
| 59 int dest_port_id, | 61 int dest_port_id, |
| 60 const std::string& channel_name, | 62 const std::string& channel_name, |
| 61 const std::string& tab_json, | 63 const std::string& tab_json, |
| 62 const std::string& source_extension_id, | 64 const std::string& source_extension_id, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 79 const ExtensionMessageService::MessagePort& port, int source_port_id, | 81 const ExtensionMessageService::MessagePort& port, int source_port_id, |
| 80 bool connection_error) { | 82 bool connection_error) { |
| 81 ListValue args; | 83 ListValue args; |
| 82 args.Set(0, Value::CreateIntegerValue(source_port_id)); | 84 args.Set(0, Value::CreateIntegerValue(source_port_id)); |
| 83 args.Set(1, Value::CreateBooleanValue(connection_error)); | 85 args.Set(1, Value::CreateBooleanValue(connection_error)); |
| 84 port.sender->Send(new ExtensionMsg_MessageInvoke(port.routing_id, | 86 port.sender->Send(new ExtensionMsg_MessageInvoke(port.routing_id, |
| 85 "", ExtensionMessageService::kDispatchOnDisconnect, args, GURL())); | 87 "", ExtensionMessageService::kDispatchOnDisconnect, args, GURL())); |
| 86 } | 88 } |
| 87 | 89 |
| 88 static void DispatchOnMessage(const ExtensionMessageService::MessagePort& port, | 90 static void DispatchOnMessage(const ExtensionMessageService::MessagePort& port, |
| 89 const std::string& message, int target_port_id) { | 91 const std::string& message, int source_port_id) { |
| 90 port.sender->Send( | 92 ListValue args; |
| 91 new ExtensionMsg_DeliverMessage( | 93 args.Set(0, Value::CreateStringValue(message)); |
| 92 port.routing_id, target_port_id, message)); | 94 args.Set(1, Value::CreateIntegerValue(source_port_id)); |
| 95 port.sender->Send(new ExtensionMsg_MessageInvoke(port.routing_id, |
| 96 "", ExtensionMessageService::kDispatchOnMessage, args, GURL())); |
| 93 } | 97 } |
| 94 | 98 |
| 95 } // namespace | 99 } // namespace |
| 96 | 100 |
| 97 // static | 101 // static |
| 98 void ExtensionMessageService::AllocatePortIdPair(int* port1, int* port2) { | 102 void ExtensionMessageService::AllocatePortIdPair(int* port1, int* port2) { |
| 99 int channel_id = g_next_channel_id.GetNext(); | 103 int channel_id = g_next_channel_id.GetNext(); |
| 100 int port1_id = channel_id * 2; | 104 int port1_id = channel_id * 2; |
| 101 int port2_id = channel_id * 2 + 1; | 105 int port2_id = channel_id * 2 + 1; |
| 102 | 106 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 361 |
| 358 if (current->second->opener.sender == sender) { | 362 if (current->second->opener.sender == sender) { |
| 359 CloseChannelImpl(current, GET_CHANNEL_OPENER_ID(current->first), | 363 CloseChannelImpl(current, GET_CHANNEL_OPENER_ID(current->first), |
| 360 notify_other_port); | 364 notify_other_port); |
| 361 } else if (current->second->receiver.sender == sender) { | 365 } else if (current->second->receiver.sender == sender) { |
| 362 CloseChannelImpl(current, GET_CHANNEL_RECEIVERS_ID(current->first), | 366 CloseChannelImpl(current, GET_CHANNEL_RECEIVERS_ID(current->first), |
| 363 notify_other_port); | 367 notify_other_port); |
| 364 } | 368 } |
| 365 } | 369 } |
| 366 } | 370 } |
| OLD | NEW |