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 // ExtensionsPorts service: wires extension message ports through the | 5 // ExtensionsPorts service: wires extension message ports through the |
6 // devtools remote protocol, allowing an external client program to | 6 // devtools remote protocol, allowing an external client program to |
7 // exchange messages with Chrome extensions. | 7 // exchange messages with Chrome extensions. |
8 | 8 |
9 #ifndef CHROME_BROWSER_DEBUGGER_EXTENSION_PORTS_REMOTE_SERVICE_H_ | 9 #ifndef CHROME_BROWSER_DEBUGGER_EXTENSION_PORTS_REMOTE_SERVICE_H_ |
10 #define CHROME_BROWSER_DEBUGGER_EXTENSION_PORTS_REMOTE_SERVICE_H_ | 10 #define CHROME_BROWSER_DEBUGGER_EXTENSION_PORTS_REMOTE_SERVICE_H_ |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } Result; | 70 } Result; |
71 | 71 |
72 virtual ~ExtensionPortsRemoteService(); | 72 virtual ~ExtensionPortsRemoteService(); |
73 | 73 |
74 // Sends a JSON message with the |response| to the external client. | 74 // Sends a JSON message with the |response| to the external client. |
75 // |tool| and |destination| are used as the respective header values. | 75 // |tool| and |destination| are used as the respective header values. |
76 void SendResponse(const base::Value& response, | 76 void SendResponse(const base::Value& response, |
77 const std::string& tool, | 77 const std::string& tool, |
78 const std::string& destination); | 78 const std::string& destination); |
79 | 79 |
80 // Handles requests from ExtensionMessageService to invoke specific | 80 // Handles a message from the ExtensionMessageService. |
81 // JavaScript functions. Currently we only handle the "disconnect" function. | |
82 void OnExtensionMessageInvoke(const std::string& extension_id, | 81 void OnExtensionMessageInvoke(const std::string& extension_id, |
83 const std::string& function_name, | 82 const std::string& function_name, |
84 const base::ListValue& args, | 83 const base::ListValue& args, |
85 const GURL& event_url); | 84 const GURL& event_url); |
86 // Handles a message sent from an extension through the | 85 // Handles a message sent from an extension through the |
87 // ExtensionMessageService, to be passed to the external client. | 86 // ExtensionMessageService, to be passed to the external client. |
88 void OnDeliverMessage(int port_id, const std::string& message); | 87 void OnExtensionMessage(const std::string& message, int port_id); |
89 // Handles a disconnect event sent from the ExtensionMessageService. | 88 // Handles a disconnect event sent from the ExtensionMessageService. |
90 void OnExtensionPortDisconnected(int port_id); | 89 void OnExtensionPortDisconnected(int port_id); |
91 | 90 |
92 // Implementation for the commands we can receive from the external client. | 91 // Implementation for the commands we can receive from the external client. |
93 // Opens a channel to an extension. | 92 // Opens a channel to an extension. |
94 void ConnectCommand(base::DictionaryValue* content, | 93 void ConnectCommand(base::DictionaryValue* content, |
95 base::DictionaryValue* response); | 94 base::DictionaryValue* response); |
96 // Disconnects a message port. | 95 // Disconnects a message port. |
97 void DisconnectCommand(int port_id, base::DictionaryValue* response); | 96 void DisconnectCommand(int port_id, base::DictionaryValue* response); |
98 // Sends a message to an extension through an established message port. | 97 // Sends a message to an extension through an established message port. |
99 void PostMessageCommand(int port_id, | 98 void PostMessageCommand(int port_id, |
100 base::DictionaryValue* content, | 99 base::DictionaryValue* content, |
101 base::DictionaryValue* response); | 100 base::DictionaryValue* response); |
102 | 101 |
103 // The delegate is used to send responses and events back to the | 102 // The delegate is used to send responses and events back to the |
104 // external client, and to resolve tab IDs. | 103 // external client, and to resolve tab IDs. |
105 DevToolsProtocolHandler* delegate_; | 104 DevToolsProtocolHandler* delegate_; |
106 | 105 |
107 // Set of message port IDs we successfully opened. | 106 // Set of message port IDs we successfully opened. |
108 typedef std::set<int> PortIdSet; | 107 typedef std::set<int> PortIdSet; |
109 PortIdSet openPortIds_; | 108 PortIdSet openPortIds_; |
110 | 109 |
111 scoped_refptr<ExtensionMessageService> service_; | 110 scoped_refptr<ExtensionMessageService> service_; |
112 | 111 |
113 DISALLOW_COPY_AND_ASSIGN(ExtensionPortsRemoteService); | 112 DISALLOW_COPY_AND_ASSIGN(ExtensionPortsRemoteService); |
114 }; | 113 }; |
115 | 114 |
116 #endif // CHROME_BROWSER_DEBUGGER_EXTENSION_PORTS_REMOTE_SERVICE_H_ | 115 #endif // CHROME_BROWSER_DEBUGGER_EXTENSION_PORTS_REMOTE_SERVICE_H_ |
OLD | NEW |