summaryrefslogtreecommitdiffstats
path: root/ppapi/native_client/src/shared/ppapi_proxy/browser_ppp.h
blob: 20ef9005e99fc86f3dcd1365375f241370b76391 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright (c) 2011 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.

#ifndef NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_BROWSER_PPP_H_
#define NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_BROWSER_PPP_H_

#include <stdarg.h>

#include "native_client/src/include/nacl_macros.h"
#include "native_client/src/include/portability.h"
#include "native_client/src/shared/srpc/nacl_srpc.h"
#include "native_client/src/shared/platform/nacl_check.h"
#include "native_client/src/shared/platform/nacl_threads.h"
#include "native_client/src/trusted/desc/nacl_desc_invalid.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/ppp.h"
#include "ppapi/c/ppp_instance.h"
#include "ppapi/c/ppp_messaging.h"

namespace plugin {
class Plugin;
}

struct PPP_InputEvent;

namespace ppapi_proxy {

class BrowserPpp {
 public:
  BrowserPpp(NaClSrpcChannel* main_channel, plugin::Plugin* plugin)
      : main_channel_(main_channel),
        is_nexe_alive_(true),
        plugin_pid_(0),
        plugin_(plugin),
        ppp_instance_interface_(NULL),
        ppp_messaging_interface_(NULL),
        ppp_input_event_interface_(NULL) {
    CHECK(main_channel_ != NULL);
    upcall_thread_.tid = 0;
  }

  ~BrowserPpp() {}

  int32_t InitializeModule(PP_Module module_id,
                           PPB_GetInterface get_browser_interface);

  // Joins upcall thread, drops references to channel (owned by plugin),
  // calls plugin side shutdown, but not user's PPP_ShutdownModule.
  void ShutdownModule();
  // Returns an interface pointer or NULL.
  const void* GetPluginInterface(const char* interface_name);
  // Returns an interface pointer or fails on a NULL CHECK.
  const void* GetPluginInterfaceSafe(const char* interface_name);

  // Guaranteed to be non-NULL if module initialization succeeded.
  // Use this instead of GetPluginInterface for PPP_INSTANCE_INTERFACE.
  const PPP_Instance* ppp_instance_interface() const {
    return ppp_instance_interface_;
  }

  const PPP_Messaging* ppp_messaging_interface() const {
    return ppp_messaging_interface_;
  }

  const PPP_InputEvent* ppp_input_event_interface() const {
    return ppp_input_event_interface_;
  }

  bool is_valid() const { return is_nexe_alive_; }
  static bool is_valid(BrowserPpp* proxy) {
    return (proxy != NULL && proxy->is_valid());
  }

  NaClSrpcChannel* main_channel() const { return main_channel_; }
  int plugin_pid() const { return plugin_pid_; }
  plugin::Plugin* plugin() { return plugin_; }

  void ReportDeadNexe() { is_nexe_alive_ = false; }

 private:
  // The "main" SRPC channel used to communicate with the plugin.
  // NULL if proxy has been shut down.
  NaClSrpcChannel* main_channel_;
  bool is_nexe_alive_;
  // The PID of the plugin.
  int plugin_pid_;
  // Plugin that owns this proxy.
  plugin::Plugin* plugin_;

  // Set on module initialization.
  const PPP_Instance* ppp_instance_interface_;
  const PPP_Messaging* ppp_messaging_interface_;
  const PPP_InputEvent* ppp_input_event_interface_;

  // The thread used to handle calls on other than the main thread.
  struct NaClThread upcall_thread_;
  NACL_DISALLOW_COPY_AND_ASSIGN(BrowserPpp);
};

}  // namespace ppapi_proxy

#endif  // NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_BROWSER_PPP_H_