Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Side by Side Diff: extensions/browser/api/web_contents_capture_client.cc

Issue 1863953002: <webview>: Fix missing transparency in captureVisibleRegion(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix build break Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/browser/api/web_contents_capture_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "extensions/browser/api/web_contents_capture_client.h" 5 #include "extensions/browser/api/web_contents_capture_client.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "content/public/browser/render_widget_host.h" 9 #include "content/public/browser/render_widget_host.h"
10 #include "content/public/browser/render_widget_host_view.h" 10 #include "content/public/browser/render_widget_host_view.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 100 }
101 OnCaptureFailure(FAILURE_REASON_UNKNOWN); 101 OnCaptureFailure(FAILURE_REASON_UNKNOWN);
102 } 102 }
103 103
104 // TODO(wjmaclean) can this be static? 104 // TODO(wjmaclean) can this be static?
105 bool WebContentsCaptureClient::EncodeBitmap(const SkBitmap& bitmap, 105 bool WebContentsCaptureClient::EncodeBitmap(const SkBitmap& bitmap,
106 std::string* base64_result) { 106 std::string* base64_result) {
107 DCHECK(base64_result); 107 DCHECK(base64_result);
108 std::vector<unsigned char> data; 108 std::vector<unsigned char> data;
109 SkAutoLockPixels screen_capture_lock(bitmap); 109 SkAutoLockPixels screen_capture_lock(bitmap);
110 const bool should_discard_alpha = !ClientAllowsTransparency();
110 bool encoded = false; 111 bool encoded = false;
111 std::string mime_type; 112 std::string mime_type;
112 switch (image_format_) { 113 switch (image_format_) {
113 case api::extension_types::IMAGE_FORMAT_JPEG: 114 case api::extension_types::IMAGE_FORMAT_JPEG:
114 encoded = gfx::JPEGCodec::Encode( 115 encoded = gfx::JPEGCodec::Encode(
115 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), 116 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)),
116 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(), 117 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(),
117 static_cast<int>(bitmap.rowBytes()), image_quality_, &data); 118 static_cast<int>(bitmap.rowBytes()), image_quality_, &data);
118 mime_type = kMimeTypeJpeg; 119 mime_type = kMimeTypeJpeg;
119 break; 120 break;
120 case api::extension_types::IMAGE_FORMAT_PNG: 121 case api::extension_types::IMAGE_FORMAT_PNG:
121 encoded = 122 encoded = gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, should_discard_alpha,
122 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, 123 &data);
123 true, // Discard transparency.
124 &data);
125 mime_type = kMimeTypePng; 124 mime_type = kMimeTypePng;
126 break; 125 break;
127 default: 126 default:
128 NOTREACHED() << "Invalid image format."; 127 NOTREACHED() << "Invalid image format.";
129 } 128 }
130 129
131 if (!encoded) 130 if (!encoded)
132 return false; 131 return false;
133 132
134 base::StringPiece stream_as_string(reinterpret_cast<const char*>(data.data()), 133 base::StringPiece stream_as_string(reinterpret_cast<const char*>(data.data()),
135 data.size()); 134 data.size());
136 135
137 base::Base64Encode(stream_as_string, base64_result); 136 base::Base64Encode(stream_as_string, base64_result);
138 base64_result->insert( 137 base64_result->insert(
139 0, base::StringPrintf("data:%s;base64,", mime_type.c_str())); 138 0, base::StringPrintf("data:%s;base64,", mime_type.c_str()));
140 139
141 return true; 140 return true;
142 } 141 }
143 142
144 } // namespace extensions 143 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/web_contents_capture_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698