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_PROXY_MESSAGE_HANDLER_H_
6 #define PPAPI_PROXY_MESSAGE_HANDLER_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ppapi/c/dev/ppb_messaging_deprecated.h"
11 #include "ppapi/c/pp_resource.h"
12 #include "ppapi/c/ppp_message_handler.h"
13 #include "ppapi/proxy/ppapi_proxy_export.h"
25 class MessageLoopResource
;
27 // MessageHandler wraps a PPP_MessageHandler to encapsulate calling methods
28 // on the right thread and calling the Destroy function when this
29 // MessageHandler is destroyed.
30 class PPAPI_PROXY_EXPORT MessageHandler
{
32 // Create a MessageHandler. If any parameters are invalid, it will return a
33 // null scoped_ptr and set |*error| appropriately.
34 // |handler_if| is the struct of function pointers we will invoke. All of
35 // the function pointers within must be valid, or we fail
36 // with PP_ERROR_BADARGUMENT.
37 // |user_data| is a pointer provided by the plugin that we pass back when we
38 // call functions in |handler_if|.
39 // |message_loop| is the message loop where we will invoke functions in
40 // |handler_if|. Must not be the main thread message loop,
41 // to try to force the plugin to not over-subscribe the main
42 // thread. If it's the main thread loop, |error| will be set
43 // to PP_ERROR_WRONGTHREAD.
44 // |error| is an out-param that will be set on failure.
45 static scoped_ptr
<MessageHandler
> Create(
47 const PPP_MessageHandler_0_2
* handler_if
,
49 PP_Resource message_loop
,
51 // Provide temporary backwards compatibility. TODO(dmichael): Remove all
52 // references to PPB_Messaging_1_1 and PPP_MessageHandler_0_1.
54 static scoped_ptr
<MessageHandler
> CreateDeprecated(
56 const PPP_MessageHandler_0_1_Deprecated
* handler_if
,
58 PP_Resource message_loop
,
62 bool LoopIsValid() const;
64 void HandleMessage(ScopedPPVar var
);
65 void HandleBlockingMessage(ScopedPPVar var
,
66 scoped_ptr
<IPC::Message
> reply_msg
);
69 MessageHandler(PP_Instance instance
,
70 const PPP_MessageHandler_0_2
* handler_if
,
72 scoped_refptr
<MessageLoopResource
> message_loop
);
73 MessageHandler(PP_Instance instance
,
74 const PPP_MessageHandler_0_1_Deprecated
* handler_if
,
76 scoped_refptr
<MessageLoopResource
> message_loop
);
79 PP_Instance instance_
;
80 const PPP_MessageHandler_0_2
* handler_if_
;
81 const PPP_MessageHandler_0_1_Deprecated
* handler_if_0_1_
;
83 scoped_refptr
<MessageLoopResource
> message_loop_
;
85 DISALLOW_COPY_AND_ASSIGN(MessageHandler
);
91 #endif // PPAPI_PROXY_MESSAGE_HANDLER_H_