OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/plugins/npapi/plugin_host.h" |
6 | 6 |
7 #include "app/gfx/gl/gl_context.h" | 7 #include "app/gfx/gl/gl_context.h" |
8 #include "app/gfx/gl/gl_implementation.h" | 8 #include "app/gfx/gl/gl_implementation.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
686 // plug-in drawing occurs, returns HWND | 686 // plug-in drawing occurs, returns HWND |
687 // NPNVjavascriptEnabledBool: tells whether Javascript is enabled | 687 // NPNVjavascriptEnabledBool: tells whether Javascript is enabled |
688 // NPNVasdEnabledBool: tells whether SmartUpdate is enabled | 688 // NPNVasdEnabledBool: tells whether SmartUpdate is enabled |
689 // NPNVOfflineBool: tells whether offline-mode is enabled | 689 // NPNVOfflineBool: tells whether offline-mode is enabled |
690 | 690 |
691 NPError rv = NPERR_GENERIC_ERROR; | 691 NPError rv = NPERR_GENERIC_ERROR; |
692 | 692 |
693 switch (static_cast<int>(variable)) { | 693 switch (static_cast<int>(variable)) { |
694 case NPNVWindowNPObject: { | 694 case NPNVWindowNPObject: { |
695 scoped_refptr<PluginInstance> plugin(FindInstance(id)); | 695 scoped_refptr<PluginInstance> plugin(FindInstance(id)); |
696 if (!plugin.get()) { | |
ananta
2011/03/23 18:39:26
Should we move this code outside the switch block
davidben
2011/03/23 18:51:08
Some variables don't seem to require a plugin inst
| |
697 NOTREACHED(); | |
698 return NPERR_INVALID_INSTANCE_ERROR; | |
699 } | |
696 NPObject *np_object = plugin->webplugin()->GetWindowScriptNPObject(); | 700 NPObject *np_object = plugin->webplugin()->GetWindowScriptNPObject(); |
697 // Return value is expected to be retained, as | 701 // Return value is expected to be retained, as |
698 // described here: | 702 // described here: |
699 // <http://www.mozilla.org/projects/plugins/npruntime.html#browseraccess> | 703 // <http://www.mozilla.org/projects/plugins/npruntime.html#browseraccess> |
700 if (np_object) { | 704 if (np_object) { |
701 WebBindings::retainObject(np_object); | 705 WebBindings::retainObject(np_object); |
702 void **v = (void **)value; | 706 void **v = (void **)value; |
703 *v = np_object; | 707 *v = np_object; |
704 rv = NPERR_NO_ERROR; | 708 rv = NPERR_NO_ERROR; |
705 } else { | 709 } else { |
706 NOTREACHED(); | 710 NOTREACHED(); |
707 } | 711 } |
708 break; | 712 break; |
709 } | 713 } |
710 case NPNVPluginElementNPObject: { | 714 case NPNVPluginElementNPObject: { |
711 scoped_refptr<PluginInstance> plugin(FindInstance(id)); | 715 scoped_refptr<PluginInstance> plugin(FindInstance(id)); |
716 if (!plugin.get()) { | |
717 NOTREACHED(); | |
718 return NPERR_INVALID_INSTANCE_ERROR; | |
719 } | |
712 NPObject *np_object = plugin->webplugin()->GetPluginElement(); | 720 NPObject *np_object = plugin->webplugin()->GetPluginElement(); |
713 // Return value is expected to be retained, as | 721 // Return value is expected to be retained, as |
714 // described here: | 722 // described here: |
715 // <http://www.mozilla.org/projects/plugins/npruntime.html#browseraccess> | 723 // <http://www.mozilla.org/projects/plugins/npruntime.html#browseraccess> |
716 if (np_object) { | 724 if (np_object) { |
717 WebBindings::retainObject(np_object); | 725 WebBindings::retainObject(np_object); |
718 void** v = static_cast<void**>(value); | 726 void** v = static_cast<void**>(value); |
719 *v = np_object; | 727 *v = np_object; |
720 rv = NPERR_NO_ERROR; | 728 rv = NPERR_NO_ERROR; |
721 } else { | 729 } else { |
722 NOTREACHED(); | 730 NOTREACHED(); |
723 } | 731 } |
724 break; | 732 break; |
725 } | 733 } |
726 #if !defined(OS_MACOSX) // OS X doesn't have windowed plugins. | 734 #if !defined(OS_MACOSX) // OS X doesn't have windowed plugins. |
727 case NPNVnetscapeWindow: { | 735 case NPNVnetscapeWindow: { |
728 scoped_refptr<PluginInstance> plugin = FindInstance(id); | 736 scoped_refptr<PluginInstance> plugin = FindInstance(id); |
729 if (!plugin.get()) { | 737 if (!plugin.get()) { |
730 NOTREACHED(); | 738 NOTREACHED(); |
731 return NPERR_GENERIC_ERROR; | 739 return NPERR_INVALID_INSTANCE_ERROR; |
732 } | 740 } |
733 gfx::PluginWindowHandle handle = plugin->window_handle(); | 741 gfx::PluginWindowHandle handle = plugin->window_handle(); |
734 *((void**)value) = (void*)handle; | 742 *((void**)value) = (void*)handle; |
735 rv = NPERR_NO_ERROR; | 743 rv = NPERR_NO_ERROR; |
736 break; | 744 break; |
737 } | 745 } |
738 #endif | 746 #endif |
739 case NPNVjavascriptEnabledBool: { | 747 case NPNVjavascriptEnabledBool: { |
740 // yes, JS is enabled. | 748 // yes, JS is enabled. |
741 *((void**)value) = (void*)1; | 749 *((void**)value) = (void*)1; |
(...skipping 14 matching lines...) Expand all Loading... | |
756 #endif | 764 #endif |
757 case NPNVSupportsWindowless: { | 765 case NPNVSupportsWindowless: { |
758 NPBool* supports_windowless = reinterpret_cast<NPBool*>(value); | 766 NPBool* supports_windowless = reinterpret_cast<NPBool*>(value); |
759 *supports_windowless = true; | 767 *supports_windowless = true; |
760 rv = NPERR_NO_ERROR; | 768 rv = NPERR_NO_ERROR; |
761 break; | 769 break; |
762 } | 770 } |
763 case NPNVprivateModeBool: { | 771 case NPNVprivateModeBool: { |
764 NPBool* private_mode = reinterpret_cast<NPBool*>(value); | 772 NPBool* private_mode = reinterpret_cast<NPBool*>(value); |
765 scoped_refptr<PluginInstance> plugin(FindInstance(id)); | 773 scoped_refptr<PluginInstance> plugin(FindInstance(id)); |
774 if (!plugin.get()) { | |
775 NOTREACHED(); | |
776 return NPERR_INVALID_INSTANCE_ERROR; | |
777 } | |
766 *private_mode = plugin->webplugin()->IsOffTheRecord(); | 778 *private_mode = plugin->webplugin()->IsOffTheRecord(); |
767 rv = NPERR_NO_ERROR; | 779 rv = NPERR_NO_ERROR; |
768 break; | 780 break; |
769 } | 781 } |
770 case webkit::npapi::default_plugin::kMissingPluginStatusStart + | 782 case webkit::npapi::default_plugin::kMissingPluginStatusStart + |
771 webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE: | 783 webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE: |
772 // fall through | 784 // fall through |
773 case webkit::npapi::default_plugin::kMissingPluginStatusStart + | 785 case webkit::npapi::default_plugin::kMissingPluginStatusStart + |
774 webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD: { | 786 webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD: { |
775 // This is a hack for the default plugin to send notification to | 787 // This is a hack for the default plugin to send notification to |
776 // renderer. Even though we check if the plugin is the default plugin, | 788 // renderer. Even though we check if the plugin is the default plugin, |
777 // we still need to worry about future standard change that may conflict | 789 // we still need to worry about future standard change that may conflict |
778 // with the variable definition, in order to avoid duplicate case clauses | 790 // with the variable definition, in order to avoid duplicate case clauses |
779 // in this big switch statement. | 791 // in this big switch statement. |
780 scoped_refptr<PluginInstance> plugin(FindInstance(id)); | 792 scoped_refptr<PluginInstance> plugin(FindInstance(id)); |
793 if (!plugin.get()) { | |
794 NOTREACHED(); | |
795 return NPERR_INVALID_INSTANCE_ERROR; | |
796 } | |
781 if (plugin->plugin_lib()->plugin_info().path.value() == | 797 if (plugin->plugin_lib()->plugin_info().path.value() == |
782 webkit::npapi::kDefaultPluginLibraryName) { | 798 webkit::npapi::kDefaultPluginLibraryName) { |
783 plugin->webplugin()->OnMissingPluginStatus(variable - | 799 plugin->webplugin()->OnMissingPluginStatus(variable - |
784 webkit::npapi::default_plugin::kMissingPluginStatusStart); | 800 webkit::npapi::default_plugin::kMissingPluginStatusStart); |
785 } | 801 } |
786 break; | 802 break; |
787 } | 803 } |
788 #if defined(OS_MACOSX) | 804 #if defined(OS_MACOSX) |
789 case NPNVpluginDrawingModel: { | 805 case NPNVpluginDrawingModel: { |
790 // return the drawing model that was negotiated when we initialized. | 806 // return the drawing model that was negotiated when we initialized. |
791 scoped_refptr<PluginInstance> plugin(FindInstance(id)); | 807 scoped_refptr<PluginInstance> plugin(FindInstance(id)); |
808 if (!plugin.get()) { | |
809 NOTREACHED(); | |
810 return NPERR_INVALID_INSTANCE_ERROR; | |
811 } | |
792 *reinterpret_cast<int*>(value) = plugin->drawing_model(); | 812 *reinterpret_cast<int*>(value) = plugin->drawing_model(); |
793 rv = NPERR_NO_ERROR; | 813 rv = NPERR_NO_ERROR; |
794 break; | 814 break; |
795 } | 815 } |
796 #ifndef NP_NO_QUICKDRAW | 816 #ifndef NP_NO_QUICKDRAW |
797 case NPNVsupportsQuickDrawBool: { | 817 case NPNVsupportsQuickDrawBool: { |
798 // We do not admit to supporting the QuickDraw drawing model. The logic | 818 // We do not admit to supporting the QuickDraw drawing model. The logic |
799 // here is that our QuickDraw plugin support is so rudimentary that we | 819 // here is that our QuickDraw plugin support is so rudimentary that we |
800 // only want to use it as a fallback to keep plugins from crashing: if a | 820 // only want to use it as a fallback to keep plugins from crashing: if a |
801 // plugin knows enough to ask, we want them to use CoreGraphics. | 821 // plugin knows enough to ask, we want them to use CoreGraphics. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
862 DVLOG(1) << "NPN_GetValue(" << variable << ") is not implemented yet."; | 882 DVLOG(1) << "NPN_GetValue(" << variable << ") is not implemented yet."; |
863 break; | 883 break; |
864 } | 884 } |
865 return rv; | 885 return rv; |
866 } | 886 } |
867 | 887 |
868 NPError NPN_SetValue(NPP id, NPPVariable variable, void* value) { | 888 NPError NPN_SetValue(NPP id, NPPVariable variable, void* value) { |
869 // Allows the plugin to set various modes | 889 // Allows the plugin to set various modes |
870 | 890 |
871 scoped_refptr<PluginInstance> plugin(FindInstance(id)); | 891 scoped_refptr<PluginInstance> plugin(FindInstance(id)); |
892 if (!plugin.get()) { | |
893 NOTREACHED(); | |
894 return NPERR_INVALID_INSTANCE_ERROR; | |
895 } | |
872 switch(variable) { | 896 switch(variable) { |
873 case NPPVpluginWindowBool: { | 897 case NPPVpluginWindowBool: { |
874 // Sets windowless mode for display of the plugin | 898 // Sets windowless mode for display of the plugin |
875 // Note: the documentation at | 899 // Note: the documentation at |
876 // http://developer.mozilla.org/en/docs/NPN_SetValue is wrong. When | 900 // http://developer.mozilla.org/en/docs/NPN_SetValue is wrong. When |
877 // value is NULL, the mode is set to true. This is the same way Mozilla | 901 // value is NULL, the mode is set to true. This is the same way Mozilla |
878 // works. | 902 // works. |
879 plugin->set_windowless(value == 0); | 903 plugin->set_windowless(value == 0); |
880 return NPERR_NO_ERROR; | 904 return NPERR_NO_ERROR; |
881 } | 905 } |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1132 } | 1156 } |
1133 | 1157 |
1134 void NPN_URLRedirectResponse(NPP instance, void* notify_data, NPBool allow) { | 1158 void NPN_URLRedirectResponse(NPP instance, void* notify_data, NPBool allow) { |
1135 scoped_refptr<PluginInstance> plugin(FindInstance(instance)); | 1159 scoped_refptr<PluginInstance> plugin(FindInstance(instance)); |
1136 if (plugin.get()) { | 1160 if (plugin.get()) { |
1137 plugin->URLRedirectResponse(!!allow, notify_data); | 1161 plugin->URLRedirectResponse(!!allow, notify_data); |
1138 } | 1162 } |
1139 } | 1163 } |
1140 | 1164 |
1141 } // extern "C" | 1165 } // extern "C" |
OLD | NEW |