Index: chrome/renderer/chrome_render_frame_observer.cc |
diff --git a/chrome/renderer/chrome_render_frame_observer.cc b/chrome/renderer/chrome_render_frame_observer.cc |
index 2a9b594a734e40d6cf846592e82fbc400598e211..e49103aec6e1716551afba331e369cf28d767b6d 100644 |
--- a/chrome/renderer/chrome_render_frame_observer.cc |
+++ b/chrome/renderer/chrome_render_frame_observer.cc |
@@ -4,6 +4,10 @@ |
#include "chrome/renderer/chrome_render_frame_observer.h" |
+#include <limits> |
+#include <string> |
+#include <vector> |
+ |
#include "base/strings/utf_string_conversions.h" |
#include "chrome/common/prerender_messages.h" |
#include "chrome/common/print_messages.h" |
@@ -12,10 +16,11 @@ |
#include "chrome/renderer/printing/print_web_view_helper.h" |
#include "content/public/renderer/render_frame.h" |
#include "skia/ext/image_operations.h" |
-#include "skia/ext/platform_canvas.h" |
#include "third_party/WebKit/public/platform/WebImage.h" |
#include "third_party/WebKit/public/web/WebElement.h" |
#include "third_party/WebKit/public/web/WebNode.h" |
+#include "third_party/skia/include/core/SkBitmap.h" |
+#include "ui/gfx/codec/jpeg_codec.h" |
using blink::WebElement; |
using blink::WebNode; |
@@ -117,8 +122,31 @@ void ChromeRenderFrameObserver::OnRequestThumbnailForContextNode( |
thumbnail_min_area_pixels, |
thumbnail_max_size_pixels); |
} |
+ |
+ SkBitmap bitmap; |
+ if (thumbnail.colorType() == kN32_SkColorType) { |
Peter Kasting
2014/12/11 20:11:30
Nit: {} unnecessary
jbroman
2014/12/12 00:08:57
Done.
|
+ bitmap = thumbnail; |
+ } else { |
+ thumbnail.copyTo(&bitmap, kN32_SkColorType); |
+ } |
+ |
+ std::string thumbnail_data; |
+ { |
+ SkAutoLockPixels lock(bitmap); |
Peter Kasting
2014/12/11 20:11:30
Is it important that this lock be released before
jbroman
2014/12/12 00:08:57
It's not important, no. There was just no reason f
|
+ if (bitmap.getPixels() != nullptr && |
Peter Kasting
2014/12/11 20:11:30
Nit: "!= nullptr" unnecessary
jbroman
2014/12/12 00:08:57
Done.
I had some vague idea that Chromium style p
|
+ static_cast<int>(bitmap.rowBytes()) > 0) { |
Peter Kasting
2014/12/11 20:11:30
Why is this cast to int necessary?
jbroman
2014/12/12 00:08:57
The rowBytes argument to gfx::JPEGCodec::Encode is
Peter Kasting
2014/12/12 00:35:51
I see. You need some kind of cast here, then. Th
jbroman
2014/12/12 01:10:46
If this were to be negative after a cast, it would
|
+ const int kDefaultQuality = 90; |
+ std::vector<unsigned char> data; |
+ if (gfx::JPEGCodec::Encode( |
+ reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), |
+ gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(), |
+ static_cast<int>(bitmap.rowBytes()), kDefaultQuality, &data)) |
+ thumbnail_data = std::string(data.begin(), data.end()); |
+ } |
+ } |
+ |
Send(new ChromeViewHostMsg_RequestThumbnailForContextNode_ACK( |
- routing_id(), thumbnail, original_size)); |
+ routing_id(), thumbnail_data, original_size)); |
} |
void ChromeRenderFrameObserver::OnPrintNodeUnderContextMenu() { |