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/ppapi_host.h" | 5 #include "ppapi/host/ppapi_host.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
9 #include "ppapi/host/host_factory.h" | 9 #include "ppapi/host/host_factory.h" |
10 #include "ppapi/host/host_message_context.h" | 10 #include "ppapi/host/host_message_context.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // Stash the |reply_msg| in the context so that it can be used to reply | 111 // Stash the |reply_msg| in the context so that it can be used to reply |
112 // to the sync message. | 112 // to the sync message. |
113 HostMessageContext context(params, reply_msg); | 113 HostMessageContext context(params, reply_msg); |
114 HandleResourceCall(params, nested_msg, &context); | 114 HandleResourceCall(params, nested_msg, &context); |
115 } | 115 } |
116 | 116 |
117 void PpapiHost::HandleResourceCall( | 117 void PpapiHost::HandleResourceCall( |
118 const proxy::ResourceMessageCallParams& params, | 118 const proxy::ResourceMessageCallParams& params, |
119 const IPC::Message& nested_msg, | 119 const IPC::Message& nested_msg, |
120 HostMessageContext* context) { | 120 HostMessageContext* context) { |
121 ReplyMessageContext reply_context = context->MakeReplyMessageContext(); | |
122 | |
123 ResourceHost* resource_host = GetResourceHost(params.pp_resource()); | 121 ResourceHost* resource_host = GetResourceHost(params.pp_resource()); |
124 if (resource_host) { | 122 if (resource_host) { |
125 reply_context.params.set_result( | 123 resource_host->HandleMessage(nested_msg, context); |
126 resource_host->OnResourceMessageReceived(nested_msg, context)); | 124 } else { |
127 | 125 if (context->params.has_callback()) { |
128 // Sanity check the resource handler. Note if the result was | 126 ReplyMessageContext reply_context = context->MakeReplyMessageContext(); |
129 // "completion pending" the resource host may have already sent the reply. | 127 reply_context.params.set_result(PP_ERROR_BADRESOURCE); |
130 if (reply_context.params.result() == PP_OK_COMPLETIONPENDING) { | 128 SendReply(reply_context, context->reply_msg); |
131 // Message handler should have only returned a pending result if a | |
132 // response will be sent to the plugin. | |
133 DCHECK(params.has_callback()); | |
134 | |
135 // Message handler should not have written a message to be returned if | |
136 // completion is pending. | |
137 DCHECK(context->reply_msg.type() == 0); | |
138 } else if (!params.has_callback()) { | |
139 // When no response is required, the message handler should not have | |
140 // written a message to be returned. | |
141 DCHECK(context->reply_msg.type() == 0); | |
142 | |
143 // If there is no callback and the result of running the message handler | |
144 // was not PP_OK the client won't find out. | |
145 DLOG_IF(WARNING, reply_context.params.result() != PP_OK) | |
146 << "'Post' message handler failed to complete successfully."; | |
147 } | 129 } |
148 } else { | |
149 reply_context.params.set_result(PP_ERROR_BADRESOURCE); | |
150 } | 130 } |
151 | |
152 if (params.has_callback() && | |
153 reply_context.params.result() != PP_OK_COMPLETIONPENDING) | |
154 SendReply(reply_context, context->reply_msg); | |
155 } | 131 } |
156 | 132 |
157 void PpapiHost::OnHostMsgResourceCreated( | 133 void PpapiHost::OnHostMsgResourceCreated( |
158 const proxy::ResourceMessageCallParams& params, | 134 const proxy::ResourceMessageCallParams& params, |
159 PP_Instance instance, | 135 PP_Instance instance, |
160 const IPC::Message& nested_msg) { | 136 const IPC::Message& nested_msg) { |
161 if (resources_.size() >= kMaxResourcesPerPlugin) | 137 if (resources_.size() >= kMaxResourcesPerPlugin) |
162 return; | 138 return; |
163 | 139 |
164 // Run through all filters until one grabs this message. | 140 // Run through all filters until one grabs this message. |
(...skipping 23 matching lines...) Expand all Loading... |
188 resources_.erase(found); | 164 resources_.erase(found); |
189 } | 165 } |
190 | 166 |
191 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) { | 167 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) { |
192 ResourceMap::iterator found = resources_.find(resource); | 168 ResourceMap::iterator found = resources_.find(resource); |
193 return found == resources_.end() ? NULL : found->second.get(); | 169 return found == resources_.end() ? NULL : found->second.get(); |
194 } | 170 } |
195 | 171 |
196 } // namespace host | 172 } // namespace host |
197 } // namespace ppapi | 173 } // namespace ppapi |
OLD | NEW |