OLD | NEW |
| (Empty) |
1 // Copyright (c) 2009 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. | |
4 | |
5 #if defined(OS_WIN) | |
6 #include <windows.h> | |
7 #endif | |
8 | |
9 #include "build/build_config.h" | |
10 #include "gpu/gpu_plugin/gpu_plugin.h" | |
11 #include "third_party/npapi/bindings/nphostapi.h" | |
12 | |
13 namespace gpu_plugin { | |
14 | |
15 // Definitions of NPAPI plugin entry points. | |
16 | |
17 namespace { | |
18 | |
19 // TODO(apatrick): move this to platform specific source files. | |
20 #if defined(OS_WIN) | |
21 class PluginObject { | |
22 public: | |
23 PluginObject(); | |
24 ~PluginObject(); | |
25 | |
26 void SetWindow(HWND hwnd); | |
27 | |
28 private: | |
29 HWND hwnd_; | |
30 | |
31 DISALLOW_COPY_AND_ASSIGN(PluginObject); | |
32 }; | |
33 | |
34 const wchar_t* const kPluginObject = L"GPUPluginObject"; | |
35 | |
36 PluginObject::PluginObject() : hwnd_(NULL) { | |
37 } | |
38 | |
39 PluginObject::~PluginObject() { | |
40 } | |
41 | |
42 void PluginObject::SetWindow(HWND hwnd) { | |
43 hwnd_ = hwnd; | |
44 if (hwnd_) { | |
45 // TODO: convert this to using app::win::ScopedProp. | |
46 // Store plugin object in window property. | |
47 SetProp(hwnd_, kPluginObject, reinterpret_cast<HANDLE>(this)); | |
48 | |
49 // Disable plugin window so mouse messages are passed to the parent window. | |
50 EnableWindow(hwnd_, false); | |
51 } else { | |
52 // Clean up properties. | |
53 RemoveProp(hwnd_, kPluginObject); | |
54 } | |
55 } | |
56 | |
57 #endif // defined(OS_WIN) | |
58 | |
59 NPError NPP_New(NPMIMEType plugin_type, NPP instance, | |
60 uint16 mode, int16 argc, char* argn[], | |
61 char* argv[], NPSavedData* saved) { | |
62 if (!instance) | |
63 return NPERR_INVALID_INSTANCE_ERROR; | |
64 | |
65 #if defined(OS_WIN) | |
66 instance->pdata = new PluginObject; | |
67 #endif | |
68 | |
69 return NPERR_NO_ERROR; | |
70 } | |
71 | |
72 NPError NPP_Destroy(NPP instance, NPSavedData** saved) { | |
73 if (!instance) | |
74 return NPERR_INVALID_INSTANCE_ERROR; | |
75 | |
76 #if defined(OS_WIN) | |
77 delete static_cast<PluginObject*>(instance->pdata); | |
78 #endif | |
79 | |
80 return NPERR_NO_ERROR; | |
81 } | |
82 | |
83 NPError NPP_SetWindow(NPP instance, NPWindow* window) { | |
84 #if defined(OS_WIN) | |
85 PluginObject* plugin_object = static_cast<PluginObject*>(instance->pdata); | |
86 plugin_object->SetWindow(reinterpret_cast<HWND>(window->window)); | |
87 #endif | |
88 | |
89 return NPERR_NO_ERROR; | |
90 } | |
91 | |
92 int16 NPP_HandleEvent(NPP instance, void* event) { | |
93 return 0; | |
94 } | |
95 | |
96 NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) { | |
97 if (!instance) | |
98 return NPERR_INVALID_INSTANCE_ERROR; | |
99 switch (variable) { | |
100 case NPPVpluginNeedsXEmbed: | |
101 *static_cast<NPBool *>(value) = 1; | |
102 return NPERR_NO_ERROR; | |
103 default: | |
104 return NPERR_INVALID_PARAM; | |
105 } | |
106 } | |
107 | |
108 NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) { | |
109 return NPERR_NO_ERROR; | |
110 } | |
111 | |
112 } // namespace | |
113 | |
114 NPError API_CALL NP_GetEntryPoints(NPPluginFuncs* funcs) { | |
115 funcs->newp = NPP_New; | |
116 funcs->destroy = NPP_Destroy; | |
117 funcs->setwindow = NPP_SetWindow; | |
118 funcs->event = NPP_HandleEvent; | |
119 funcs->getvalue = NPP_GetValue; | |
120 funcs->setvalue = NPP_SetValue; | |
121 return NPERR_NO_ERROR; | |
122 } | |
123 | |
124 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
125 NPError API_CALL NP_Initialize(NPNetscapeFuncs *browser_funcs, | |
126 NPPluginFuncs* plugin_funcs) { | |
127 #else | |
128 NPError API_CALL NP_Initialize(NPNetscapeFuncs *browser_funcs) { | |
129 #endif | |
130 if (!browser_funcs) | |
131 return NPERR_INVALID_FUNCTABLE_ERROR; | |
132 | |
133 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
134 NP_GetEntryPoints(plugin_funcs); | |
135 #endif | |
136 | |
137 return NPERR_NO_ERROR; | |
138 } | |
139 | |
140 NPError API_CALL NP_Shutdown() { | |
141 return NPERR_NO_ERROR; | |
142 } | |
143 | |
144 } // namespace gpu_plugin | |
OLD | NEW |