| 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 #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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
| 17 #include "ipc/ipc_message.h" | 17 #include "ipc/ipc_message.h" |
| 18 | 18 |
| 19 class Profile; | 19 class Profile; |
| 20 class TabContents; | 20 |
| 21 namespace content { |
| 22 class WebContents; |
| 23 } |
| 21 | 24 |
| 22 // This class manages message and event passing between renderer processes. | 25 // This class manages message and event passing between renderer processes. |
| 23 // It maintains a list of processes that are listening to events and a set of | 26 // It maintains a list of processes that are listening to events and a set of |
| 24 // open channels. | 27 // open channels. |
| 25 // | 28 // |
| 26 // Messaging works this way: | 29 // Messaging works this way: |
| 27 // - An extension-owned script context (like a background page or a content | 30 // - An extension-owned script context (like a background page or a content |
| 28 // script) adds an event listener to the "onConnect" event. | 31 // script) adds an event listener to the "onConnect" event. |
| 29 // - Another context calls "extension.connect()" to open a channel to the | 32 // - Another context calls "extension.connect()" to open a channel to the |
| 30 // extension process, or an extension context calls "tabs.connect(tabId)" to | 33 // extension process, or an extension context calls "tabs.connect(tabId)" to |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 99 |
| 97 // Given an extension ID, opens a channel between the given DevTools | 100 // Given an extension ID, opens a channel between the given DevTools |
| 98 // service and the content script for that extension running in the | 101 // service and the content script for that extension running in the |
| 99 // designated tab. | 102 // designated tab. |
| 100 // | 103 // |
| 101 // Returns a port ID identifying the DevTools end of the channel, to | 104 // Returns a port ID identifying the DevTools end of the channel, to |
| 102 // be used for posting messages. May return -1 on failure, although | 105 // be used for posting messages. May return -1 on failure, although |
| 103 // the code doesn't detect whether the extension actually exists. | 106 // the code doesn't detect whether the extension actually exists. |
| 104 int OpenSpecialChannelToTab( | 107 int OpenSpecialChannelToTab( |
| 105 const std::string& extension_id, const std::string& channel_name, | 108 const std::string& extension_id, const std::string& channel_name, |
| 106 TabContents* target_tab_contents, IPC::Message::Sender* source); | 109 content::WebContents* target_web_contents, IPC::Message::Sender* source); |
| 107 | 110 |
| 108 // Closes the message channel associated with the given port, and notifies | 111 // Closes the message channel associated with the given port, and notifies |
| 109 // the other side. | 112 // the other side. |
| 110 void CloseChannel(int port_id); | 113 void CloseChannel(int port_id); |
| 111 | 114 |
| 112 // Sends a message from a renderer to the given port. | 115 // Sends a message from a renderer to the given port. |
| 113 void PostMessageFromRenderer(int port_id, const std::string& message); | 116 void PostMessageFromRenderer(int port_id, const std::string& message); |
| 114 | 117 |
| 115 private: | 118 private: |
| 116 friend class base::RefCounted<ExtensionMessageService>; | 119 friend class base::RefCounted<ExtensionMessageService>; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 144 Profile* profile_; | 147 Profile* profile_; |
| 145 | 148 |
| 146 content::NotificationRegistrar registrar_; | 149 content::NotificationRegistrar registrar_; |
| 147 | 150 |
| 148 MessageChannelMap channels_; | 151 MessageChannelMap channels_; |
| 149 | 152 |
| 150 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageService); | 153 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageService); |
| 151 }; | 154 }; |
| 152 | 155 |
| 153 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_ | 156 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_ |
| OLD | NEW |