1 // Copyright 2014 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.
5 #ifndef PPAPI_CPP_MESSAGE_HANDLER_H_
6 #define PPAPI_CPP_MESSAGE_HANDLER_H_
10 /// <code>MessageHandler</code> is an abstract base class that the plugin may
11 /// implement if it wants to receive messages from JavaScript on a background
12 /// thread when JavaScript invokes postMessage() or
13 /// postMessageAndAwaitResponse(). See pp::Instance::RegisterMessageHandler()
15 class MessageHandler
{
17 virtual ~MessageHandler() {};
19 /// Invoked as a result of JavaScript invoking postMessage() on the plugin's
22 /// @param[in] instance An <code>InstanceHandle</code> identifying one
23 /// instance of a module.
24 /// @param[in] message_data A copy of the parameter that JavaScript provided
26 virtual void HandleMessage(pp::InstanceHandle instance
,
27 const Var
& message_data
) = 0;
29 /// Invoked as a result of JavaScript invoking postMessageAndAwaitResponse()
30 /// on the plugin's DOM element.
32 /// NOTE: JavaScript execution is blocked during the duration of this call.
33 /// Hence, the plugin should respond as quickly as possible. For this reason,
34 /// blocking completion callbacks are disallowed while handling a blocking
37 /// @param[in] instance An <code>InstanceHandle</code> identifying one
38 /// instance of a module.
39 /// @param[in] message_data A copy of the parameter that JavaScript provided
41 /// @return Returns a pp::Var that is then copied to a JavaScript object
42 /// which is returned as the result of JavaScript's call of
43 /// postMessageAndAwaitResponse().
44 virtual pp::Var
HandleBlockingMessage(pp::InstanceHandle instance
,
45 const Var
& message_data
) = 0;
47 /// Invoked when this MessageHandler is no longer needed. After this, no more
48 /// calls will be made to this object.
50 /// @param[in] instance An <code>InstanceHandle</code> identifying one
51 /// instance of a module.
52 virtual void WasUnregistered(pp::InstanceHandle instance
) = 0;
57 #endif // PPAPI_CPP_MESSAGE_HANDLER_H_