| 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 a message from the ExtensionMessageService. | 80 // Handles requests from ExtensionMessageService to invoke specific |
| 81 // JavaScript functions. Currently we only handle the "disconnect" function. |
| 81 void OnExtensionMessageInvoke(const std::string& extension_id, | 82 void OnExtensionMessageInvoke(const std::string& extension_id, |
| 82 const std::string& function_name, | 83 const std::string& function_name, |
| 83 const base::ListValue& args, | 84 const base::ListValue& args, |
| 84 const GURL& event_url); | 85 const GURL& event_url); |
| 85 // Handles a message sent from an extension through the | 86 // Handles a message sent from an extension through the |
| 86 // ExtensionMessageService, to be passed to the external client. | 87 // ExtensionMessageService, to be passed to the external client. |
| 87 void OnExtensionMessage(const std::string& message, int port_id); | 88 void OnDeliverMessage(int port_id, const std::string& message); |
| 88 // Handles a disconnect event sent from the ExtensionMessageService. | 89 // Handles a disconnect event sent from the ExtensionMessageService. |
| 89 void OnExtensionPortDisconnected(int port_id); | 90 void OnExtensionPortDisconnected(int port_id); |
| 90 | 91 |
| 91 // Implementation for the commands we can receive from the external client. | 92 // Implementation for the commands we can receive from the external client. |
| 92 // Opens a channel to an extension. | 93 // Opens a channel to an extension. |
| 93 void ConnectCommand(base::DictionaryValue* content, | 94 void ConnectCommand(base::DictionaryValue* content, |
| 94 base::DictionaryValue* response); | 95 base::DictionaryValue* response); |
| 95 // Disconnects a message port. | 96 // Disconnects a message port. |
| 96 void DisconnectCommand(int port_id, base::DictionaryValue* response); | 97 void DisconnectCommand(int port_id, base::DictionaryValue* response); |
| 97 // Sends a message to an extension through an established message port. | 98 // Sends a message to an extension through an established message port. |
| 98 void PostMessageCommand(int port_id, | 99 void PostMessageCommand(int port_id, |
| 99 base::DictionaryValue* content, | 100 base::DictionaryValue* content, |
| 100 base::DictionaryValue* response); | 101 base::DictionaryValue* response); |
| 101 | 102 |
| 102 // The delegate is used to send responses and events back to the | 103 // The delegate is used to send responses and events back to the |
| 103 // external client, and to resolve tab IDs. | 104 // external client, and to resolve tab IDs. |
| 104 DevToolsProtocolHandler* delegate_; | 105 DevToolsProtocolHandler* delegate_; |
| 105 | 106 |
| 106 // Set of message port IDs we successfully opened. | 107 // Set of message port IDs we successfully opened. |
| 107 typedef std::set<int> PortIdSet; | 108 typedef std::set<int> PortIdSet; |
| 108 PortIdSet openPortIds_; | 109 PortIdSet openPortIds_; |
| 109 | 110 |
| 110 scoped_refptr<ExtensionMessageService> service_; | 111 scoped_refptr<ExtensionMessageService> service_; |
| 111 | 112 |
| 112 DISALLOW_COPY_AND_ASSIGN(ExtensionPortsRemoteService); | 113 DISALLOW_COPY_AND_ASSIGN(ExtensionPortsRemoteService); |
| 113 }; | 114 }; |
| 114 | 115 |
| 115 #endif // CHROME_BROWSER_DEBUGGER_EXTENSION_PORTS_REMOTE_SERVICE_H_ | 116 #endif // CHROME_BROWSER_DEBUGGER_EXTENSION_PORTS_REMOTE_SERVICE_H_ |
| OLD | NEW |