| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "webkit/plugins/npapi/plugin_host.h" | 5 #include "content/child/npapi/plugin_host.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "content/child/npapi/plugin_instance.h" |
| 17 #include "content/child/npapi/plugin_lib.h" |
| 18 #include "content/child/npapi/plugin_stream_url.h" |
| 19 #include "content/child/npapi/webplugin_delegate.h" |
| 16 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
| 17 #include "third_party/WebKit/public/web/WebBindings.h" | 21 #include "third_party/WebKit/public/web/WebBindings.h" |
| 18 #include "third_party/WebKit/public/web/WebKit.h" | 22 #include "third_party/WebKit/public/web/WebKit.h" |
| 19 #include "third_party/npapi/bindings/npruntime.h" | 23 #include "third_party/npapi/bindings/npruntime.h" |
| 20 #include "ui/base/ui_base_switches.h" | 24 #include "ui/base/ui_base_switches.h" |
| 21 #include "ui/gl/gl_implementation.h" | 25 #include "ui/gl/gl_implementation.h" |
| 22 #include "ui/gl/gl_surface.h" | 26 #include "ui/gl/gl_surface.h" |
| 23 #include "webkit/common/user_agent/user_agent.h" | 27 #include "webkit/common/user_agent/user_agent.h" |
| 24 #include "webkit/plugins/npapi/plugin_instance.h" | |
| 25 #include "webkit/plugins/npapi/plugin_lib.h" | |
| 26 #include "webkit/plugins/npapi/plugin_stream_url.h" | |
| 27 #include "webkit/plugins/npapi/webplugin_delegate.h" | |
| 28 #include "webkit/plugins/webplugininfo.h" | 28 #include "webkit/plugins/webplugininfo.h" |
| 29 | 29 |
| 30 #if defined(OS_MACOSX) | 30 #if defined(OS_MACOSX) |
| 31 #include "base/mac/mac_util.h" | 31 #include "base/mac/mac_util.h" |
| 32 #endif | 32 #endif |
| 33 | 33 |
| 34 using WebKit::WebBindings; | 34 using WebKit::WebBindings; |
| 35 | 35 |
| 36 // Declarations for stub implementations of deprecated functions, which are no | 36 // Declarations for stub implementations of deprecated functions, which are no |
| 37 // longer listed in npapi.h. | 37 // longer listed in npapi.h. |
| 38 extern "C" { | 38 extern "C" { |
| 39 void* NPN_GetJavaEnv(); | 39 void* NPN_GetJavaEnv(); |
| 40 void* NPN_GetJavaPeer(NPP); | 40 void* NPN_GetJavaPeer(NPP); |
| 41 } | 41 } |
| 42 | 42 |
| 43 namespace webkit { | 43 namespace content { |
| 44 namespace npapi { | |
| 45 | 44 |
| 46 // Finds a PluginInstance from an NPP. | 45 // Finds a PluginInstance from an NPP. |
| 47 // The caller must take a reference if needed. | 46 // The caller must take a reference if needed. |
| 48 static PluginInstance* FindInstance(NPP id) { | 47 static PluginInstance* FindInstance(NPP id) { |
| 49 if (id == NULL) { | 48 if (id == NULL) { |
| 50 return NULL; | 49 return NULL; |
| 51 } | 50 } |
| 52 return reinterpret_cast<PluginInstance*>(id->ndata); | 51 return reinterpret_cast<PluginInstance*>(id->ndata); |
| 53 } | 52 } |
| 54 | 53 |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 break; | 291 break; |
| 293 } | 292 } |
| 294 } | 293 } |
| 295 state = newstate; | 294 state = newstate; |
| 296 ptr++; | 295 ptr++; |
| 297 } while (!done); | 296 } while (!done); |
| 298 | 297 |
| 299 return !err; | 298 return !err; |
| 300 } | 299 } |
| 301 | 300 |
| 302 } // namespace npapi | 301 } // namespace content |
| 303 } // namespace webkit | |
| 304 | 302 |
| 305 extern "C" { | 303 extern "C" { |
| 306 | 304 |
| 307 using webkit::npapi::FindInstance; | 305 using content::FindInstance; |
| 308 using webkit::npapi::PluginHost; | 306 using content::PluginHost; |
| 309 using webkit::npapi::PluginInstance; | 307 using content::PluginInstance; |
| 310 using webkit::npapi::WebPlugin; | 308 using content::WebPlugin; |
| 311 | 309 |
| 312 // Allocates memory from the host's memory space. | 310 // Allocates memory from the host's memory space. |
| 313 void* NPN_MemAlloc(uint32_t size) { | 311 void* NPN_MemAlloc(uint32_t size) { |
| 314 // Note: We must use the same allocator/deallocator | 312 // Note: We must use the same allocator/deallocator |
| 315 // that is used by the javascript library, as some of the | 313 // that is used by the javascript library, as some of the |
| 316 // JS APIs will pass memory to the plugin which the plugin | 314 // JS APIs will pass memory to the plugin which the plugin |
| 317 // will attempt to free. | 315 // will attempt to free. |
| 318 return malloc(size); | 316 return malloc(size); |
| 319 } | 317 } |
| 320 | 318 |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 case NPNVsupportsCocoaBool: { | 782 case NPNVsupportsCocoaBool: { |
| 785 // These drawing and event models are always supported. | 783 // These drawing and event models are always supported. |
| 786 NPBool* supports_model = reinterpret_cast<NPBool*>(value); | 784 NPBool* supports_model = reinterpret_cast<NPBool*>(value); |
| 787 *supports_model = true; | 785 *supports_model = true; |
| 788 rv = NPERR_NO_ERROR; | 786 rv = NPERR_NO_ERROR; |
| 789 break; | 787 break; |
| 790 } | 788 } |
| 791 case NPNVsupportsInvalidatingCoreAnimationBool: | 789 case NPNVsupportsInvalidatingCoreAnimationBool: |
| 792 case NPNVsupportsCoreAnimationBool: { | 790 case NPNVsupportsCoreAnimationBool: { |
| 793 NPBool* supports_model = reinterpret_cast<NPBool*>(value); | 791 NPBool* supports_model = reinterpret_cast<NPBool*>(value); |
| 794 *supports_model = webkit::npapi::SupportsCoreAnimationPlugins(); | 792 *supports_model = content::SupportsCoreAnimationPlugins(); |
| 795 rv = NPERR_NO_ERROR; | 793 rv = NPERR_NO_ERROR; |
| 796 break; | 794 break; |
| 797 } | 795 } |
| 798 #ifndef NP_NO_CARBON | 796 #ifndef NP_NO_CARBON |
| 799 case NPNVsupportsCarbonBool: | 797 case NPNVsupportsCarbonBool: |
| 800 #endif | 798 #endif |
| 801 #ifndef NP_NO_QUICKDRAW | 799 #ifndef NP_NO_QUICKDRAW |
| 802 case NPNVsupportsQuickDrawBool: | 800 case NPNVsupportsQuickDrawBool: |
| 803 #endif | 801 #endif |
| 804 case NPNVsupportsOpenGLBool: { | 802 case NPNVsupportsOpenGLBool: { |
| 805 // These models are never supported. OpenGL was never widely supported, | 803 // These models are never supported. OpenGL was never widely supported, |
| 806 // and QuickDraw and Carbon have been deprecated for quite some time. | 804 // and QuickDraw and Carbon have been deprecated for quite some time. |
| 807 NPBool* supports_model = reinterpret_cast<NPBool*>(value); | 805 NPBool* supports_model = reinterpret_cast<NPBool*>(value); |
| 808 *supports_model = false; | 806 *supports_model = false; |
| 809 rv = NPERR_NO_ERROR; | 807 rv = NPERR_NO_ERROR; |
| 810 break; | 808 break; |
| 811 } | 809 } |
| 812 case NPNVsupportsCompositingCoreAnimationPluginsBool: { | 810 case NPNVsupportsCompositingCoreAnimationPluginsBool: { |
| 813 NPBool* supports_compositing = reinterpret_cast<NPBool*>(value); | 811 NPBool* supports_compositing = reinterpret_cast<NPBool*>(value); |
| 814 *supports_compositing = | 812 *supports_compositing = content::SupportsCoreAnimationPlugins(); |
| 815 webkit::npapi::SupportsCoreAnimationPlugins(); | |
| 816 rv = NPERR_NO_ERROR; | 813 rv = NPERR_NO_ERROR; |
| 817 break; | 814 break; |
| 818 } | 815 } |
| 819 case NPNVsupportsUpdatedCocoaTextInputBool: { | 816 case NPNVsupportsUpdatedCocoaTextInputBool: { |
| 820 // We support the clarifications to the Cocoa IME event spec. | 817 // We support the clarifications to the Cocoa IME event spec. |
| 821 NPBool* supports_update = reinterpret_cast<NPBool*>(value); | 818 NPBool* supports_update = reinterpret_cast<NPBool*>(value); |
| 822 *supports_update = true; | 819 *supports_update = true; |
| 823 rv = NPERR_NO_ERROR; | 820 rv = NPERR_NO_ERROR; |
| 824 break; | 821 break; |
| 825 } | 822 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 // TODO: implement me | 869 // TODO: implement me |
| 873 DVLOG(1) << "NPN_SetValue(NPPVpluginKeepLibraryInMemory) is not " | 870 DVLOG(1) << "NPN_SetValue(NPPVpluginKeepLibraryInMemory) is not " |
| 874 "implemented."; | 871 "implemented."; |
| 875 return NPERR_GENERIC_ERROR; | 872 return NPERR_GENERIC_ERROR; |
| 876 #if defined(OS_MACOSX) | 873 #if defined(OS_MACOSX) |
| 877 case NPPVpluginDrawingModel: { | 874 case NPPVpluginDrawingModel: { |
| 878 intptr_t model = reinterpret_cast<intptr_t>(value); | 875 intptr_t model = reinterpret_cast<intptr_t>(value); |
| 879 if (model == NPDrawingModelCoreGraphics || | 876 if (model == NPDrawingModelCoreGraphics || |
| 880 ((model == NPDrawingModelInvalidatingCoreAnimation || | 877 ((model == NPDrawingModelInvalidatingCoreAnimation || |
| 881 model == NPDrawingModelCoreAnimation) && | 878 model == NPDrawingModelCoreAnimation) && |
| 882 webkit::npapi::SupportsCoreAnimationPlugins())) { | 879 content::SupportsCoreAnimationPlugins())) { |
| 883 plugin->set_drawing_model(static_cast<NPDrawingModel>(model)); | 880 plugin->set_drawing_model(static_cast<NPDrawingModel>(model)); |
| 884 return NPERR_NO_ERROR; | 881 return NPERR_NO_ERROR; |
| 885 } | 882 } |
| 886 return NPERR_GENERIC_ERROR; | 883 return NPERR_GENERIC_ERROR; |
| 887 } | 884 } |
| 888 case NPPVpluginEventModel: { | 885 case NPPVpluginEventModel: { |
| 889 // Only the Cocoa event model is supported. | 886 // Only the Cocoa event model is supported. |
| 890 intptr_t model = reinterpret_cast<intptr_t>(value); | 887 intptr_t model = reinterpret_cast<intptr_t>(value); |
| 891 if (model == NPEventModelCocoa) { | 888 if (model == NPEventModelCocoa) { |
| 892 plugin->set_event_model(static_cast<NPEventModel>(model)); | 889 plugin->set_event_model(static_cast<NPEventModel>(model)); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 } | 1101 } |
| 1105 | 1102 |
| 1106 void NPN_URLRedirectResponse(NPP instance, void* notify_data, NPBool allow) { | 1103 void NPN_URLRedirectResponse(NPP instance, void* notify_data, NPBool allow) { |
| 1107 scoped_refptr<PluginInstance> plugin(FindInstance(instance)); | 1104 scoped_refptr<PluginInstance> plugin(FindInstance(instance)); |
| 1108 if (plugin.get()) { | 1105 if (plugin.get()) { |
| 1109 plugin->URLRedirectResponse(!!allow, notify_data); | 1106 plugin->URLRedirectResponse(!!allow, notify_data); |
| 1110 } | 1107 } |
| 1111 } | 1108 } |
| 1112 | 1109 |
| 1113 } // extern "C" | 1110 } // extern "C" |
| OLD | NEW |