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_ |
11 #pragma once | 11 #pragma once |
12 | 12 |
13 #include <set> | 13 #include <set> |
14 #include <string> | 14 #include <string> |
15 | 15 |
16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "chrome/browser/extensions/extension_message_service.h" | 18 #include "chrome/browser/extensions/extension_message_service.h" |
19 #include "content/browser/debugger/devtools_remote.h" | 19 #include "content/browser/debugger/devtools_remote.h" |
20 #include "ipc/ipc_message.h" | 20 #include "ipc/ipc_message.h" |
21 | 21 |
22 class DevToolsProtocolHandler; | 22 class DevToolsProtocolHandler; |
23 class DevToolsRemoteMessage; | 23 class DevToolsRemoteMessage; |
| 24 class GURL; |
| 25 |
| 26 namespace base { |
24 class DictionaryValue; | 27 class DictionaryValue; |
25 class GURL; | |
26 class ListValue; | 28 class ListValue; |
27 class Value; | 29 class Value; |
| 30 } |
28 | 31 |
29 class ExtensionPortsRemoteService : public DevToolsRemoteListener, | 32 class ExtensionPortsRemoteService : public DevToolsRemoteListener, |
30 public IPC::Message::Sender { | 33 public IPC::Message::Sender { |
31 public: | 34 public: |
32 // Specifies a tool name ("ExtensionPorts") handled by this class. | 35 // Specifies a tool name ("ExtensionPorts") handled by this class. |
33 static const std::string kToolName; | 36 static const std::string kToolName; |
34 | 37 |
35 // |delegate| (never NULL) is the protocol handler instance which | 38 // |delegate| (never NULL) is the protocol handler instance which |
36 // dispatches messages to this service. | 39 // dispatches messages to this service. |
37 // The ownership of |delegate| is NOT transferred to this class. | 40 // The ownership of |delegate| is NOT transferred to this class. |
(...skipping 25 matching lines...) Expand all Loading... |
63 RESULT_PARAMETER_ERROR, | 66 RESULT_PARAMETER_ERROR, |
64 RESULT_UNKNOWN_PORT, | 67 RESULT_UNKNOWN_PORT, |
65 RESULT_TAB_NOT_FOUND, | 68 RESULT_TAB_NOT_FOUND, |
66 RESULT_CONNECT_FAILED, // probably extension ID not found. | 69 RESULT_CONNECT_FAILED, // probably extension ID not found. |
67 } Result; | 70 } Result; |
68 | 71 |
69 virtual ~ExtensionPortsRemoteService(); | 72 virtual ~ExtensionPortsRemoteService(); |
70 | 73 |
71 // Sends a JSON message with the |response| to the external client. | 74 // Sends a JSON message with the |response| to the external client. |
72 // |tool| and |destination| are used as the respective header values. | 75 // |tool| and |destination| are used as the respective header values. |
73 void SendResponse(const Value& response, | 76 void SendResponse(const base::Value& response, |
74 const std::string& tool, | 77 const std::string& tool, |
75 const std::string& destination); | 78 const std::string& destination); |
76 | 79 |
77 // Handles a message from the ExtensionMessageService. | 80 // Handles a message from the ExtensionMessageService. |
78 void OnExtensionMessageInvoke(const std::string& extension_id, | 81 void OnExtensionMessageInvoke(const std::string& extension_id, |
79 const std::string& function_name, | 82 const std::string& function_name, |
80 const ListValue& args, | 83 const base::ListValue& args, |
81 const GURL& event_url); | 84 const GURL& event_url); |
82 // Handles a message sent from an extension through the | 85 // Handles a message sent from an extension through the |
83 // ExtensionMessageService, to be passed to the external client. | 86 // ExtensionMessageService, to be passed to the external client. |
84 void OnExtensionMessage(const std::string& message, int port_id); | 87 void OnExtensionMessage(const std::string& message, int port_id); |
85 // Handles a disconnect event sent from the ExtensionMessageService. | 88 // Handles a disconnect event sent from the ExtensionMessageService. |
86 void OnExtensionPortDisconnected(int port_id); | 89 void OnExtensionPortDisconnected(int port_id); |
87 | 90 |
88 // Implementation for the commands we can receive from the external client. | 91 // Implementation for the commands we can receive from the external client. |
89 // Opens a channel to an extension. | 92 // Opens a channel to an extension. |
90 void ConnectCommand(DictionaryValue* content, DictionaryValue* response); | 93 void ConnectCommand(base::DictionaryValue* content, |
| 94 base::DictionaryValue* response); |
91 // Disconnects a message port. | 95 // Disconnects a message port. |
92 void DisconnectCommand(int port_id, DictionaryValue* response); | 96 void DisconnectCommand(int port_id, base::DictionaryValue* response); |
93 // Sends a message to an extension through an established message port. | 97 // Sends a message to an extension through an established message port. |
94 void PostMessageCommand(int port_id, DictionaryValue* content, | 98 void PostMessageCommand(int port_id, |
95 DictionaryValue* response); | 99 base::DictionaryValue* content, |
| 100 base::DictionaryValue* response); |
96 | 101 |
97 // 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 |
98 // external client, and to resolve tab IDs. | 103 // external client, and to resolve tab IDs. |
99 DevToolsProtocolHandler* delegate_; | 104 DevToolsProtocolHandler* delegate_; |
100 | 105 |
101 // Set of message port IDs we successfully opened. | 106 // Set of message port IDs we successfully opened. |
102 typedef std::set<int> PortIdSet; | 107 typedef std::set<int> PortIdSet; |
103 PortIdSet openPortIds_; | 108 PortIdSet openPortIds_; |
104 | 109 |
105 scoped_refptr<ExtensionMessageService> service_; | 110 scoped_refptr<ExtensionMessageService> service_; |
106 | 111 |
107 DISALLOW_COPY_AND_ASSIGN(ExtensionPortsRemoteService); | 112 DISALLOW_COPY_AND_ASSIGN(ExtensionPortsRemoteService); |
108 }; | 113 }; |
109 | 114 |
110 #endif // CHROME_BROWSER_DEBUGGER_EXTENSION_PORTS_REMOTE_SERVICE_H_ | 115 #endif // CHROME_BROWSER_DEBUGGER_EXTENSION_PORTS_REMOTE_SERVICE_H_ |
OLD | NEW |