| 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 SkPixmap pixmap; |
| 217 if (bitmap.peekPixels(&pixmap)) { |
| 217 const int kDefaultQuality = 90; | 218 const int kDefaultQuality = 90; |
| 218 std::vector<unsigned char> data; | 219 std::vector<unsigned char> data; |
| 219 if (gfx::JPEGCodec::Encode( | 220 if (gfx::JPEGCodec::Encode(pixmap, kDefaultQuality, &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); | 221 thumbnail_data.swap(data); |
| 224 } | 222 } |
| 225 } | 223 } |
| 226 | 224 |
| 227 callback.Run(thumbnail_data, original_size); | 225 callback.Run(thumbnail_data, original_size); |
| 228 } | 226 } |
| 229 | 227 |
| 230 void ChromeRenderFrameObserver::OnPrintNodeUnderContextMenu() { | 228 void ChromeRenderFrameObserver::OnPrintNodeUnderContextMenu() { |
| 231 #if BUILDFLAG(ENABLE_PRINTING) | 229 #if BUILDFLAG(ENABLE_PRINTING) |
| 232 printing::PrintWebViewHelper* helper = | 230 printing::PrintWebViewHelper* helper = |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 const service_manager::BindSourceInfo& source_info, | 363 const service_manager::BindSourceInfo& source_info, |
| 366 chrome::mojom::ImageContextMenuRendererRequest request) { | 364 chrome::mojom::ImageContextMenuRendererRequest request) { |
| 367 image_context_menu_renderer_bindings_.AddBinding(this, std::move(request)); | 365 image_context_menu_renderer_bindings_.AddBinding(this, std::move(request)); |
| 368 } | 366 } |
| 369 | 367 |
| 370 void ChromeRenderFrameObserver::OnThumbnailCapturerRequest( | 368 void ChromeRenderFrameObserver::OnThumbnailCapturerRequest( |
| 371 const service_manager::BindSourceInfo& source_info, | 369 const service_manager::BindSourceInfo& source_info, |
| 372 chrome::mojom::ThumbnailCapturerRequest request) { | 370 chrome::mojom::ThumbnailCapturerRequest request) { |
| 373 thumbnail_capturer_bindings_.AddBinding(this, std::move(request)); | 371 thumbnail_capturer_bindings_.AddBinding(this, std::move(request)); |
| 374 } | 372 } |
| OLD | NEW |