summaryrefslogtreecommitdiffstats
path: root/ppapi/host/resource_message_handler.cc
blob: 603d5e2538267b6e6a8b3e6599ace97cdc596626 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ppapi/host/resource_message_handler.h"

#include "base/logging.h"
#include "ipc/ipc_message.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/host/host_message_context.h"

namespace ppapi {
namespace host {

ResourceMessageHandler::ResourceMessageHandler() {
}

ResourceMessageHandler::~ResourceMessageHandler() {
}

void ResourceMessageHandler::RunMessageHandlerAndReply(
    const IPC::Message& msg,
    HostMessageContext* context) {
  ReplyMessageContext reply_context = context->MakeReplyMessageContext();
  // CAUTION: Handling the message may cause the destruction of this object.
  // The message handler should ensure that if there is a chance that the
  // object will be destroyed, PP_OK_COMPLETIONPENDING is returned as the
  // result of the message handler. Otherwise the code below will attempt to
  // send a reply message on a destroyed object.
  reply_context.params.set_result(OnResourceMessageReceived(msg, context));

  // Sanity check the resource handler. Note if the result was
  // "completion pending" the resource host may have already sent the reply.
  if (reply_context.params.result() == PP_OK_COMPLETIONPENDING) {
    // Message handler should have only returned a pending result if a
    // response will be sent to the plugin.
    DCHECK(context->params.has_callback());

    // Message handler should not have written a message to be returned if
    // completion is pending.
    DCHECK(context->reply_msg.type() == 0);
  } else if (!context->params.has_callback()) {
    // When no response is required, the message handler should not have
    // written a message to be returned.
    DCHECK(context->reply_msg.type() == 0);

    // If there is no callback and the result of running the message handler
    // was not PP_OK the client won't find out.
    DLOG_IF(WARNING, reply_context.params.result() != PP_OK)
        << "'Post' message handler failed to complete successfully.";
  }

  if (context->params.has_callback() &&
      reply_context.params.result() != PP_OK_COMPLETIONPENDING)
    SendReply(reply_context, context->reply_msg);
}

int32_t ResourceMessageHandler::OnResourceMessageReceived(
    const IPC::Message& msg,
    HostMessageContext* context) {
  return PP_ERROR_NOTSUPPORTED;
}

}  // namespace host
}  // namespace ppapi