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 7b13a729d2054f82d74661c2571f1bcb84d10db1..5a880c0e97853993658b8df9c0892e2f6d7cbc46 100644 |
--- a/chrome/renderer/chrome_render_frame_observer.cc |
+++ b/chrome/renderer/chrome_render_frame_observer.cc |
@@ -45,6 +45,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" |
@@ -72,6 +73,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; |
+ |
namespace { |
// If the source image is null or occupies less area than |
@@ -194,6 +199,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; |
@@ -219,8 +225,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); |