| 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 CONTENT_PUBLIC_BROWSER_BROWSER_MESSAGE_FILTER_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_BROWSER_MESSAGE_FILTER_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_BROWSER_MESSAGE_FILTER_H_ | 6 #define CONTENT_PUBLIC_BROWSER_BROWSER_MESSAGE_FILTER_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/process/process.h" | 9 #include "base/process/process.h" |
| 10 #include "content/common/content_export.h" | 10 #include "content/common/content_export.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 namespace content { | 22 namespace content { |
| 23 struct BrowserMessageFilterTraits; | 23 struct BrowserMessageFilterTraits; |
| 24 | 24 |
| 25 // Base class for message filters in the browser process. You can receive and | 25 // Base class for message filters in the browser process. You can receive and |
| 26 // send messages on any thread. | 26 // send messages on any thread. |
| 27 class CONTENT_EXPORT BrowserMessageFilter | 27 class CONTENT_EXPORT BrowserMessageFilter |
| 28 : public base::RefCountedThreadSafe< | 28 : public base::RefCountedThreadSafe< |
| 29 BrowserMessageFilter, BrowserMessageFilterTraits>, | 29 BrowserMessageFilter, BrowserMessageFilterTraits>, |
| 30 public IPC::Sender { | 30 public IPC::Sender { |
| 31 public: | 31 public: |
| 32 explicit BrowserMessageFilter(uint32 message_class_to_filter); | 32 BrowserMessageFilter(); |
| 33 BrowserMessageFilter(const uint32* message_classes_to_filter, | |
| 34 size_t num_message_classes_to_filter); | |
| 35 | 33 |
| 36 // These match the corresponding IPC::ChannelProxy::MessageFilter methods and | 34 // These match the corresponding IPC::ChannelProxy::MessageFilter methods and |
| 37 // are always called on the IO thread. | 35 // are always called on the IO thread. |
| 38 virtual void OnFilterAdded(IPC::Channel* channel) {} | 36 virtual void OnFilterAdded(IPC::Channel* channel) {} |
| 39 virtual void OnFilterRemoved() {} | 37 virtual void OnFilterRemoved() {} |
| 40 virtual void OnChannelClosing() {} | 38 virtual void OnChannelClosing() {} |
| 41 virtual void OnChannelConnected(int32 peer_pid) {} | 39 virtual void OnChannelConnected(int32 peer_pid) {} |
| 42 | 40 |
| 43 // Called when the message filter is about to be deleted. This gives | 41 // Called when the message filter is about to be deleted. This gives |
| 44 // derived classes the option of controlling which thread they're deleted | 42 // derived classes the option of controlling which thread they're deleted |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 84 |
| 87 // Checks that the given message can be dispatched on the UI thread, depending | 85 // Checks that the given message can be dispatched on the UI thread, depending |
| 88 // on the platform. If not, returns false and an error ot the sender. | 86 // on the platform. If not, returns false and an error ot the sender. |
| 89 static bool CheckCanDispatchOnUI(const IPC::Message& message, | 87 static bool CheckCanDispatchOnUI(const IPC::Message& message, |
| 90 IPC::Sender* sender); | 88 IPC::Sender* sender); |
| 91 | 89 |
| 92 // Call this if a message couldn't be deserialized. This kills the renderer. | 90 // Call this if a message couldn't be deserialized. This kills the renderer. |
| 93 // Can be called on any thread. | 91 // Can be called on any thread. |
| 94 virtual void BadMessageReceived(); | 92 virtual void BadMessageReceived(); |
| 95 | 93 |
| 96 const std::vector<uint32>& message_classes_to_filter() const { | |
| 97 return message_classes_to_filter_; | |
| 98 } | |
| 99 | |
| 100 protected: | 94 protected: |
| 101 virtual ~BrowserMessageFilter(); | 95 virtual ~BrowserMessageFilter(); |
| 102 | 96 |
| 103 private: | 97 private: |
| 104 friend class base::RefCountedThreadSafe<BrowserMessageFilter, | 98 friend class base::RefCountedThreadSafe<BrowserMessageFilter, |
| 105 BrowserMessageFilterTraits>; | 99 BrowserMessageFilterTraits>; |
| 106 | 100 |
| 107 class Internal; | 101 class Internal; |
| 108 friend class BrowserChildProcessHostImpl; | 102 friend class BrowserChildProcessHostImpl; |
| 109 friend class BrowserPpapiHost; | 103 friend class BrowserPpapiHost; |
| 110 friend class RenderProcessHostImpl; | 104 friend class RenderProcessHostImpl; |
| 111 | 105 |
| 112 // This is private because the only classes that need access to it are made | 106 // This is private because the only classes that need access to it are made |
| 113 // friends above. This is only guaranteed to be valid on creation, after that | 107 // friends above. This is only guaranteed to be valid on creation, after that |
| 114 // this class could outlive the filter. | 108 // this class could outlive the filter. |
| 115 IPC::ChannelProxy::MessageFilter* GetFilter(); | 109 IPC::ChannelProxy::MessageFilter* GetFilter(); |
| 116 | 110 |
| 117 // This implements IPC::ChannelProxy::MessageFilter so that we can hide that | 111 // This implements IPC::ChannelProxy::MessageFilter so that we can hide that |
| 118 // from child classes. Internal keeps a reference to this class, which is why | 112 // from child classes. Internal keeps a reference to this class, which is why |
| 119 // there's a weak pointer back. This class could outlive Internal based on | 113 // there's a weak pointer back. This class could outlive Internal based on |
| 120 // what the child class does in its OnDestruct method. | 114 // what the child class does in its OnDestruct method. |
| 121 Internal* internal_; | 115 Internal* internal_; |
| 122 | 116 |
| 123 IPC::Channel* channel_; | 117 IPC::Channel* channel_; |
| 124 base::ProcessId peer_pid_; | 118 base::ProcessId peer_pid_; |
| 125 | 119 |
| 126 std::vector<uint32> message_classes_to_filter_; | |
| 127 | |
| 128 #if defined(OS_WIN) | 120 #if defined(OS_WIN) |
| 129 base::Lock peer_handle_lock_; | 121 base::Lock peer_handle_lock_; |
| 130 base::ProcessHandle peer_handle_; | 122 base::ProcessHandle peer_handle_; |
| 131 #endif | 123 #endif |
| 132 }; | 124 }; |
| 133 | 125 |
| 134 struct BrowserMessageFilterTraits { | 126 struct BrowserMessageFilterTraits { |
| 135 static void Destruct(const BrowserMessageFilter* filter) { | 127 static void Destruct(const BrowserMessageFilter* filter) { |
| 136 filter->OnDestruct(); | 128 filter->OnDestruct(); |
| 137 } | 129 } |
| 138 }; | 130 }; |
| 139 | 131 |
| 140 } // namespace content | 132 } // namespace content |
| 141 | 133 |
| 142 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_MESSAGE_FILTER_H_ | 134 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_MESSAGE_FILTER_H_ |
| OLD | NEW |