| 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 <memory> |
| 9 #include <set> | 10 #include <set> |
| 10 #include <string> | 11 #include <string> |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/extensions/api/messaging/message_property_provider.h" | 18 #include "chrome/browser/extensions/api/messaging/message_property_provider.h" |
| 19 #include "extensions/browser/api/messaging/native_message_host.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 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 virtual void RemoveCommonFrames(const MessagePort& port); | 69 virtual void RemoveCommonFrames(const MessagePort& port); |
| 70 | 70 |
| 71 // Check whether the given RenderFrameHost is associated with this port. | 71 // Check whether the given RenderFrameHost is associated with this port. |
| 72 virtual bool HasFrame(content::RenderFrameHost* rfh) const; | 72 virtual bool HasFrame(content::RenderFrameHost* rfh) const; |
| 73 | 73 |
| 74 // Called right before a port is connected to a channel. If false, the port | 74 // Called right before a port is connected to a channel. If false, the port |
| 75 // is not used and the channel is closed. | 75 // is not used and the channel is closed. |
| 76 virtual bool IsValidPort() = 0; | 76 virtual bool IsValidPort() = 0; |
| 77 | 77 |
| 78 // Notify the port that the channel has been opened. | 78 // Notify the port that the channel has been opened. |
| 79 virtual void DispatchOnConnect(const std::string& channel_name, | 79 virtual void DispatchOnConnect( |
| 80 scoped_ptr<base::DictionaryValue> source_tab, | 80 const std::string& channel_name, |
| 81 int source_frame_id, | 81 std::unique_ptr<base::DictionaryValue> source_tab, |
| 82 int guest_process_id, | 82 int source_frame_id, |
| 83 int guest_render_frame_routing_id, | 83 int guest_process_id, |
| 84 const std::string& source_extension_id, | 84 int guest_render_frame_routing_id, |
| 85 const std::string& target_extension_id, | 85 const std::string& source_extension_id, |
| 86 const GURL& source_url, | 86 const std::string& target_extension_id, |
| 87 const std::string& tls_channel_id) {} | 87 const GURL& source_url, |
| 88 const std::string& tls_channel_id) {} |
| 88 | 89 |
| 89 // Notify the port that the channel has been closed. If |error_message| is | 90 // Notify the port that the channel has been closed. If |error_message| is |
| 90 // non-empty, it indicates an error occurred while opening the connection. | 91 // non-empty, it indicates an error occurred while opening the connection. |
| 91 virtual void DispatchOnDisconnect(const std::string& error_message) {} | 92 virtual void DispatchOnDisconnect(const std::string& error_message) {} |
| 92 | 93 |
| 93 // Dispatch a message to this end of the communication. | 94 // Dispatch a message to this end of the communication. |
| 94 virtual void DispatchOnMessage(const Message& message) = 0; | 95 virtual void DispatchOnMessage(const Message& message) = 0; |
| 95 | 96 |
| 96 // Mark the port as opened by the specific frame. | 97 // Mark the port as opened by the specific frame. |
| 97 virtual void OpenPort(int process_id, int routing_id) {} | 98 virtual void OpenPort(int process_id, int routing_id) {} |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 PendingLazyBackgroundPageChannelMap; | 203 PendingLazyBackgroundPageChannelMap; |
| 203 | 204 |
| 204 // Common implementation for opening a channel configured by |params|. | 205 // Common implementation for opening a channel configured by |params|. |
| 205 // | 206 // |
| 206 // |target_extension| will be non-null if |params->target_extension_id| is | 207 // |target_extension| will be non-null if |params->target_extension_id| is |
| 207 // non-empty, that is, if the target is an extension, it must exist. | 208 // non-empty, that is, if the target is an extension, it must exist. |
| 208 // | 209 // |
| 209 // |did_enqueue| will be true if the channel opening was delayed while | 210 // |did_enqueue| will be true if the channel opening was delayed while |
| 210 // waiting for an event page to start, false otherwise. | 211 // waiting for an event page to start, false otherwise. |
| 211 void OpenChannelImpl(content::BrowserContext* browser_context, | 212 void OpenChannelImpl(content::BrowserContext* browser_context, |
| 212 scoped_ptr<OpenChannelParams> params, | 213 std::unique_ptr<OpenChannelParams> params, |
| 213 const Extension* target_extension, | 214 const Extension* target_extension, |
| 214 bool did_enqueue); | 215 bool did_enqueue); |
| 215 | 216 |
| 216 void ClosePortImpl(int port_id, | 217 void ClosePortImpl(int port_id, |
| 217 int process_id, | 218 int process_id, |
| 218 int routing_id, | 219 int routing_id, |
| 219 bool force_close, | 220 bool force_close, |
| 220 const std::string& error_message); | 221 const std::string& error_message); |
| 221 | 222 |
| 222 void CloseChannelImpl(MessageChannelMap::iterator channel_iter, | 223 void CloseChannelImpl(MessageChannelMap::iterator channel_iter, |
| 223 int port_id, | 224 int port_id, |
| 224 const std::string& error_message, | 225 const std::string& error_message, |
| 225 bool notify_other_port); | 226 bool notify_other_port); |
| 226 | 227 |
| 227 // Have MessageService take ownership of |channel|, and remove any pending | 228 // Have MessageService take ownership of |channel|, and remove any pending |
| 228 // channels with the same id. | 229 // channels with the same id. |
| 229 void AddChannel(MessageChannel* channel, int receiver_port_id); | 230 void AddChannel(MessageChannel* channel, int receiver_port_id); |
| 230 | 231 |
| 231 // If the channel is being opened from an incognito tab the user must allow | 232 // If the channel is being opened from an incognito tab the user must allow |
| 232 // the connection. | 233 // the connection. |
| 233 void OnOpenChannelAllowed(scoped_ptr<OpenChannelParams> params, bool allowed); | 234 void OnOpenChannelAllowed(std::unique_ptr<OpenChannelParams> params, |
| 234 void GotChannelID(scoped_ptr<OpenChannelParams> params, | 235 bool allowed); |
| 236 void GotChannelID(std::unique_ptr<OpenChannelParams> params, |
| 235 const std::string& tls_channel_id); | 237 const std::string& tls_channel_id); |
| 236 | 238 |
| 237 // Enqueues a message on a pending channel. | 239 // Enqueues a message on a pending channel. |
| 238 void EnqueuePendingMessage(int port_id, int channel_id, | 240 void EnqueuePendingMessage(int port_id, int channel_id, |
| 239 const Message& message); | 241 const Message& message); |
| 240 | 242 |
| 241 // Enqueues a message on a channel pending on a lazy background page load. | 243 // Enqueues a message on a channel pending on a lazy background page load. |
| 242 void EnqueuePendingMessageForLazyBackgroundLoad(int port_id, | 244 void EnqueuePendingMessageForLazyBackgroundLoad(int port_id, |
| 243 int channel_id, | 245 int channel_id, |
| 244 const Message& message); | 246 const Message& message); |
| 245 | 247 |
| 246 // Immediately sends a message to the given port. | 248 // Immediately sends a message to the given port. |
| 247 void DispatchMessage(int port_id, MessageChannel* channel, | 249 void DispatchMessage(int port_id, MessageChannel* channel, |
| 248 const Message& message); | 250 const Message& message); |
| 249 | 251 |
| 250 // Potentially registers a pending task with the LazyBackgroundTaskQueue | 252 // Potentially registers a pending task with the LazyBackgroundTaskQueue |
| 251 // to open a channel. Returns true if a task was queued. | 253 // to open a channel. Returns true if a task was queued. |
| 252 // Takes ownership of |params| if true is returned. | 254 // Takes ownership of |params| if true is returned. |
| 253 bool MaybeAddPendingLazyBackgroundPageOpenChannelTask( | 255 bool MaybeAddPendingLazyBackgroundPageOpenChannelTask( |
| 254 content::BrowserContext* context, | 256 content::BrowserContext* context, |
| 255 const Extension* extension, | 257 const Extension* extension, |
| 256 scoped_ptr<OpenChannelParams>* params, | 258 std::unique_ptr<OpenChannelParams>* params, |
| 257 const PendingMessagesQueue& pending_messages); | 259 const PendingMessagesQueue& pending_messages); |
| 258 | 260 |
| 259 // Callbacks for LazyBackgroundTaskQueue tasks. The queue passes in an | 261 // Callbacks for LazyBackgroundTaskQueue tasks. The queue passes in an |
| 260 // ExtensionHost to its task callbacks, though some of our callbacks don't | 262 // ExtensionHost to its task callbacks, though some of our callbacks don't |
| 261 // use that argument. | 263 // use that argument. |
| 262 void PendingLazyBackgroundPageOpenChannel( | 264 void PendingLazyBackgroundPageOpenChannel( |
| 263 scoped_ptr<OpenChannelParams> params, | 265 std::unique_ptr<OpenChannelParams> params, |
| 264 int source_process_id, | 266 int source_process_id, |
| 265 extensions::ExtensionHost* host); | 267 extensions::ExtensionHost* host); |
| 266 void PendingLazyBackgroundPageClosePort(int port_id, | 268 void PendingLazyBackgroundPageClosePort(int port_id, |
| 267 int process_id, | 269 int process_id, |
| 268 int routing_id, | 270 int routing_id, |
| 269 bool force_close, | 271 bool force_close, |
| 270 const std::string& error_message, | 272 const std::string& error_message, |
| 271 extensions::ExtensionHost* host) { | 273 extensions::ExtensionHost* host) { |
| 272 if (host) | 274 if (host) |
| 273 ClosePortImpl(port_id, process_id, routing_id, force_close, | 275 ClosePortImpl(port_id, process_id, routing_id, force_close, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 LazyBackgroundTaskQueue* lazy_background_task_queue_; | 316 LazyBackgroundTaskQueue* lazy_background_task_queue_; |
| 315 | 317 |
| 316 base::WeakPtrFactory<MessageService> weak_factory_; | 318 base::WeakPtrFactory<MessageService> weak_factory_; |
| 317 | 319 |
| 318 DISALLOW_COPY_AND_ASSIGN(MessageService); | 320 DISALLOW_COPY_AND_ASSIGN(MessageService); |
| 319 }; | 321 }; |
| 320 | 322 |
| 321 } // namespace extensions | 323 } // namespace extensions |
| 322 | 324 |
| 323 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_ | 325 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_ |
| OLD | NEW |