Home | History | Annotate | Download | only in proxy
      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
      3 // found in the LICENSE file.
      4 
      5 #include "ppapi/proxy/plugin_message_filter.h"
      6 
      7 #include "ppapi/proxy/ppapi_messages.h"
      8 
      9 namespace ppapi {
     10 namespace proxy {
     11 
     12 PluginMessageFilter::PluginMessageFilter(
     13     std::set<PP_Instance>* seen_instance_ids)
     14     : seen_instance_ids_(seen_instance_ids),
     15       channel_(NULL) {
     16 }
     17 
     18 PluginMessageFilter::~PluginMessageFilter() {
     19 }
     20 
     21 void PluginMessageFilter::OnFilterAdded(IPC::Channel* channel) {
     22   channel_ = channel;
     23 }
     24 
     25 void PluginMessageFilter::OnFilterRemoved() {
     26   channel_ = NULL;
     27 }
     28 
     29 bool PluginMessageFilter::OnMessageReceived(const IPC::Message& message) {
     30   bool handled = true;
     31   IPC_BEGIN_MESSAGE_MAP(PluginMessageFilter, message)
     32     IPC_MESSAGE_HANDLER(PpapiMsg_ReserveInstanceId, OnMsgReserveInstanceId)
     33     IPC_MESSAGE_UNHANDLED(handled = false)
     34   IPC_END_MESSAGE_MAP()
     35   return handled;
     36 }
     37 
     38 bool PluginMessageFilter::Send(IPC::Message* msg) {
     39   if (channel_)
     40     return channel_->Send(msg);
     41   delete msg;
     42   return false;
     43 }
     44 
     45 void PluginMessageFilter::OnMsgReserveInstanceId(PP_Instance instance,
     46                                                  bool* usable) {
     47   // See the message definition for how this works.
     48   if (seen_instance_ids_->find(instance) != seen_instance_ids_->end()) {
     49     // Instance ID already seen, reject it.
     50     *usable = false;
     51     return;
     52   }
     53 
     54   // This instance ID is new so we can return that it's usable and mark it as
     55   // used for future reference.
     56   seen_instance_ids_->insert(instance);
     57   *usable = true;
     58 }
     59 
     60 }  // namespace proxy
     61 }  // namespace ppapi
     62