Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: content/renderer/pepper/pepper_plugin_instance_impl.cc

Issue 599633007: Fixed build enable_printing=2 for windows and removed dead code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Thu Sep 25 22:28:15 PDT 2014 Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/renderer/pepper/pepper_plugin_instance_impl.h" 5 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 #include "ppapi/shared_impl/resource.h" 87 #include "ppapi/shared_impl/resource.h"
88 #include "ppapi/shared_impl/scoped_pp_resource.h" 88 #include "ppapi/shared_impl/scoped_pp_resource.h"
89 #include "ppapi/shared_impl/scoped_pp_var.h" 89 #include "ppapi/shared_impl/scoped_pp_var.h"
90 #include "ppapi/shared_impl/time_conversion.h" 90 #include "ppapi/shared_impl/time_conversion.h"
91 #include "ppapi/shared_impl/url_request_info_data.h" 91 #include "ppapi/shared_impl/url_request_info_data.h"
92 #include "ppapi/shared_impl/var.h" 92 #include "ppapi/shared_impl/var.h"
93 #include "ppapi/thunk/enter.h" 93 #include "ppapi/thunk/enter.h"
94 #include "ppapi/thunk/ppb_buffer_api.h" 94 #include "ppapi/thunk/ppb_buffer_api.h"
95 #include "printing/metafile_skia_wrapper.h" 95 #include "printing/metafile_skia_wrapper.h"
96 #include "printing/pdf_metafile_skia.h" 96 #include "printing/pdf_metafile_skia.h"
97 #include "printing/units.h"
98 #include "skia/ext/platform_canvas.h" 97 #include "skia/ext/platform_canvas.h"
99 #include "skia/ext/platform_device.h"
100 #include "third_party/WebKit/public/platform/WebCursorInfo.h" 98 #include "third_party/WebKit/public/platform/WebCursorInfo.h"
101 #include "third_party/WebKit/public/platform/WebGamepads.h" 99 #include "third_party/WebKit/public/platform/WebGamepads.h"
102 #include "third_party/WebKit/public/platform/WebRect.h" 100 #include "third_party/WebKit/public/platform/WebRect.h"
103 #include "third_party/WebKit/public/platform/WebString.h" 101 #include "third_party/WebKit/public/platform/WebString.h"
104 #include "third_party/WebKit/public/platform/WebURL.h" 102 #include "third_party/WebKit/public/platform/WebURL.h"
105 #include "third_party/WebKit/public/platform/WebURLError.h" 103 #include "third_party/WebKit/public/platform/WebURLError.h"
106 #include "third_party/WebKit/public/platform/WebURLRequest.h" 104 #include "third_party/WebKit/public/platform/WebURLRequest.h"
107 #include "third_party/WebKit/public/web/WebBindings.h" 105 #include "third_party/WebKit/public/web/WebBindings.h"
108 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" 106 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
109 #include "third_party/WebKit/public/web/WebDataSource.h" 107 #include "third_party/WebKit/public/web/WebDataSource.h"
110 #include "third_party/WebKit/public/web/WebDocument.h" 108 #include "third_party/WebKit/public/web/WebDocument.h"
111 #include "third_party/WebKit/public/web/WebElement.h" 109 #include "third_party/WebKit/public/web/WebElement.h"
112 #include "third_party/WebKit/public/web/WebInputEvent.h" 110 #include "third_party/WebKit/public/web/WebInputEvent.h"
113 #include "third_party/WebKit/public/web/WebLocalFrame.h" 111 #include "third_party/WebKit/public/web/WebLocalFrame.h"
114 #include "third_party/WebKit/public/web/WebPluginContainer.h" 112 #include "third_party/WebKit/public/web/WebPluginContainer.h"
115 #include "third_party/WebKit/public/web/WebPrintParams.h" 113 #include "third_party/WebKit/public/web/WebPrintParams.h"
116 #include "third_party/WebKit/public/web/WebPrintScalingOption.h" 114 #include "third_party/WebKit/public/web/WebPrintScalingOption.h"
117 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" 115 #include "third_party/WebKit/public/web/WebScopedUserGesture.h"
118 #include "third_party/WebKit/public/web/WebScriptSource.h" 116 #include "third_party/WebKit/public/web/WebScriptSource.h"
119 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 117 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
120 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" 118 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
121 #include "third_party/WebKit/public/web/WebView.h" 119 #include "third_party/WebKit/public/web/WebView.h"
122 #include "third_party/khronos/GLES2/gl2.h" 120 #include "third_party/khronos/GLES2/gl2.h"
123 #include "third_party/skia/include/core/SkCanvas.h"
124 #include "third_party/skia/include/core/SkRect.h"
125 #include "ui/gfx/image/image_skia.h" 121 #include "ui/gfx/image/image_skia.h"
126 #include "ui/gfx/image/image_skia_rep.h" 122 #include "ui/gfx/image/image_skia_rep.h"
127 #include "ui/gfx/range/range.h" 123 #include "ui/gfx/range/range.h"
128 #include "ui/gfx/rect_conversions.h"
129 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
130 #include "v8/include/v8.h" 124 #include "v8/include/v8.h"
131 125
132 #if defined(OS_CHROMEOS) 126 #if defined(OS_CHROMEOS)
133 #include "ui/events/keycodes/keyboard_codes_posix.h" 127 #include "ui/events/keycodes/keyboard_codes_posix.h"
134 #endif 128 #endif
135 129
136 #if defined(OS_WIN) 130 #if defined(OS_WIN)
137 #include "base/metrics/histogram.h" 131 #include "base/metrics/histogram.h"
138 #include "base/win/windows_version.h" 132 #include "base/win/windows_version.h"
139 #include "skia/ext/platform_canvas.h" 133 #include "skia/ext/platform_canvas.h"
140 #include "ui/gfx/codec/jpeg_codec.h"
141 #include "ui/gfx/gdi_util.h"
142 #endif 134 #endif
143 135
144 using base::StringPrintf; 136 using base::StringPrintf;
145 using ppapi::InputEventData; 137 using ppapi::InputEventData;
146 using ppapi::PpapiGlobals; 138 using ppapi::PpapiGlobals;
147 using ppapi::PPB_InputEvent_Shared; 139 using ppapi::PPB_InputEvent_Shared;
148 using ppapi::PPB_View_Shared; 140 using ppapi::PPB_View_Shared;
149 using ppapi::PPP_Instance_Combined; 141 using ppapi::PPP_Instance_Combined;
150 using ppapi::Resource; 142 using ppapi::Resource;
151 using ppapi::ScopedPPResource; 143 using ppapi::ScopedPPResource;
(...skipping 27 matching lines...) Expand all
179 using blink::WebURLLoader; 171 using blink::WebURLLoader;
180 using blink::WebURLLoaderClient; 172 using blink::WebURLLoaderClient;
181 using blink::WebURLRequest; 173 using blink::WebURLRequest;
182 using blink::WebURLResponse; 174 using blink::WebURLResponse;
183 using blink::WebUserGestureIndicator; 175 using blink::WebUserGestureIndicator;
184 using blink::WebUserGestureToken; 176 using blink::WebUserGestureToken;
185 using blink::WebView; 177 using blink::WebView;
186 178
187 namespace content { 179 namespace content {
188 180
189 #if defined(OS_WIN)
190 // Exported by pdf.dll
191 typedef bool (*RenderPDFPageToDCProc)(const unsigned char* pdf_buffer,
192 int buffer_size,
193 int page_number,
194 HDC dc,
195 int dpi_x,
196 int dpi_y,
197 int bounds_origin_x,
198 int bounds_origin_y,
199 int bounds_width,
200 int bounds_height,
201 bool fit_to_bounds,
202 bool stretch_to_bounds,
203 bool keep_aspect_ratio,
204 bool center_in_bounds,
205 bool autorotate);
206
207 void DrawEmptyRectangle(HDC dc) {
208 // TODO(sanjeevr): This is a temporary hack. If we output a JPEG
209 // to the EMF, the EnumEnhMetaFile call fails in the browser
210 // process. The failure also happens if we output nothing here.
211 // We need to investigate the reason for this failure and fix it.
212 // In the meantime this temporary hack of drawing an empty
213 // rectangle in the DC gets us by.
214 Rectangle(dc, 0, 0, 0, 0);
215 }
216 #endif // defined(OS_WIN)
217
218 namespace { 181 namespace {
219 182
220 // Check PP_TextInput_Type and ui::TextInputType are kept in sync. 183 // Check PP_TextInput_Type and ui::TextInputType are kept in sync.
221 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_NONE) == int(PP_TEXTINPUT_TYPE_NONE), 184 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_NONE) == int(PP_TEXTINPUT_TYPE_NONE),
222 mismatching_enums); 185 mismatching_enums);
223 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_TEXT) == int(PP_TEXTINPUT_TYPE_TEXT), 186 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_TEXT) == int(PP_TEXTINPUT_TYPE_TEXT),
224 mismatching_enums); 187 mismatching_enums);
225 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_PASSWORD) == 188 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_PASSWORD) ==
226 int(PP_TEXTINPUT_TYPE_PASSWORD), 189 int(PP_TEXTINPUT_TYPE_PASSWORD),
227 mismatching_enums); 190 mismatching_enums);
(...skipping 1547 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 if (!num_pages) 1738 if (!num_pages)
1776 return 0; 1739 return 0;
1777 current_print_settings_ = print_settings; 1740 current_print_settings_ = print_settings;
1778 canvas_.clear(); 1741 canvas_.clear();
1779 ranges_.clear(); 1742 ranges_.clear();
1780 return num_pages; 1743 return num_pages;
1781 } 1744 }
1782 1745
1783 bool PepperPluginInstanceImpl::PrintPage(int page_number, 1746 bool PepperPluginInstanceImpl::PrintPage(int page_number,
1784 blink::WebCanvas* canvas) { 1747 blink::WebCanvas* canvas) {
1785 #if defined(ENABLE_FULL_PRINTING) 1748 #if defined(ENABLE_PRINTING)
1786 DCHECK(plugin_print_interface_); 1749 DCHECK(plugin_print_interface_);
1787 PP_PrintPageNumberRange_Dev page_range; 1750 PP_PrintPageNumberRange_Dev page_range;
1788 page_range.first_page_number = page_range.last_page_number = page_number; 1751 page_range.first_page_number = page_range.last_page_number = page_number;
1789 // The canvas only has a metafile on it for print preview. 1752 // The canvas only has a metafile on it for print preview.
1790 bool save_for_later = 1753 bool save_for_later =
1791 (printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas) != NULL); 1754 (printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas) != NULL);
1792 #if defined(OS_MACOSX) 1755 #if defined(OS_MACOSX)
1793 save_for_later = save_for_later && skia::IsPreviewMetafile(*canvas); 1756 save_for_later = save_for_later && skia::IsPreviewMetafile(*canvas);
1794 #endif // defined(OS_MACOSX) 1757 #endif // defined(OS_MACOSX)
1795 if (save_for_later) { 1758 if (save_for_later) {
1796 ranges_.push_back(page_range); 1759 ranges_.push_back(page_range);
1797 canvas_ = skia::SharePtr(canvas); 1760 canvas_ = skia::SharePtr(canvas);
1798 return true; 1761 return true;
1799 } else { 1762 } else {
1800 return PrintPageHelper(&page_range, 1, canvas); 1763 return PrintPageHelper(&page_range, 1, canvas);
1801 } 1764 }
1802 #else // defined(ENABLED_PRINTING) 1765 #else // ENABLE_PRINTING
1803 return false; 1766 return false;
1804 #endif 1767 #endif
1805 } 1768 }
1806 1769
1807 bool PepperPluginInstanceImpl::PrintPageHelper( 1770 bool PepperPluginInstanceImpl::PrintPageHelper(
1808 PP_PrintPageNumberRange_Dev* page_ranges, 1771 PP_PrintPageNumberRange_Dev* page_ranges,
1809 int num_ranges, 1772 int num_ranges,
1810 blink::WebCanvas* canvas) { 1773 blink::WebCanvas* canvas) {
1811 // Keep a reference on the stack. See NOTE above. 1774 // Keep a reference on the stack. See NOTE above.
1812 scoped_refptr<PepperPluginInstanceImpl> ref(this); 1775 scoped_refptr<PepperPluginInstanceImpl> ref(this);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1959 return false; 1922 return false;
1960 WebView* view = frame->view(); 1923 WebView* view = frame->view();
1961 if (!view) 1924 if (!view)
1962 return false; 1925 return false;
1963 1926
1964 return view->isAcceleratedCompositingActive(); 1927 return view->isAcceleratedCompositingActive();
1965 } 1928 }
1966 1929
1967 bool PepperPluginInstanceImpl::PrintPDFOutput(PP_Resource print_output, 1930 bool PepperPluginInstanceImpl::PrintPDFOutput(PP_Resource print_output,
1968 blink::WebCanvas* canvas) { 1931 blink::WebCanvas* canvas) {
1969 #if defined(ENABLE_FULL_PRINTING) 1932 #if defined(ENABLE_PRINTING)
1970 ppapi::thunk::EnterResourceNoLock<PPB_Buffer_API> enter(print_output, true); 1933 ppapi::thunk::EnterResourceNoLock<PPB_Buffer_API> enter(print_output, true);
1971 if (enter.failed()) 1934 if (enter.failed())
1972 return false; 1935 return false;
1973 1936
1974 BufferAutoMapper mapper(enter.object()); 1937 BufferAutoMapper mapper(enter.object());
1975 if (!mapper.data() || !mapper.size()) { 1938 if (!mapper.data() || !mapper.size()) {
1976 NOTREACHED(); 1939 NOTREACHED();
1977 return false; 1940 return false;
1978 } 1941 }
1979 #if defined(OS_WIN)
1980 // For Windows, we need the PDF DLL to render the output PDF to a DC.
1981 HMODULE pdf_module = GetModuleHandle(L"pdf.dll");
1982 if (!pdf_module)
1983 return false;
1984 RenderPDFPageToDCProc render_proc = reinterpret_cast<RenderPDFPageToDCProc>(
1985 GetProcAddress(pdf_module, "RenderPDFPageToDC"));
1986 if (!render_proc)
1987 return false;
1988 #endif // defined(OS_WIN)
1989 1942
1990 bool ret = false;
1991 #if defined(OS_POSIX) && !defined(OS_ANDROID)
1992 printing::PdfMetafileSkia* metafile = 1943 printing::PdfMetafileSkia* metafile =
1993 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas); 1944 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas);
1994 DCHECK(metafile != NULL);
1995 if (metafile) 1945 if (metafile)
1996 ret = metafile->InitFromData(mapper.data(), mapper.size()); 1946 return metafile->InitFromData(mapper.data(), mapper.size());
1997 #elif defined(OS_WIN)
1998 printing::PdfMetafileSkia* metafile =
1999 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas);
2000 if (metafile) {
2001 // We only have a metafile when doing print preview, so we just want to
2002 // pass the PDF off to preview.
2003 ret = metafile->InitFromData(mapper.data(), mapper.size());
2004 } else {
2005 // On Windows, we now need to render the PDF to the DC that backs the
2006 // supplied canvas.
2007 HDC dc = skia::BeginPlatformPaint(canvas);
2008 DrawEmptyRectangle(dc);
2009 gfx::Size size_in_pixels;
2010 size_in_pixels.set_width(
2011 printing::ConvertUnit(current_print_settings_.printable_area.size.width,
2012 static_cast<int>(printing::kPointsPerInch),
2013 current_print_settings_.dpi));
2014 size_in_pixels.set_height(printing::ConvertUnit(
2015 current_print_settings_.printable_area.size.height,
2016 static_cast<int>(printing::kPointsPerInch),
2017 current_print_settings_.dpi));
2018 // We need to scale down DC to fit an entire page into DC available area.
2019 // First, we'll try to use default scaling based on the 72dpi that is
2020 // used in webkit for printing.
2021 // If default scaling is not enough to fit the entire PDF without
2022 // Current metafile is based on screen DC and have current screen size.
2023 // Writing outside of those boundaries will result in the cut-off output.
2024 // On metafiles (this is the case here), scaling down will still record
2025 // original coordinates and we'll be able to print in full resolution.
2026 // Before playback we'll need to counter the scaling up that will happen
2027 // in the browser (printed_document_win.cc).
2028 double dynamic_scale = gfx::CalculatePageScale(
2029 dc, size_in_pixels.width(), size_in_pixels.height());
2030 double page_scale = static_cast<double>(printing::kPointsPerInch) /
2031 static_cast<double>(current_print_settings_.dpi);
2032 1947
2033 if (dynamic_scale < page_scale) { 1948 NOTREACHED();
2034 page_scale = dynamic_scale; 1949 #endif // ENABLE_PRINTING
2035 printing::MetafileSkiaWrapper::SetCustomScaleOnCanvas(*canvas,
2036 page_scale);
2037 }
2038
2039 gfx::ScaleDC(dc, page_scale);
2040
2041 ret = render_proc(static_cast<unsigned char*>(mapper.data()),
2042 mapper.size(),
2043 0,
2044 dc,
2045 current_print_settings_.dpi,
2046 current_print_settings_.dpi,
2047 0,
2048 0,
2049 size_in_pixels.width(),
2050 size_in_pixels.height(),
2051 true,
2052 false,
2053 true,
2054 true,
2055 true);
2056 skia::EndPlatformPaint(canvas);
2057 }
2058 #endif // defined(OS_WIN)
2059
2060 return ret;
2061 #else // defined(ENABLE_FULL_PRINTING)
2062 return false; 1950 return false;
2063 #endif
2064 } 1951 }
2065 1952
2066 void PepperPluginInstanceImpl::UpdateLayer(bool device_changed) { 1953 void PepperPluginInstanceImpl::UpdateLayer(bool device_changed) {
2067 if (!container_) 1954 if (!container_)
2068 return; 1955 return;
2069 1956
2070 gpu::Mailbox mailbox; 1957 gpu::Mailbox mailbox;
2071 uint32 sync_point = 0; 1958 uint32 sync_point = 0;
2072 if (bound_graphics_3d_.get()) { 1959 if (bound_graphics_3d_.get()) {
2073 bound_graphics_3d_->GetBackingMailbox(&mailbox, &sync_point); 1960 bound_graphics_3d_->GetBackingMailbox(&mailbox, &sync_point);
(...skipping 1309 matching lines...) Expand 10 before | Expand all | Expand 10 after
3383 // Running out-of-process. Initiate an IPC call to notify the plugin 3270 // Running out-of-process. Initiate an IPC call to notify the plugin
3384 // process. 3271 // process.
3385 ppapi::proxy::HostDispatcher* dispatcher = 3272 ppapi::proxy::HostDispatcher* dispatcher =
3386 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); 3273 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance());
3387 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( 3274 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad(
3388 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); 3275 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data));
3389 } 3276 }
3390 } 3277 }
3391 3278
3392 } // namespace content 3279 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698