OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/renderer/chrome_render_frame_observer.h" | 5 #include "chrome/renderer/chrome_render_frame_observer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 if (thumbnail.colorType() == kN32_SkColorType) { | 206 if (thumbnail.colorType() == kN32_SkColorType) { |
207 bitmap = thumbnail; | 207 bitmap = thumbnail; |
208 } else { | 208 } else { |
209 SkImageInfo info = thumbnail.info().makeColorType(kN32_SkColorType); | 209 SkImageInfo info = thumbnail.info().makeColorType(kN32_SkColorType); |
210 if (bitmap.tryAllocPixels(info)) { | 210 if (bitmap.tryAllocPixels(info)) { |
211 thumbnail.readPixels(info, bitmap.getPixels(), bitmap.rowBytes(), 0, 0); | 211 thumbnail.readPixels(info, bitmap.getPixels(), bitmap.rowBytes(), 0, 0); |
212 } | 212 } |
213 } | 213 } |
214 | 214 |
215 std::vector<uint8_t> thumbnail_data; | 215 std::vector<uint8_t> thumbnail_data; |
216 if (bitmap.getPixels()) { | 216 constexpr int kDefaultQuality = 90; |
217 const int kDefaultQuality = 90; | 217 std::vector<unsigned char> data; |
218 std::vector<unsigned char> data; | 218 if (gfx::JPEGCodec::Encode(bitmap, kDefaultQuality, &data)) { |
219 if (gfx::JPEGCodec::Encode( | 219 thumbnail_data.swap(data); |
220 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), | |
221 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(), | |
222 static_cast<int>(bitmap.rowBytes()), kDefaultQuality, &data)) { | |
223 thumbnail_data.swap(data); | |
224 } | |
225 } | 220 } |
226 | 221 |
227 callback.Run(thumbnail_data, original_size); | 222 callback.Run(thumbnail_data, original_size); |
228 } | 223 } |
229 | 224 |
230 void ChromeRenderFrameObserver::OnPrintNodeUnderContextMenu() { | 225 void ChromeRenderFrameObserver::OnPrintNodeUnderContextMenu() { |
231 #if BUILDFLAG(ENABLE_PRINTING) | 226 #if BUILDFLAG(ENABLE_PRINTING) |
232 printing::PrintWebViewHelper* helper = | 227 printing::PrintWebViewHelper* helper = |
233 printing::PrintWebViewHelper::Get(render_frame()); | 228 printing::PrintWebViewHelper::Get(render_frame()); |
234 if (helper) | 229 if (helper) |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 const service_manager::BindSourceInfo& source_info, | 360 const service_manager::BindSourceInfo& source_info, |
366 chrome::mojom::ImageContextMenuRendererRequest request) { | 361 chrome::mojom::ImageContextMenuRendererRequest request) { |
367 image_context_menu_renderer_bindings_.AddBinding(this, std::move(request)); | 362 image_context_menu_renderer_bindings_.AddBinding(this, std::move(request)); |
368 } | 363 } |
369 | 364 |
370 void ChromeRenderFrameObserver::OnThumbnailCapturerRequest( | 365 void ChromeRenderFrameObserver::OnThumbnailCapturerRequest( |
371 const service_manager::BindSourceInfo& source_info, | 366 const service_manager::BindSourceInfo& source_info, |
372 chrome::mojom::ThumbnailCapturerRequest request) { | 367 chrome::mojom::ThumbnailCapturerRequest request) { |
373 thumbnail_capturer_bindings_.AddBinding(this, std::move(request)); | 368 thumbnail_capturer_bindings_.AddBinding(this, std::move(request)); |
374 } | 369 } |
OLD | NEW |