| OLD | NEW |
| 1 // Copyright (c) 2006-2008 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 // Pepper API support should be turned on for this module. | 5 // Pepper API support should be turned on for this module. |
| 6 #define PEPPER_APIS_ENABLED | 6 #define PEPPER_APIS_ENABLED |
| 7 | 7 |
| 8 #include "webkit/glue/plugins/plugin_host.h" | 8 #include "webkit/glue/plugins/plugin_host.h" |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "base/string_piece.h" | 13 #include "base/string_piece.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/sys_string_conversions.h" | 15 #include "base/sys_string_conversions.h" |
| 16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
| 17 #include "third_party/WebKit/WebKit/chromium/public/WebBindings.h" | 17 #include "third_party/WebKit/WebKit/chromium/public/WebBindings.h" |
| 18 #include "webkit/default_plugin/default_plugin_shared.h" | 18 #include "webkit/default_plugin/default_plugin_shared.h" |
| 19 #include "webkit/glue/glue_util.h" | 19 #include "webkit/glue/glue_util.h" |
| 20 #include "webkit/glue/webplugininfo.h" | 20 #include "webkit/glue/webplugininfo.h" |
| 21 #include "webkit/glue/webplugin_delegate.h" | 21 #include "webkit/glue/webplugin_delegate.h" |
| 22 #include "webkit/glue/webkit_glue.h" | 22 #include "webkit/glue/webkit_glue.h" |
| 23 #include "webkit/glue/pepper/pepper.h" | |
| 24 #include "webkit/glue/plugins/plugin_instance.h" | 23 #include "webkit/glue/plugins/plugin_instance.h" |
| 25 #include "webkit/glue/plugins/plugin_lib.h" | 24 #include "webkit/glue/plugins/plugin_lib.h" |
| 26 #include "webkit/glue/plugins/plugin_list.h" | 25 #include "webkit/glue/plugins/plugin_list.h" |
| 27 #include "webkit/glue/plugins/plugin_stream_url.h" | 26 #include "webkit/glue/plugins/plugin_stream_url.h" |
| 27 #include "third_party/npapi/bindings/npapi_extensions.h" |
| 28 #include "third_party/npapi/bindings/npruntime.h" | 28 #include "third_party/npapi/bindings/npruntime.h" |
| 29 | 29 |
| 30 using WebKit::WebBindings; | 30 using WebKit::WebBindings; |
| 31 | 31 |
| 32 namespace NPAPI | 32 namespace NPAPI |
| 33 { | 33 { |
| 34 scoped_refptr<PluginHost> PluginHost::singleton_; | 34 scoped_refptr<PluginHost> PluginHost::singleton_; |
| 35 | 35 |
| 36 PluginHost::PluginHost() { | 36 PluginHost::PluginHost() { |
| 37 InitializeHostFuncs(); | 37 InitializeHostFuncs(); |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 // plugin is responsible fro saving the current HDC settings, setting up | 659 // plugin is responsible fro saving the current HDC settings, setting up |
| 660 // its own environment, drawing, and restoring the HDC to the previous | 660 // its own environment, drawing, and restoring the HDC to the previous |
| 661 // settings. The HDC settings must be restored whenever control returns | 661 // settings. The HDC settings must be restored whenever control returns |
| 662 // back to the browser, either before returning from NPP_HandleEvent or | 662 // back to the browser, either before returning from NPP_HandleEvent or |
| 663 // before calling a drawing-related netscape method. | 663 // before calling a drawing-related netscape method. |
| 664 | 664 |
| 665 NOTIMPLEMENTED(); | 665 NOTIMPLEMENTED(); |
| 666 } | 666 } |
| 667 | 667 |
| 668 #if defined(PEPPER_APIS_ENABLED) | 668 #if defined(PEPPER_APIS_ENABLED) |
| 669 static NPError InitializeRenderContext(NPP id, | 669 // Pepper 2D device API -------------------------------------------------------- |
| 670 NPRenderType type, | 670 |
| 671 NPRenderContext* context) { | 671 static NPError Device2DQueryCapability(NPP id, int32 capability, int32* value) { |
| 672 scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); | 672 scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); |
| 673 if (plugin) { | 673 if (plugin) { |
| 674 webkit_glue::WebPluginDelegate* delegate = plugin->webplugin()->delegate(); | 674 plugin->webplugin()->delegate()->Device2DQueryCapability(capability, value); |
| 675 // Set up the renderer for the specified type. | 675 return NPERR_NO_ERROR; |
| 676 return delegate->InitializeRenderContext(type, context); | 676 } else { |
| 677 return NPERR_GENERIC_ERROR; |
| 678 } |
| 679 } |
| 680 |
| 681 static NPError Device2DQueryConfig(NPP id, |
| 682 const NPDeviceConfig* request, |
| 683 NPDeviceConfig* obtain) { |
| 684 scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); |
| 685 if (plugin) { |
| 686 return plugin->webplugin()->delegate()->Device2DQueryConfig( |
| 687 static_cast<const NPDeviceContext2DConfig*>(request), |
| 688 static_cast<NPDeviceContext2DConfig*>(obtain)); |
| 677 } | 689 } |
| 678 return NPERR_GENERIC_ERROR; | 690 return NPERR_GENERIC_ERROR; |
| 679 } | 691 } |
| 680 | 692 |
| 681 static NPError FlushRenderContext(NPP id, | 693 static NPError Device2DInitializeContext(NPP id, |
| 682 NPRenderContext* context, | 694 const NPDeviceConfig* config, |
| 683 NPFlushRenderContextCallbackPtr callback, | 695 NPDeviceContext* context) { |
| 684 void* user_data) { | |
| 685 scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); | 696 scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); |
| 686 if (plugin) { | 697 if (plugin) { |
| 687 webkit_glue::WebPluginDelegate* delegate = plugin->webplugin()->delegate(); | 698 return plugin->webplugin()->delegate()->Device2DInitializeContext( |
| 688 // Do the flush. | 699 static_cast<const NPDeviceContext2DConfig*>(config), |
| 689 NPError err = delegate->FlushRenderContext(context); | 700 static_cast<NPDeviceContext2D*>(context)); |
| 701 } |
| 702 return NPERR_GENERIC_ERROR; |
| 703 } |
| 704 |
| 705 static NPError Device2DSetStateContext(NPP id, |
| 706 NPDeviceContext* context, |
| 707 int32 state, |
| 708 int32 value) { |
| 709 scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); |
| 710 if (plugin) { |
| 711 return plugin->webplugin()->delegate()->Device2DSetStateContext( |
| 712 static_cast<NPDeviceContext2D*>(context), state, value); |
| 713 } |
| 714 return NPERR_GENERIC_ERROR; |
| 715 } |
| 716 |
| 717 static NPError Device2DGetStateContext(NPP id, |
| 718 NPDeviceContext* context, |
| 719 int32 state, |
| 720 int32* value) { |
| 721 scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); |
| 722 if (plugin) { |
| 723 return plugin->webplugin()->delegate()->Device2DGetStateContext( |
| 724 static_cast<NPDeviceContext2D*>(context), state, value); |
| 725 } |
| 726 return NPERR_GENERIC_ERROR; |
| 727 } |
| 728 |
| 729 static NPError Device2DFlushContext(NPP id, |
| 730 NPDeviceContext* context, |
| 731 NPDeviceFlushContextCallbackPtr callback, |
| 732 void* user_data) { |
| 733 scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); |
| 734 if (plugin) { |
| 735 NPError err = plugin->webplugin()->delegate()->Device2DFlushContext( |
| 736 static_cast<NPDeviceContext2D*>(context), callback, user_data); |
| 690 | 737 |
| 691 // Invoke the callback to inform the caller the work was done. | 738 // Invoke the callback to inform the caller the work was done. |
| 739 // TODO(brettw) this is probably not how we want this to work, this should |
| 740 // happen when the frame is painted so the plugin knows when it can draw |
| 741 // the next frame. |
| 692 if (callback != NULL) | 742 if (callback != NULL) |
| 693 (*callback)(context, err, user_data); | 743 (*callback)(id, context, err, user_data); |
| 694 | 744 |
| 695 // Return any errors. | 745 // Return any errors. |
| 696 return err; | 746 return err; |
| 697 } | 747 } |
| 698 return NPERR_GENERIC_ERROR; | 748 return NPERR_GENERIC_ERROR; |
| 699 } | 749 } |
| 700 | 750 |
| 701 static NPError DestroyRenderContext(NPP id, | 751 static NPError Device2DDestroyContext(NPP id, |
| 702 NPRenderContext* context) { | 752 NPDeviceContext* context) { |
| 703 scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); | 753 scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); |
| 704 if (plugin) { | 754 if (plugin) { |
| 705 webkit_glue::WebPluginDelegate* delegate = plugin->webplugin()->delegate(); | 755 return plugin->webplugin()->delegate()->Device2DDestroyContext( |
| 706 return delegate->DestroyRenderContext(context); | 756 static_cast<NPDeviceContext2D*>(context)); |
| 707 } | 757 } |
| 708 return NPERR_GENERIC_ERROR; | 758 return NPERR_GENERIC_ERROR; |
| 709 } | 759 } |
| 710 | 760 |
| 711 static NPError OpenFileInSandbox(NPP id, const char* file_name, void** handle) { | 761 // ----------------------------------------------------------------------------- |
| 712 scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); | 762 |
| 713 if (!plugin) | 763 static NPDevice* AcquireDevice(NPP id, NPDeviceID device_id) { |
| 714 return NPERR_GENERIC_ERROR; | 764 static NPDevice device_2d = { |
| 715 webkit_glue::WebPluginDelegate* delegate = plugin->webplugin()->delegate(); | 765 Device2DQueryCapability, |
| 716 return delegate->OpenFileInSandbox(file_name, handle); | 766 Device2DQueryConfig, |
| 767 Device2DInitializeContext, |
| 768 Device2DSetStateContext, |
| 769 Device2DGetStateContext, |
| 770 Device2DFlushContext, |
| 771 Device2DDestroyContext, |
| 772 }; |
| 773 switch (device_id) { |
| 774 case NPPepper2DDevice: |
| 775 return const_cast<NPDevice*>(&device_2d); |
| 776 default: |
| 777 return NULL; |
| 778 } |
| 717 } | 779 } |
| 780 |
| 718 #endif // defined(PEPPER_APIS_ENABLED) | 781 #endif // defined(PEPPER_APIS_ENABLED) |
| 719 | 782 |
| 720 NPError NPN_GetValue(NPP id, NPNVariable variable, void *value) { | 783 NPError NPN_GetValue(NPP id, NPNVariable variable, void *value) { |
| 721 // Allows the plugin to query the browser for information | 784 // Allows the plugin to query the browser for information |
| 722 // | 785 // |
| 723 // Variables: | 786 // Variables: |
| 724 // NPNVxDisplay (unix only) | 787 // NPNVxDisplay (unix only) |
| 725 // NPNVxtAppContext (unix only) | 788 // NPNVxtAppContext (unix only) |
| 726 // NPNVnetscapeWindow (win only) - Gets the native window on which the | 789 // NPNVnetscapeWindow (win only) - Gets the native window on which the |
| 727 // plug-in drawing occurs, returns HWND | 790 // plug-in drawing occurs, returns HWND |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 // we do not support these drawing and event models. | 928 // we do not support these drawing and event models. |
| 866 NPBool* supports_model = reinterpret_cast<NPBool*>(value); | 929 NPBool* supports_model = reinterpret_cast<NPBool*>(value); |
| 867 *supports_model = FALSE; | 930 *supports_model = FALSE; |
| 868 rv = NPERR_NO_ERROR; | 931 rv = NPERR_NO_ERROR; |
| 869 break; | 932 break; |
| 870 } | 933 } |
| 871 #endif | 934 #endif |
| 872 #if defined(PEPPER_APIS_ENABLED) | 935 #if defined(PEPPER_APIS_ENABLED) |
| 873 case NPNVPepperExtensions: | 936 case NPNVPepperExtensions: |
| 874 { | 937 { |
| 875 static const NPPepperExtensions kExtensions = { | 938 static const NPExtensions kExtensions = { |
| 876 InitializeRenderContext, | 939 AcquireDevice, |
| 877 FlushRenderContext, | |
| 878 DestroyRenderContext, | |
| 879 OpenFileInSandbox, | |
| 880 }; | 940 }; |
| 881 // Return a pointer to the canonical function table. | 941 // Return a pointer to the canonical function table. |
| 882 NPPepperExtensions* extensions = | 942 NPExtensions* extensions = const_cast<NPExtensions*>(&kExtensions); |
| 883 const_cast<NPPepperExtensions*>(&kExtensions); | 943 NPExtensions** exts = reinterpret_cast<NPExtensions**>(value); |
| 884 NPPepperExtensions** exts = reinterpret_cast<NPPepperExtensions**>(value); | |
| 885 *exts = extensions; | 944 *exts = extensions; |
| 886 rv = NPERR_NO_ERROR; | 945 rv = NPERR_NO_ERROR; |
| 887 break; | 946 break; |
| 888 } | 947 } |
| 889 #endif // defined(PEPPER_APIS_ENABLED) | 948 #endif // defined(PEPPER_APIS_ENABLED) |
| 890 default: | 949 default: |
| 891 { | 950 { |
| 892 // TODO: implement me | 951 // TODO: implement me |
| 893 DLOG(INFO) << "NPN_GetValue(" << variable << ") is not implemented yet."; | 952 DLOG(INFO) << "NPN_GetValue(" << variable << ") is not implemented yet."; |
| 894 break; | 953 break; |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 | 1183 |
| 1125 return plugin->ScheduleTimer(interval, repeat, func); | 1184 return plugin->ScheduleTimer(interval, repeat, func); |
| 1126 } | 1185 } |
| 1127 | 1186 |
| 1128 void NPN_UnscheduleTimer(NPP id, uint32 timer_id) { | 1187 void NPN_UnscheduleTimer(NPP id, uint32 timer_id) { |
| 1129 scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); | 1188 scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); |
| 1130 if (plugin) | 1189 if (plugin) |
| 1131 plugin->UnscheduleTimer(timer_id); | 1190 plugin->UnscheduleTimer(timer_id); |
| 1132 } | 1191 } |
| 1133 } // extern "C" | 1192 } // extern "C" |
| OLD | NEW |