Chromium Code Reviews| 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 08ca11e128025445d355c026ae12b3265e4af132..2876c3fdaffffccd88d31f2b4efefa3b9720331f 100644 |
| --- a/chrome/renderer/chrome_render_frame_observer.cc |
| +++ b/chrome/renderer/chrome_render_frame_observer.cc |
| @@ -43,6 +43,7 @@ |
| #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| #include "third_party/skia/include/core/SkBitmap.h" |
| #include "ui/gfx/codec/jpeg_codec.h" |
| +#include "ui/gfx/codec/png_codec.h" |
| #include "ui/gfx/geometry/size_f.h" |
| #include "url/gurl.h" |
| @@ -70,6 +71,10 @@ static const char kTranslateCaptureText[] = "Translate.CaptureText"; |
| // the refresh delay is less than this value (in seconds). |
| static const double kLocationChangeIntervalInSeconds = 10; |
| +// For the context menu, we want to keep transparency as is instead of |
| +// replacing transparent pixels with black ones |
| +static const bool kDiscardTransparencyForContextMenu = false; |
|
msarett1
2017/06/21 04:18:15
I'm glad this is false.
"true" is fairly awkward
Daniel Park
2017/06/22 01:11:35
I'm a little unsure of how to proceed with regards
|
| + |
| namespace { |
| // If the source image is null or occupies less area than |
| @@ -190,6 +195,7 @@ void ChromeRenderFrameObserver::RequestReloadImageForContextNode() { |
| void ChromeRenderFrameObserver::RequestThumbnailForContextNode( |
| int32_t thumbnail_min_area_pixels, |
| const gfx::Size& thumbnail_max_size_pixels, |
| + bool use_png_codec, |
| const RequestThumbnailForContextNodeCallback& callback) { |
| WebNode context_node = render_frame()->GetWebFrame()->ContextMenuNode(); |
| SkBitmap thumbnail; |
| @@ -215,8 +221,16 @@ void ChromeRenderFrameObserver::RequestThumbnailForContextNode( |
| std::vector<uint8_t> thumbnail_data; |
| constexpr int kDefaultQuality = 90; |
| std::vector<unsigned char> data; |
| - if (gfx::JPEGCodec::Encode(bitmap, kDefaultQuality, &data)) { |
| - thumbnail_data.swap(data); |
| + |
| + if (use_png_codec) { |
| + if (gfx::PNGCodec::EncodeBGRASkBitmap( |
| + bitmap, kDiscardTransparencyForContextMenu, &data)) { |
| + thumbnail_data.swap(data); |
| + } |
| + } else { |
| + if (gfx::JPEGCodec::Encode(bitmap, kDefaultQuality, &data)) { |
| + thumbnail_data.swap(data); |
| + } |
| } |
| callback.Run(thumbnail_data, original_size); |