| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 static const char kDispatchOnDisconnect[]; | 55 static const char kDispatchOnDisconnect[]; |
| 56 static const char kDispatchOnMessage[]; | 56 static const char kDispatchOnMessage[]; |
| 57 static const char kDispatchEvent[]; | 57 static const char kDispatchEvent[]; |
| 58 static const char kDispatchError[]; | 58 static const char kDispatchError[]; |
| 59 | 59 |
| 60 // A messaging channel. Note that the opening port can be the same as the | 60 // A messaging channel. Note that the opening port can be the same as the |
| 61 // receiver, if an extension toolstrip wants to talk to its tab (for example). | 61 // receiver, if an extension toolstrip wants to talk to its tab (for example). |
| 62 struct MessageChannel; | 62 struct MessageChannel; |
| 63 struct MessagePort; | 63 struct MessagePort; |
| 64 | 64 |
| 65 // Returns the event name for an event that is extension-specific. |
| 66 static std::string GetPerExtensionEventName(const std::string& event_name, |
| 67 const std::string& extension_id); |
| 68 |
| 65 // --- UI thread only: | 69 // --- UI thread only: |
| 66 | 70 |
| 67 explicit ExtensionMessageService(Profile* profile); | 71 explicit ExtensionMessageService(Profile* profile); |
| 68 | 72 |
| 69 // Notification that our owning profile is going away. | 73 // Notification that our owning profile is going away. |
| 70 void ProfileDestroyed(); | 74 void ProfileDestroyed(); |
| 71 | 75 |
| 72 // Add or remove |render_process_pid| as a listener for |event_name|. | 76 // Add or remove |render_process_pid| as a listener for |event_name|. |
| 73 void AddEventListener(const std::string& event_name, int render_process_id); | 77 void AddEventListener(const std::string& event_name, int render_process_id); |
| 74 void RemoveEventListener(const std::string& event_name, | 78 void RemoveEventListener(const std::string& event_name, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 85 void PostMessageFromRenderer(int port_id, const std::string& message); | 89 void PostMessageFromRenderer(int port_id, const std::string& message); |
| 86 | 90 |
| 87 // Send an event to every registered extension renderer. If | 91 // Send an event to every registered extension renderer. If |
| 88 // |has_incognito_data| is true, the event is only sent to extension with the | 92 // |has_incognito_data| is true, the event is only sent to extension with the |
| 89 // permission to access incognito data. If |event_url| is not empty, the | 93 // permission to access incognito data. If |event_url| is not empty, the |
| 90 // event is only sent to extension with host permissions for this url. | 94 // event is only sent to extension with host permissions for this url. |
| 91 virtual void DispatchEventToRenderers( | 95 virtual void DispatchEventToRenderers( |
| 92 const std::string& event_name, const std::string& event_args, | 96 const std::string& event_name, const std::string& event_args, |
| 93 bool has_incognito_data, const GURL& event_url); | 97 bool has_incognito_data, const GURL& event_url); |
| 94 | 98 |
| 99 // Same as above, except use the extension-specific naming scheme for the |
| 100 // event. This is used by events that are per-extension. |
| 101 void DispatchEventToExtension( |
| 102 const std::string& extension_id, |
| 103 const std::string& event_name, const std::string& event_args, |
| 104 bool has_incognito_data, const GURL& event_url); |
| 105 |
| 95 // Given an extension ID, opens a channel between the given | 106 // Given an extension ID, opens a channel between the given |
| 96 // automation "port" or DevTools service and that extension. the | 107 // automation "port" or DevTools service and that extension. the |
| 97 // channel will be open to the extension process hosting the | 108 // channel will be open to the extension process hosting the |
| 98 // background page and tool strip. | 109 // background page and tool strip. |
| 99 // | 110 // |
| 100 // Returns a port ID to be used for posting messages between the | 111 // Returns a port ID to be used for posting messages between the |
| 101 // processes, or -1 if the extension doesn't exist. | 112 // processes, or -1 if the extension doesn't exist. |
| 102 int OpenSpecialChannelToExtension( | 113 int OpenSpecialChannelToExtension( |
| 103 const std::string& extension_id, const std::string& channel_name, | 114 const std::string& extension_id, const std::string& channel_name, |
| 104 const std::string& tab_json, IPC::Message::Sender* source); | 115 const std::string& tab_json, IPC::Message::Sender* source); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 int next_port_id_; | 215 int next_port_id_; |
| 205 | 216 |
| 206 // Protects the next_port_id_ variable, since it can be | 217 // Protects the next_port_id_ variable, since it can be |
| 207 // used on the IO thread or the UI thread. | 218 // used on the IO thread or the UI thread. |
| 208 Lock next_port_id_lock_; | 219 Lock next_port_id_lock_; |
| 209 | 220 |
| 210 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageService); | 221 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageService); |
| 211 }; | 222 }; |
| 212 | 223 |
| 213 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_ | 224 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_ |
| OLD | NEW |