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 3// found in the LICENSE file. 4 5#include "ppapi/host/resource_host.h" 6 7#include "base/logging.h" 8#include "ppapi/c/pp_errors.h" 9#include "ppapi/host/ppapi_host.h" 10#include "ppapi/host/resource_message_filter.h" 11 12namespace ppapi { 13namespace host { 14 15ResourceHost::ResourceHost(PpapiHost* host, 16 PP_Instance instance, 17 PP_Resource resource) 18 : host_(host), 19 pp_instance_(instance), 20 pp_resource_(resource) { 21} 22 23ResourceHost::~ResourceHost() { 24 for (size_t i = 0; i < message_filters_.size(); ++i) 25 message_filters_[i]->OnFilterDestroyed(); 26} 27 28bool ResourceHost::HandleMessage(const IPC::Message& msg, 29 HostMessageContext* context) { 30 // First see if the message is handled off-thread by message filters. 31 for (size_t i = 0; i < message_filters_.size(); ++i) { 32 if (message_filters_[i]->HandleMessage(msg, context)) 33 return true; 34 } 35 // Run this ResourceHosts message handler. 36 RunMessageHandlerAndReply(msg, context); 37 return true; 38} 39 40void ResourceHost::SetPPResourceForPendingHost(PP_Resource pp_resource) { 41 DCHECK(!pp_resource_); 42 pp_resource_ = pp_resource; 43 DidConnectPendingHostToResource(); 44} 45 46void ResourceHost::SendReply(const ReplyMessageContext& context, 47 const IPC::Message& msg) { 48 host_->SendReply(context, msg); 49} 50 51bool ResourceHost::IsFileRefHost() { 52 return false; 53} 54 55bool ResourceHost::IsFileSystemHost() { 56 return false; 57} 58 59bool ResourceHost::IsGraphics2DHost() { 60 return false; 61} 62 63void ResourceHost::AddFilter(scoped_refptr<ResourceMessageFilter> filter) { 64 message_filters_.push_back(filter); 65 filter->OnFilterAdded(this); 66} 67 68} // namespace host 69} // namespace ppapi 70