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 #include "ppapi/proxy/plugin_message_filter.h" | 5 #include "ppapi/proxy/plugin_message_filter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "ipc/ipc_channel.h" | 9 #include "ipc/ipc_channel.h" |
10 #include "ppapi/proxy/ppapi_messages.h" | 10 #include "ppapi/proxy/ppapi_messages.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 return handled; | 47 return handled; |
48 } | 48 } |
49 | 49 |
50 bool PluginMessageFilter::Send(IPC::Message* msg) { | 50 bool PluginMessageFilter::Send(IPC::Message* msg) { |
51 if (sender_) | 51 if (sender_) |
52 return sender_->Send(msg); | 52 return sender_->Send(msg); |
53 delete msg; | 53 delete msg; |
54 return false; | 54 return false; |
55 } | 55 } |
56 | 56 |
| 57 void PluginMessageFilter::AddResourceMessageFilter( |
| 58 const scoped_refptr<ResourceMessageFilter>& filter) { |
| 59 resource_filters_.push_back(filter); |
| 60 } |
| 61 |
57 // static | 62 // static |
58 void PluginMessageFilter::DispatchResourceReplyForTest( | 63 void PluginMessageFilter::DispatchResourceReplyForTest( |
59 const ResourceMessageReplyParams& reply_params, | 64 const ResourceMessageReplyParams& reply_params, |
60 const IPC::Message& nested_msg) { | 65 const IPC::Message& nested_msg) { |
61 DispatchResourceReply(reply_params, nested_msg); | 66 DispatchResourceReply(reply_params, nested_msg); |
62 } | 67 } |
63 | 68 |
64 void PluginMessageFilter::OnMsgReserveInstanceId(PP_Instance instance, | 69 void PluginMessageFilter::OnMsgReserveInstanceId(PP_Instance instance, |
65 bool* usable) { | 70 bool* usable) { |
66 // If |seen_instance_ids_| is set to NULL, we are not supposed to see this | 71 // If |seen_instance_ids_| is set to NULL, we are not supposed to see this |
67 // message. | 72 // message. |
68 CHECK(seen_instance_ids_); | 73 CHECK(seen_instance_ids_); |
69 // See the message definition for how this works. | 74 // See the message definition for how this works. |
70 if (seen_instance_ids_->find(instance) != seen_instance_ids_->end()) { | 75 if (seen_instance_ids_->find(instance) != seen_instance_ids_->end()) { |
71 // Instance ID already seen, reject it. | 76 // Instance ID already seen, reject it. |
72 *usable = false; | 77 *usable = false; |
73 return; | 78 return; |
74 } | 79 } |
75 | 80 |
76 // This instance ID is new so we can return that it's usable and mark it as | 81 // This instance ID is new so we can return that it's usable and mark it as |
77 // used for future reference. | 82 // used for future reference. |
78 seen_instance_ids_->insert(instance); | 83 seen_instance_ids_->insert(instance); |
79 *usable = true; | 84 *usable = true; |
80 } | 85 } |
81 | 86 |
82 void PluginMessageFilter::OnMsgResourceReply( | 87 void PluginMessageFilter::OnMsgResourceReply( |
83 const ResourceMessageReplyParams& reply_params, | 88 const ResourceMessageReplyParams& reply_params, |
84 const IPC::Message& nested_msg) { | 89 const IPC::Message& nested_msg) { |
| 90 for (const auto& filter_ptr : resource_filters_) { |
| 91 if (filter_ptr->OnResourceReplyReceived(reply_params, nested_msg)) |
| 92 return; |
| 93 } |
85 scoped_refptr<base::MessageLoopProxy> target = | 94 scoped_refptr<base::MessageLoopProxy> target = |
86 resource_reply_thread_registrar_->GetTargetThread(reply_params, | 95 resource_reply_thread_registrar_->GetTargetThread(reply_params, |
87 nested_msg); | 96 nested_msg); |
88 | 97 target->PostTask( |
89 if (!target.get()) { | 98 FROM_HERE, base::Bind(&DispatchResourceReply, reply_params, nested_msg)); |
90 DispatchResourceReply(reply_params, nested_msg); | |
91 } else { | |
92 target->PostTask( | |
93 FROM_HERE, | |
94 base::Bind(&DispatchResourceReply, reply_params, nested_msg)); | |
95 } | |
96 } | 99 } |
97 | 100 |
98 // static | 101 // static |
99 void PluginMessageFilter::DispatchResourceReply( | 102 void PluginMessageFilter::DispatchResourceReply( |
100 const ResourceMessageReplyParams& reply_params, | 103 const ResourceMessageReplyParams& reply_params, |
101 const IPC::Message& nested_msg) { | 104 const IPC::Message& nested_msg) { |
102 ProxyAutoLock lock; | 105 ProxyAutoLock lock; |
103 Resource* resource = PpapiGlobals::Get()->GetResourceTracker()->GetResource( | 106 Resource* resource = PpapiGlobals::Get()->GetResourceTracker()->GetResource( |
104 reply_params.pp_resource()); | 107 reply_params.pp_resource()); |
105 if (!resource) { | 108 if (!resource) { |
106 DVLOG_IF(1, reply_params.sequence() != 0) | 109 DVLOG_IF(1, reply_params.sequence() != 0) |
107 << "Pepper resource reply message received but the resource doesn't " | 110 << "Pepper resource reply message received but the resource doesn't " |
108 "exist (probably has been destroyed)."; | 111 "exist (probably has been destroyed)."; |
109 return; | 112 return; |
110 } | 113 } |
111 resource->OnReplyReceived(reply_params, nested_msg); | 114 resource->OnReplyReceived(reply_params, nested_msg); |
112 } | 115 } |
113 | 116 |
114 } // namespace proxy | 117 } // namespace proxy |
115 } // namespace ppapi | 118 } // namespace ppapi |
OLD | NEW |