| 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 gfx::Size original_size; | 196 gfx::Size original_size; |
| 197 if (!context_node.IsNull() && context_node.IsElementNode()) { | 197 if (!context_node.IsNull() && context_node.IsElementNode()) { |
| 198 blink::WebImage image = context_node.To<WebElement>().ImageContents(); | 198 blink::WebImage image = context_node.To<WebElement>().ImageContents(); |
| 199 original_size = image.Size(); | 199 original_size = image.Size(); |
| 200 thumbnail = Downscale(image, | 200 thumbnail = Downscale(image, |
| 201 thumbnail_min_area_pixels, | 201 thumbnail_min_area_pixels, |
| 202 thumbnail_max_size_pixels); | 202 thumbnail_max_size_pixels); |
| 203 } | 203 } |
| 204 | 204 |
| 205 SkBitmap bitmap; | 205 SkBitmap bitmap; |
| 206 if (thumbnail.colorType() == kN32_SkColorType) | 206 if (thumbnail.colorType() == kN32_SkColorType) { |
| 207 bitmap = thumbnail; | 207 bitmap = thumbnail; |
| 208 else | 208 } else { |
| 209 thumbnail.copyTo(&bitmap, kN32_SkColorType); | 209 SkImageInfo info = thumbnail.info().makeColorType(kN32_SkColorType); |
| 210 if (bitmap.tryAllocPixels(info)) { |
| 211 thumbnail.readPixels(info, bitmap.getPixels(), bitmap.rowBytes(), 0, 0); |
| 212 } |
| 213 } |
| 210 | 214 |
| 211 std::vector<uint8_t> thumbnail_data; | 215 std::vector<uint8_t> thumbnail_data; |
| 212 if (bitmap.getPixels()) { | 216 if (bitmap.getPixels()) { |
| 213 const int kDefaultQuality = 90; | 217 const int kDefaultQuality = 90; |
| 214 std::vector<unsigned char> data; | 218 std::vector<unsigned char> data; |
| 215 if (gfx::JPEGCodec::Encode( | 219 if (gfx::JPEGCodec::Encode( |
| 216 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), | 220 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), |
| 217 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(), | 221 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(), |
| 218 static_cast<int>(bitmap.rowBytes()), kDefaultQuality, &data)) { | 222 static_cast<int>(bitmap.rowBytes()), kDefaultQuality, &data)) { |
| 219 thumbnail_data.swap(data); | 223 thumbnail_data.swap(data); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 363 |
| 360 void ChromeRenderFrameObserver::OnImageContextMenuRendererRequest( | 364 void ChromeRenderFrameObserver::OnImageContextMenuRendererRequest( |
| 361 chrome::mojom::ImageContextMenuRendererRequest request) { | 365 chrome::mojom::ImageContextMenuRendererRequest request) { |
| 362 image_context_menu_renderer_bindings_.AddBinding(this, std::move(request)); | 366 image_context_menu_renderer_bindings_.AddBinding(this, std::move(request)); |
| 363 } | 367 } |
| 364 | 368 |
| 365 void ChromeRenderFrameObserver::OnThumbnailCapturerRequest( | 369 void ChromeRenderFrameObserver::OnThumbnailCapturerRequest( |
| 366 chrome::mojom::ThumbnailCapturerRequest request) { | 370 chrome::mojom::ThumbnailCapturerRequest request) { |
| 367 thumbnail_capturer_bindings_.AddBinding(this, std::move(request)); | 371 thumbnail_capturer_bindings_.AddBinding(this, std::move(request)); |
| 368 } | 372 } |
| OLD | NEW |