OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_API_MESSAGING_MESSAGE_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "chrome/browser/extensions/api/messaging/message_property_provider.h" | 16 #include "chrome/browser/extensions/api/messaging/message_property_provider.h" |
17 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h" | |
18 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
19 #include "extensions/browser/api/messaging/native_message_host.h" | |
20 #include "extensions/browser/browser_context_keyed_api_factory.h" | 20 #include "extensions/browser/browser_context_keyed_api_factory.h" |
21 #include "extensions/common/api/messaging/message.h" | 21 #include "extensions/common/api/messaging/message.h" |
22 | 22 |
23 class GURL; | 23 class GURL; |
24 class Profile; | 24 class Profile; |
25 | 25 |
26 namespace base { | 26 namespace base { |
27 class DictionaryValue; | 27 class DictionaryValue; |
28 } | 28 } |
29 | 29 |
(...skipping 24 matching lines...) Expand all Loading... | |
54 // a message to the opposite side of the channel, which may have multiple | 54 // a message to the opposite side of the channel, which may have multiple |
55 // listeners. | 55 // listeners. |
56 // | 56 // |
57 // Terminology: | 57 // Terminology: |
58 // channel: connection between two ports | 58 // channel: connection between two ports |
59 // port: an IPC::Message::Process interface and an optional routing_id (in the | 59 // port: an IPC::Message::Process interface and an optional routing_id (in the |
60 // case that the port is a tab). The Process is usually either a | 60 // case that the port is a tab). The Process is usually either a |
61 // RenderProcessHost or a RenderViewHost. | 61 // RenderProcessHost or a RenderViewHost. |
62 class MessageService : public BrowserContextKeyedAPI, | 62 class MessageService : public BrowserContextKeyedAPI, |
63 public content::NotificationObserver, | 63 public content::NotificationObserver, |
64 public NativeMessageProcessHost::Client { | 64 public NativeMessageHost::Client { |
65 public: | 65 public: |
66 // Result returned from IsHostAllowed(). | |
67 enum PolicyPermission { | |
68 DISALLOW, // The host is not allowed. | |
69 ALLOW_SYSTEM_ONLY, // Allowed only when installed on system level. | |
70 ALLOW_ALL, // Allowed when installed on system or user level. | |
71 }; | |
72 | |
66 // A messaging channel. Note that the opening port can be the same as the | 73 // A messaging channel. Note that the opening port can be the same as the |
67 // receiver, if an extension background page wants to talk to its tab (for | 74 // receiver, if an extension background page wants to talk to its tab (for |
68 // example). | 75 // example). |
69 struct MessageChannel; | 76 struct MessageChannel; |
70 | 77 |
71 // One side of the communication handled by extensions::MessageService. | 78 // One side of the communication handled by extensions::MessageService. |
72 class MessagePort { | 79 class MessagePort { |
73 public: | 80 public: |
74 virtual ~MessagePort() {} | 81 virtual ~MessagePort() {} |
75 // Notify the port that the channel has been opened. | 82 // Notify the port that the channel has been opened. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 | 153 |
147 // Closes the message channel associated with the given port, and notifies | 154 // Closes the message channel associated with the given port, and notifies |
148 // the other side. | 155 // the other side. |
149 virtual void CloseChannel(int port_id, | 156 virtual void CloseChannel(int port_id, |
150 const std::string& error_message) OVERRIDE; | 157 const std::string& error_message) OVERRIDE; |
151 | 158 |
152 // Enqueues a message on a pending channel, or sends a message to the given | 159 // Enqueues a message on a pending channel, or sends a message to the given |
153 // port if the channel isn't pending. | 160 // port if the channel isn't pending. |
154 void PostMessage(int port_id, const Message& message); | 161 void PostMessage(int port_id, const Message& message); |
155 | 162 |
156 // NativeMessageProcessHost::Client | 163 // NativeMessageHost::Client implementation. |
157 virtual void PostMessageFromNativeProcess( | 164 virtual void PostMessageFromNativeHost(int port_id, |
158 int port_id, | 165 const std::string& message) OVERRIDE; |
159 const std::string& message) OVERRIDE; | |
160 | 166 |
161 private: | 167 private: |
168 // Returns policy permissions for the host with the specified name. | |
169 static PolicyPermission IsHostAllowed(const PrefService* pref_service, | |
Sergey Ulanov
2014/09/25 01:45:21
This doesn't really need to be part of the Message
kelvinp
2014/09/26 18:12:27
Done.
| |
170 const std::string& native_host_name); | |
171 | |
162 friend class MockMessageService; | 172 friend class MockMessageService; |
163 friend class BrowserContextKeyedAPIFactory<MessageService>; | 173 friend class BrowserContextKeyedAPIFactory<MessageService>; |
164 struct OpenChannelParams; | 174 struct OpenChannelParams; |
165 | 175 |
166 // A map of channel ID to its channel object. | 176 // A map of channel ID to its channel object. |
167 typedef std::map<int, MessageChannel*> MessageChannelMap; | 177 typedef std::map<int, MessageChannel*> MessageChannelMap; |
168 | 178 |
169 typedef std::pair<int, Message> PendingMessage; | 179 typedef std::pair<int, Message> PendingMessage; |
170 typedef std::vector<PendingMessage> PendingMessagesQueue; | 180 typedef std::vector<PendingMessage> PendingMessagesQueue; |
171 // A set of channel IDs waiting for TLS channel IDs to complete opening, | 181 // A set of channel IDs waiting for TLS channel IDs to complete opening, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 LazyBackgroundTaskQueue* lazy_background_task_queue_; | 278 LazyBackgroundTaskQueue* lazy_background_task_queue_; |
269 | 279 |
270 base::WeakPtrFactory<MessageService> weak_factory_; | 280 base::WeakPtrFactory<MessageService> weak_factory_; |
271 | 281 |
272 DISALLOW_COPY_AND_ASSIGN(MessageService); | 282 DISALLOW_COPY_AND_ASSIGN(MessageService); |
273 }; | 283 }; |
274 | 284 |
275 } // namespace extensions | 285 } // namespace extensions |
276 | 286 |
277 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_ | 287 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_ |
OLD | NEW |