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 #include "ppapi/host/resource_host.h" | 5 #include "ppapi/host/resource_host.h" |
6 | 6 |
7 #include "ppapi/c/pp_errors.h" | 7 #include "ppapi/c/pp_errors.h" |
| 8 #include "ppapi/host/ppapi_host.h" |
| 9 #include "ppapi/host/resource_message_filter.h" |
8 | 10 |
9 namespace ppapi { | 11 namespace ppapi { |
10 namespace host { | 12 namespace host { |
11 | 13 |
12 ResourceHost::ResourceHost(PpapiHost* host, | 14 ResourceHost::ResourceHost(PpapiHost* host, |
13 PP_Instance instance, | 15 PP_Instance instance, |
14 PP_Resource resource) | 16 PP_Resource resource) |
15 : host_(host), | 17 : host_(host), |
16 pp_instance_(instance), | 18 pp_instance_(instance), |
17 pp_resource_(resource) { | 19 pp_resource_(resource) { |
18 } | 20 } |
19 | 21 |
20 ResourceHost::~ResourceHost() { | 22 ResourceHost::~ResourceHost() { |
| 23 for (size_t i = 0; i < message_filters_.size(); ++i) |
| 24 message_filters_[i]->OnFilterDestroyed(); |
21 } | 25 } |
22 | 26 |
23 int32_t ResourceHost::OnResourceMessageReceived(const IPC::Message& msg, | 27 bool ResourceHost::HandleMessage(const IPC::Message& msg, |
24 HostMessageContext* context) { | 28 HostMessageContext* context) { |
25 return PP_ERROR_NOTSUPPORTED; | 29 // First see if the message is handled off-thread by message filters. |
| 30 for (size_t i = 0; i < message_filters_.size(); ++i) { |
| 31 if (message_filters_[i]->HandleMessage(msg, context)) |
| 32 return true; |
| 33 } |
| 34 // Run this ResourceHosts message handler. |
| 35 RunMessageHandlerAndReply(msg, context); |
| 36 return true; |
| 37 } |
| 38 |
| 39 void ResourceHost::SendReply(const ReplyMessageContext& context, |
| 40 const IPC::Message& msg) { |
| 41 host_->SendReply(context, msg); |
| 42 } |
| 43 |
| 44 void ResourceHost::AddFilter(scoped_refptr<ResourceMessageFilter> filter) { |
| 45 message_filters_.push_back(filter); |
| 46 filter->OnFilterAdded(this); |
26 } | 47 } |
27 | 48 |
28 } // namespace host | 49 } // namespace host |
29 } // namespace ppapi | 50 } // namespace ppapi |
OLD | NEW |