summaryrefslogtreecommitdiffstats
path: root/o3d/gpu/gpu_plugin/gpu_plugin.cc
blob: d8cfb58988422d90d7fbfa2a087d109330b99036 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright (c) 2006-2008 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 "gpu/gpu_plugin/gpu_plugin.h"
#include "gpu/gpu_plugin/gpu_plugin_object_factory.h"
#include "gpu/np_utils/np_browser.h"
#include "gpu/np_utils/np_plugin_object.h"
#include "gpu/np_utils/np_plugin_object_factory.h"

#if defined(O3D_IN_CHROME)
#include "webkit/glue/plugins/nphostapi.h"
#else
#include "o3d/third_party/npapi/include/npfunctions.h"
#endif

namespace gpu_plugin {

// Definitions of NPAPI plugin entry points.

namespace {
NPBrowser* g_browser;
GPUPluginObjectFactory g_plugin_object_factory;

NPError NPP_New(NPMIMEType plugin_type, NPP instance,
                uint16 mode, int16 argc, char* argn[],
                char* argv[], NPSavedData* saved) {
  if (!instance)
    return NPERR_INVALID_INSTANCE_ERROR;

  PluginObject* plugin_object =
      NPPluginObjectFactory::get()->CreatePluginObject(instance, plugin_type);
  if (!plugin_object)
    return NPERR_GENERIC_ERROR;

  instance->pdata = plugin_object;

  NPError error = plugin_object->New(plugin_type, argc, argn, argv, saved);
  if (error != NPERR_NO_ERROR) {
    plugin_object->Release();
  }

  return error;
}

NPError NPP_Destroy(NPP instance, NPSavedData** saved) {
  if (!instance)
    return NPERR_INVALID_INSTANCE_ERROR;

  PluginObject* plugin_object = static_cast<PluginObject*>(instance->pdata);
  NPError error = plugin_object->Destroy(saved);

  if (error == NPERR_NO_ERROR) {
    plugin_object->Release();
  }

  return error;
}

NPError NPP_SetWindow(NPP instance, NPWindow* window) {
  if (!instance)
    return NPERR_INVALID_INSTANCE_ERROR;

  PluginObject* plugin_object = static_cast<PluginObject*>(instance->pdata);
  return plugin_object->SetWindow(window);
}

int16 NPP_HandleEvent(NPP instance, void* event) {
  if (!instance)
    return 0;

  PluginObject* plugin_object = static_cast<PluginObject*>(instance->pdata);
  return plugin_object->HandleEvent(static_cast<NPEvent*>(event));
}

NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) {
  if (!instance)
    return NPERR_INVALID_INSTANCE_ERROR;

  PluginObject* plugin_object = static_cast<PluginObject*>(instance->pdata);
  switch (variable) {
    case NPPVpluginScriptableNPObject:
      *reinterpret_cast<NPObject**>(value) =
          plugin_object->GetScriptableNPObject();
      return NPERR_NO_ERROR;
    default:
      return NPERR_GENERIC_ERROR;
  }
}

NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) {
  return NPERR_NO_ERROR;
}
}

NPError NP_GetEntryPoints(NPPluginFuncs* funcs) {
  funcs->newp = NPP_New;
  funcs->destroy = NPP_Destroy;
  funcs->setwindow = NPP_SetWindow;
  funcs->event = NPP_HandleEvent;
  funcs->getvalue = NPP_GetValue;
  funcs->setvalue = NPP_SetValue;
  return NPERR_NO_ERROR;
}

#if defined(OS_LINUX)
NPError API_CALL NP_Initialize(NPNetscapeFuncs *browser_funcs,
                               NPPluginFuncs* plugin_funcs) {
#else
NPError NP_Initialize(NPNetscapeFuncs *browser_funcs) {
#endif
  if (!browser_funcs)
    return NPERR_INVALID_FUNCTABLE_ERROR;

  if (g_browser)
    return NPERR_GENERIC_ERROR;

#if defined(OS_LINUX)
  NP_GetEntryPoints(plugin_funcs);
#endif

  g_browser = new NPBrowser(browser_funcs);

  return NPERR_NO_ERROR;
}

NPError NP_Shutdown() {
  if (!g_browser)
    return NPERR_GENERIC_ERROR;

  delete g_browser;
  g_browser = NULL;

  return NPERR_NO_ERROR;
}
}  // namespace gpu_plugin