OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #if defined(OS_WIN) |
| 6 #include <windows.h> |
| 7 #endif |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "build/build_config.h" |
5 #include "gpu/gpu_plugin/gpu_plugin.h" | 11 #include "gpu/gpu_plugin/gpu_plugin.h" |
6 #include "webkit/glue/plugins/nphostapi.h" | 12 #include "webkit/glue/plugins/nphostapi.h" |
7 | 13 |
8 namespace gpu_plugin { | 14 namespace gpu_plugin { |
9 | 15 |
10 // Definitions of NPAPI plugin entry points. | 16 // Definitions of NPAPI plugin entry points. |
11 | 17 |
12 namespace { | 18 namespace { |
13 | 19 |
| 20 // TODO(apatrick): move this to platform specific source files. |
| 21 #if defined(OS_WIN) |
| 22 class PluginObject { |
| 23 public: |
| 24 PluginObject(); |
| 25 ~PluginObject(); |
| 26 |
| 27 void SetWindow(HWND hwnd); |
| 28 |
| 29 private: |
| 30 HWND hwnd_; |
| 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 // Store plugin object in window property. |
| 46 SetProp(hwnd_, kPluginObject, reinterpret_cast<HANDLE>(this)); |
| 47 |
| 48 // Disable plugin window so mouse messages are passed to the parent window. |
| 49 EnableWindow(hwnd_, false); |
| 50 } else { |
| 51 // Clean up properties. |
| 52 RemoveProp(hwnd_, kPluginObject); |
| 53 } |
| 54 } |
| 55 |
| 56 #endif // defined(OS_WIN) |
| 57 |
14 NPError NPP_New(NPMIMEType plugin_type, NPP instance, | 58 NPError NPP_New(NPMIMEType plugin_type, NPP instance, |
15 uint16 mode, int16 argc, char* argn[], | 59 uint16 mode, int16 argc, char* argn[], |
16 char* argv[], NPSavedData* saved) { | 60 char* argv[], NPSavedData* saved) { |
17 if (!instance) | 61 if (!instance) |
18 return NPERR_INVALID_INSTANCE_ERROR; | 62 return NPERR_INVALID_INSTANCE_ERROR; |
19 | 63 |
| 64 #if defined(OS_WIN) |
| 65 instance->pdata = new PluginObject; |
| 66 #endif |
| 67 |
20 return NPERR_NO_ERROR; | 68 return NPERR_NO_ERROR; |
21 } | 69 } |
22 | 70 |
23 NPError NPP_Destroy(NPP instance, NPSavedData** saved) { | 71 NPError NPP_Destroy(NPP instance, NPSavedData** saved) { |
24 if (!instance) | 72 if (!instance) |
25 return NPERR_INVALID_INSTANCE_ERROR; | 73 return NPERR_INVALID_INSTANCE_ERROR; |
26 | 74 |
| 75 #if defined(OS_WIN) |
| 76 delete static_cast<PluginObject*>(instance->pdata); |
| 77 #endif |
| 78 |
27 return NPERR_NO_ERROR; | 79 return NPERR_NO_ERROR; |
28 } | 80 } |
29 | 81 |
30 NPError NPP_SetWindow(NPP instance, NPWindow* window) { | 82 NPError NPP_SetWindow(NPP instance, NPWindow* window) { |
| 83 #if defined(OS_WIN) |
| 84 PluginObject* plugin_object = static_cast<PluginObject*>(instance->pdata); |
| 85 plugin_object->SetWindow(reinterpret_cast<HWND>(window->window)); |
| 86 #endif |
| 87 |
31 return NPERR_NO_ERROR; | 88 return NPERR_NO_ERROR; |
32 } | 89 } |
33 | 90 |
34 int16 NPP_HandleEvent(NPP instance, void* event) { | 91 int16 NPP_HandleEvent(NPP instance, void* event) { |
35 return 0; | 92 return 0; |
36 } | 93 } |
37 | 94 |
38 NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) { | 95 NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) { |
39 if (!instance) | 96 if (!instance) |
40 return NPERR_INVALID_INSTANCE_ERROR; | 97 return NPERR_INVALID_INSTANCE_ERROR; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 #endif | 134 #endif |
78 | 135 |
79 return NPERR_NO_ERROR; | 136 return NPERR_NO_ERROR; |
80 } | 137 } |
81 | 138 |
82 NPError API_CALL NP_Shutdown() { | 139 NPError API_CALL NP_Shutdown() { |
83 return NPERR_NO_ERROR; | 140 return NPERR_NO_ERROR; |
84 } | 141 } |
85 | 142 |
86 } // namespace gpu_plugin | 143 } // namespace gpu_plugin |
OLD | NEW |