| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_MESSAGE_PORT_MESSAGE_FILTER_H_ | |
| 6 #define CONTENT_BROWSER_MESSAGE_PORT_MESSAGE_FILTER_H_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "base/macros.h" | |
| 10 #include "content/common/content_export.h" | |
| 11 #include "content/public/browser/browser_message_filter.h" | |
| 12 #include "content/public/browser/message_port_delegate.h" | |
| 13 | |
| 14 // Windows headers will redefine SendMessage. | |
| 15 #ifdef SendMessage | |
| 16 #undef SendMessage | |
| 17 #endif | |
| 18 | |
| 19 struct FrameMsg_PostMessage_Params; | |
| 20 | |
| 21 namespace content { | |
| 22 | |
| 23 // Filter for MessagePort related IPC messages (creating and destroying a | |
| 24 // MessagePort, sending a message via a MessagePort etc). | |
| 25 class CONTENT_EXPORT MessagePortMessageFilter | |
| 26 : public MessagePortDelegate, | |
| 27 public BrowserMessageFilter { | |
| 28 public: | |
| 29 typedef base::Callback<int(void)> NextRoutingIDCallback; | |
| 30 | |
| 31 // |next_routing_id| is owned by this object. It can be used up until | |
| 32 // OnChannelClosing. | |
| 33 explicit MessagePortMessageFilter(const NextRoutingIDCallback& callback); | |
| 34 | |
| 35 // BrowserMessageFilter implementation. | |
| 36 void OnChannelClosing() override; | |
| 37 bool OnMessageReceived(const IPC::Message& message) override; | |
| 38 void OnDestruct() const override; | |
| 39 | |
| 40 int GetNextRoutingID(); | |
| 41 | |
| 42 // MessagePortDelegate implementation. | |
| 43 void SendMessage( | |
| 44 int route_id, | |
| 45 const base::string16& message, | |
| 46 const std::vector<int>& sent_message_ports) override; | |
| 47 void SendMessagesAreQueued(int route_id) override; | |
| 48 | |
| 49 // Updates message ports registered for |message_ports| and returns | |
| 50 // new routing IDs for the updated ports via |new_routing_ids|. | |
| 51 void UpdateMessagePortsWithNewRoutes( | |
| 52 const std::vector<int>& message_ports, | |
| 53 std::vector<int>* new_routing_ids); | |
| 54 | |
| 55 void RouteMessageEventWithMessagePorts( | |
| 56 int routing_id, | |
| 57 const FrameMsg_PostMessage_Params& params); | |
| 58 | |
| 59 protected: | |
| 60 // This is protected, so we can define sub classes for testing. | |
| 61 ~MessagePortMessageFilter() override; | |
| 62 | |
| 63 private: | |
| 64 friend class BrowserThread; | |
| 65 friend class base::DeleteHelper<MessagePortMessageFilter>; | |
| 66 | |
| 67 // Message handlers. | |
| 68 void OnCreateMessagePort(int* route_id, int* message_port_id); | |
| 69 | |
| 70 // This is guaranteed to be valid until OnChannelClosing is invoked, and it's | |
| 71 // not used after. | |
| 72 NextRoutingIDCallback next_routing_id_; | |
| 73 | |
| 74 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePortMessageFilter); | |
| 75 }; | |
| 76 | |
| 77 } // namespace content | |
| 78 | |
| 79 #endif // CONTENT_BROWSER_MESSAGE_PORT_MESSAGE_FILTER_H_ | |
| OLD | NEW |