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/ppapi/ppapi_plugin_instance.h" | 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 if (!plugin_policy_updated_interface_) { | 718 if (!plugin_policy_updated_interface_) { |
719 plugin_policy_updated_interface_ = | 719 plugin_policy_updated_interface_ = |
720 static_cast<const PPP_PolicyUpdate_Dev*>(module_->GetPluginInterface( | 720 static_cast<const PPP_PolicyUpdate_Dev*>(module_->GetPluginInterface( |
721 PPP_POLICY_UPDATE_DEV_INTERFACE)); | 721 PPP_POLICY_UPDATE_DEV_INTERFACE)); |
722 } | 722 } |
723 | 723 |
724 return !!plugin_policy_updated_interface_; | 724 return !!plugin_policy_updated_interface_; |
725 } | 725 } |
726 | 726 |
727 bool PluginInstance::LoadPrintInterface() { | 727 bool PluginInstance::LoadPrintInterface() { |
728 if (!plugin_print_interface_.get()) { | 728 if (!plugin_print_interface_) { |
729 // Try to get the most recent version first. Fall back to older supported | 729 plugin_print_interface_ = static_cast<const PPP_Printing_Dev*>( |
730 // versions if necessary. | 730 module_->GetPluginInterface(PPP_PRINTING_DEV_INTERFACE)); |
731 const PPP_Printing_Dev_0_4* print_if = | |
732 static_cast<const PPP_Printing_Dev_0_4*>( | |
733 module_->GetPluginInterface(PPP_PRINTING_DEV_INTERFACE_0_4)); | |
734 if (print_if) { | |
735 plugin_print_interface_.reset(new PPP_Printing_Dev_Combined(*print_if)); | |
736 } else { | |
737 const PPP_Printing_Dev_0_3* print_if_0_3 = | |
738 static_cast<const PPP_Printing_Dev_0_3*>( | |
739 module_->GetPluginInterface(PPP_PRINTING_DEV_INTERFACE_0_3)); | |
740 if (print_if_0_3) | |
741 plugin_print_interface_.reset( | |
742 new PPP_Printing_Dev_Combined(*print_if_0_3)); | |
743 } | |
744 } | 731 } |
745 return !!plugin_print_interface_.get(); | 732 return !!plugin_print_interface_; |
746 } | 733 } |
747 | 734 |
748 bool PluginInstance::LoadPrivateInterface() { | 735 bool PluginInstance::LoadPrivateInterface() { |
749 if (!plugin_private_interface_) { | 736 if (!plugin_private_interface_) { |
750 plugin_private_interface_ = static_cast<const PPP_Instance_Private*>( | 737 plugin_private_interface_ = static_cast<const PPP_Instance_Private*>( |
751 module_->GetPluginInterface(PPP_INSTANCE_PRIVATE_INTERFACE)); | 738 module_->GetPluginInterface(PPP_INSTANCE_PRIVATE_INTERFACE)); |
752 } | 739 } |
753 | 740 |
754 return !!plugin_private_interface_; | 741 return !!plugin_private_interface_; |
755 } | 742 } |
756 | 743 |
757 bool PluginInstance::LoadSelectionInterface() { | 744 bool PluginInstance::LoadSelectionInterface() { |
758 if (!plugin_selection_interface_) { | 745 if (!plugin_selection_interface_) { |
759 plugin_selection_interface_ = | 746 plugin_selection_interface_ = |
760 static_cast<const PPP_Selection_Dev*>(module_->GetPluginInterface( | 747 static_cast<const PPP_Selection_Dev*>(module_->GetPluginInterface( |
761 PPP_SELECTION_DEV_INTERFACE)); | 748 PPP_SELECTION_DEV_INTERFACE)); |
(...skipping 18 matching lines...) Expand all Loading... |
780 | 767 |
781 void PluginInstance::ReportGeometry() { | 768 void PluginInstance::ReportGeometry() { |
782 // If this call was delayed, we may have transitioned back to fullscreen in | 769 // If this call was delayed, we may have transitioned back to fullscreen in |
783 // the mean time, so only report the geometry if we are actually in normal | 770 // the mean time, so only report the geometry if we are actually in normal |
784 // mode. | 771 // mode. |
785 if (container_ && !fullscreen_container_) | 772 if (container_ && !fullscreen_container_) |
786 container_->reportGeometry(); | 773 container_->reportGeometry(); |
787 } | 774 } |
788 | 775 |
789 bool PluginInstance::GetPreferredPrintOutputFormat( | 776 bool PluginInstance::GetPreferredPrintOutputFormat( |
790 PP_PrintOutputFormat_Dev_0_4* format) { | 777 PP_PrintOutputFormat_Dev* format) { |
791 // Keep a reference on the stack. See NOTE above. | 778 // Keep a reference on the stack. See NOTE above. |
792 scoped_refptr<PluginInstance> ref(this); | 779 scoped_refptr<PluginInstance> ref(this); |
793 if (!LoadPrintInterface()) | 780 if (!LoadPrintInterface()) |
794 return false; | 781 return false; |
795 if (plugin_print_interface_->QuerySupportedFormats) { | 782 uint32_t supported_formats = |
796 // If the most recent version of the QuerySupportedFormats functions is | 783 plugin_print_interface_->QuerySupportedFormats(pp_instance()); |
797 // available, use it. | 784 if (supported_formats & PP_PRINTOUTPUTFORMAT_PDF) { |
798 uint32_t supported_formats = | 785 *format = PP_PRINTOUTPUTFORMAT_PDF; |
799 plugin_print_interface_->QuerySupportedFormats(pp_instance()); | 786 return true; |
800 if (supported_formats & PP_PRINTOUTPUTFORMAT_PDF_0_4) { | 787 } else if (supported_formats & PP_PRINTOUTPUTFORMAT_RASTER) { |
801 *format = PP_PRINTOUTPUTFORMAT_PDF_0_4; | 788 *format = PP_PRINTOUTPUTFORMAT_RASTER; |
802 return true; | 789 return true; |
803 } else if (supported_formats & PP_PRINTOUTPUTFORMAT_RASTER_0_4) { | |
804 *format = PP_PRINTOUTPUTFORMAT_RASTER_0_4; | |
805 return true; | |
806 } | |
807 return false; | |
808 } else if (plugin_print_interface_->QuerySupportedFormats_0_3) { | |
809 // If we couldn't use the latest version of the function, but the 0.3 | |
810 // version exists, we can use it. | |
811 uint32_t format_count = 0; | |
812 PP_PrintOutputFormat_Dev_0_3* supported_formats = | |
813 plugin_print_interface_->QuerySupportedFormats_0_3(pp_instance(), | |
814 &format_count); | |
815 if (!supported_formats) | |
816 return false; | |
817 | |
818 bool found_supported_format = false; | |
819 for (uint32_t index = 0; index < format_count; index++) { | |
820 if (supported_formats[index] == PP_PRINTOUTPUTFORMAT_PDF_0_3) { | |
821 // If we found PDF, we are done. | |
822 found_supported_format = true; | |
823 *format = PP_PRINTOUTPUTFORMAT_PDF_0_4; | |
824 break; | |
825 } else if (supported_formats[index] == | |
826 PP_PRINTOUTPUTFORMAT_RASTER_0_3) { | |
827 // We found raster. Keep looking. | |
828 found_supported_format = true; | |
829 *format = PP_PRINTOUTPUTFORMAT_RASTER_0_4; | |
830 } | |
831 } | |
832 PluginModule::GetMemoryDev()->MemFree(supported_formats); | |
833 return found_supported_format; | |
834 } | 790 } |
835 return false; | 791 return false; |
836 } | 792 } |
837 | 793 |
838 bool PluginInstance::SupportsPrintInterface() { | 794 bool PluginInstance::SupportsPrintInterface() { |
839 PP_PrintOutputFormat_Dev_0_4 format; | 795 PP_PrintOutputFormat_Dev format; |
840 return GetPreferredPrintOutputFormat(&format); | 796 return GetPreferredPrintOutputFormat(&format); |
841 } | 797 } |
842 | 798 |
843 int PluginInstance::PrintBegin(const gfx::Rect& printable_area, | 799 int PluginInstance::PrintBegin(const gfx::Rect& printable_area, |
844 int printer_dpi) { | 800 int printer_dpi) { |
845 // Keep a reference on the stack. See NOTE above. | 801 // Keep a reference on the stack. See NOTE above. |
846 scoped_refptr<PluginInstance> ref(this); | 802 scoped_refptr<PluginInstance> ref(this); |
847 PP_PrintOutputFormat_Dev_0_4 format; | 803 PP_PrintOutputFormat_Dev format; |
848 if (!GetPreferredPrintOutputFormat(&format)) { | 804 if (!GetPreferredPrintOutputFormat(&format)) { |
849 // PrintBegin should not have been called since SupportsPrintInterface | 805 // PrintBegin should not have been called since SupportsPrintInterface |
850 // would have returned false; | 806 // would have returned false; |
851 NOTREACHED(); | 807 NOTREACHED(); |
852 return 0; | 808 return 0; |
853 } | 809 } |
854 | 810 |
855 int num_pages = 0; | 811 int num_pages = 0; |
856 PP_PrintSettings_Dev_0_4 print_settings; | 812 PP_PrintSettings_Dev print_settings; |
857 RectToPPRect(printable_area, &print_settings.printable_area); | 813 RectToPPRect(printable_area, &print_settings.printable_area); |
858 print_settings.dpi = printer_dpi; | 814 print_settings.dpi = printer_dpi; |
859 print_settings.orientation = PP_PRINTORIENTATION_NORMAL; | 815 print_settings.orientation = PP_PRINTORIENTATION_NORMAL; |
860 print_settings.grayscale = PP_FALSE; | 816 print_settings.grayscale = PP_FALSE; |
861 print_settings.format = format; | 817 print_settings.format = format; |
862 if (plugin_print_interface_->Begin) { | 818 num_pages = plugin_print_interface_->Begin(pp_instance(), |
863 // If we have the most current version of Begin, use it. | 819 &print_settings); |
864 num_pages = plugin_print_interface_->Begin(pp_instance(), | |
865 &print_settings); | |
866 } else if (plugin_print_interface_->Begin_0_3) { | |
867 // Fall back to the 0.3 version of Begin if necessary, and convert the | |
868 // output format. | |
869 PP_PrintSettings_Dev_0_3 print_settings_0_3; | |
870 RectToPPRect(printable_area, &print_settings_0_3.printable_area); | |
871 print_settings_0_3.dpi = printer_dpi; | |
872 print_settings_0_3.orientation = PP_PRINTORIENTATION_NORMAL; | |
873 print_settings_0_3.grayscale = PP_FALSE; | |
874 switch (format) { | |
875 case PP_PRINTOUTPUTFORMAT_RASTER_0_4: | |
876 print_settings_0_3.format = PP_PRINTOUTPUTFORMAT_RASTER_0_3; | |
877 break; | |
878 case PP_PRINTOUTPUTFORMAT_PDF_0_4: | |
879 print_settings_0_3.format = PP_PRINTOUTPUTFORMAT_PDF_0_3; | |
880 break; | |
881 case PP_PRINTOUTPUTFORMAT_POSTSCRIPT_0_4: | |
882 print_settings_0_3.format = PP_PRINTOUTPUTFORMAT_POSTSCRIPT_0_3; | |
883 break; | |
884 default: | |
885 return 0; | |
886 } | |
887 num_pages = plugin_print_interface_->Begin_0_3(pp_instance(), | |
888 &print_settings_0_3); | |
889 } | |
890 if (!num_pages) | 820 if (!num_pages) |
891 return 0; | 821 return 0; |
892 current_print_settings_ = print_settings; | 822 current_print_settings_ = print_settings; |
893 #if defined(OS_LINUX) || defined(OS_WIN) | 823 #if defined(OS_LINUX) || defined(OS_WIN) |
894 canvas_ = NULL; | 824 canvas_ = NULL; |
895 ranges_.clear(); | 825 ranges_.clear(); |
896 #endif // OS_LINUX || OS_WIN | 826 #endif // OS_LINUX || OS_WIN |
897 return num_pages; | 827 return num_pages; |
898 } | 828 } |
899 | 829 |
900 bool PluginInstance::PrintPage(int page_number, WebKit::WebCanvas* canvas) { | 830 bool PluginInstance::PrintPage(int page_number, WebKit::WebCanvas* canvas) { |
901 DCHECK(plugin_print_interface_.get()); | 831 DCHECK(plugin_print_interface_); |
902 PP_PrintPageNumberRange_Dev page_range; | 832 PP_PrintPageNumberRange_Dev page_range; |
903 page_range.first_page_number = page_range.last_page_number = page_number; | 833 page_range.first_page_number = page_range.last_page_number = page_number; |
904 #if defined(OS_LINUX) || defined(OS_WIN) | 834 #if defined(OS_LINUX) || defined(OS_WIN) |
905 // The canvas only has a metafile on it for print preview. | 835 // The canvas only has a metafile on it for print preview. |
906 if (printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas)) { | 836 if (printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas)) { |
907 ranges_.push_back(page_range); | 837 ranges_.push_back(page_range); |
908 canvas_ = canvas; | 838 canvas_ = canvas; |
909 return true; | 839 return true; |
910 } else | 840 } else |
911 #endif // OS_LINUX || OS_WIN | 841 #endif // OS_LINUX || OS_WIN |
912 { | 842 { |
913 return PrintPageHelper(&page_range, 1, canvas); | 843 return PrintPageHelper(&page_range, 1, canvas); |
914 } | 844 } |
915 } | 845 } |
916 | 846 |
917 bool PluginInstance::PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges, | 847 bool PluginInstance::PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges, |
918 int num_ranges, | 848 int num_ranges, |
919 WebKit::WebCanvas* canvas) { | 849 WebKit::WebCanvas* canvas) { |
920 // Keep a reference on the stack. See NOTE above. | 850 // Keep a reference on the stack. See NOTE above. |
921 scoped_refptr<PluginInstance> ref(this); | 851 scoped_refptr<PluginInstance> ref(this); |
922 PP_Resource print_output = plugin_print_interface_->PrintPages( | 852 PP_Resource print_output = plugin_print_interface_->PrintPages( |
923 pp_instance(), page_ranges, num_ranges); | 853 pp_instance(), page_ranges, num_ranges); |
924 if (!print_output) | 854 if (!print_output) |
925 return false; | 855 return false; |
926 | 856 |
927 bool ret = false; | 857 bool ret = false; |
928 | 858 |
929 if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF_0_4) | 859 if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF) |
930 ret = PrintPDFOutput(print_output, canvas); | 860 ret = PrintPDFOutput(print_output, canvas); |
931 else if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_RASTER_0_4) | 861 else if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_RASTER) |
932 ret = PrintRasterOutput(print_output, canvas); | 862 ret = PrintRasterOutput(print_output, canvas); |
933 | 863 |
934 // Now we need to release the print output resource. | 864 // Now we need to release the print output resource. |
935 PluginModule::GetCore()->ReleaseResource(print_output); | 865 PluginModule::GetCore()->ReleaseResource(print_output); |
936 | 866 |
937 return ret; | 867 return ret; |
938 } | 868 } |
939 | 869 |
940 void PluginInstance::PrintEnd() { | 870 void PluginInstance::PrintEnd() { |
941 // Keep a reference on the stack. See NOTE above. | 871 // Keep a reference on the stack. See NOTE above. |
942 scoped_refptr<PluginInstance> ref(this); | 872 scoped_refptr<PluginInstance> ref(this); |
943 #if defined(OS_LINUX) || defined(OS_WIN) | 873 #if defined(OS_LINUX) || defined(OS_WIN) |
944 if (!ranges_.empty()) | 874 if (!ranges_.empty()) |
945 PrintPageHelper(&(ranges_.front()), ranges_.size(), canvas_.get()); | 875 PrintPageHelper(&(ranges_.front()), ranges_.size(), canvas_.get()); |
946 canvas_ = NULL; | 876 canvas_ = NULL; |
947 ranges_.clear(); | 877 ranges_.clear(); |
948 #endif // OS_LINUX || OS_WIN | 878 #endif // OS_LINUX || OS_WIN |
949 | 879 |
950 DCHECK(plugin_print_interface_.get()); | 880 DCHECK(plugin_print_interface_); |
951 if (plugin_print_interface_.get()) | 881 if (plugin_print_interface_) |
952 plugin_print_interface_->End(pp_instance()); | 882 plugin_print_interface_->End(pp_instance()); |
953 | 883 |
954 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 884 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
955 #if defined(OS_MACOSX) | 885 #if defined(OS_MACOSX) |
956 last_printed_page_ = NULL; | 886 last_printed_page_ = NULL; |
957 #endif // defined(OS_MACOSX) | 887 #endif // defined(OS_MACOSX) |
958 } | 888 } |
959 | 889 |
960 bool PluginInstance::IsFullscreenOrPending() { | 890 bool PluginInstance::IsFullscreenOrPending() { |
961 return fullscreen_container_ != NULL; | 891 return fullscreen_container_ != NULL; |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1551 } | 1481 } |
1552 | 1482 |
1553 void PluginInstance::DoSetCursor(WebCursorInfo* cursor) { | 1483 void PluginInstance::DoSetCursor(WebCursorInfo* cursor) { |
1554 cursor_.reset(cursor); | 1484 cursor_.reset(cursor); |
1555 if (fullscreen_container_) | 1485 if (fullscreen_container_) |
1556 fullscreen_container_->DidChangeCursor(*cursor); | 1486 fullscreen_container_->DidChangeCursor(*cursor); |
1557 } | 1487 } |
1558 | 1488 |
1559 } // namespace ppapi | 1489 } // namespace ppapi |
1560 } // namespace webkit | 1490 } // namespace webkit |
OLD | NEW |