| 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 "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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 std::string* base64_result) { | 91 std::string* base64_result) { |
| 92 DCHECK(base64_result); | 92 DCHECK(base64_result); |
| 93 std::vector<unsigned char> data; | 93 std::vector<unsigned char> data; |
| 94 const bool should_discard_alpha = !ClientAllowsTransparency(); | 94 const bool should_discard_alpha = !ClientAllowsTransparency(); |
| 95 bool encoded = false; | 95 bool encoded = false; |
| 96 std::string mime_type; | 96 std::string mime_type; |
| 97 switch (image_format_) { | 97 switch (image_format_) { |
| 98 case api::extension_types::IMAGE_FORMAT_JPEG: | 98 case api::extension_types::IMAGE_FORMAT_JPEG: |
| 99 encoded = gfx::JPEGCodec::Encode( | 99 encoded = gfx::JPEGCodec::Encode( |
| 100 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), | 100 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), |
| 101 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(), | 101 kN32_SkColorType, bitmap.width(), bitmap.height(), |
| 102 static_cast<int>(bitmap.rowBytes()), image_quality_, &data); | 102 static_cast<int>(bitmap.rowBytes()), image_quality_, &data); |
| 103 mime_type = kMimeTypeJpeg; | 103 mime_type = kMimeTypeJpeg; |
| 104 break; | 104 break; |
| 105 case api::extension_types::IMAGE_FORMAT_PNG: | 105 case api::extension_types::IMAGE_FORMAT_PNG: |
| 106 encoded = gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, should_discard_alpha, | 106 encoded = gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, should_discard_alpha, |
| 107 &data); | 107 &data); |
| 108 mime_type = kMimeTypePng; | 108 mime_type = kMimeTypePng; |
| 109 break; | 109 break; |
| 110 default: | 110 default: |
| 111 NOTREACHED() << "Invalid image format."; | 111 NOTREACHED() << "Invalid image format."; |
| 112 } | 112 } |
| 113 | 113 |
| 114 if (!encoded) | 114 if (!encoded) |
| 115 return false; | 115 return false; |
| 116 | 116 |
| 117 base::StringPiece stream_as_string(reinterpret_cast<const char*>(data.data()), | 117 base::StringPiece stream_as_string(reinterpret_cast<const char*>(data.data()), |
| 118 data.size()); | 118 data.size()); |
| 119 | 119 |
| 120 base::Base64Encode(stream_as_string, base64_result); | 120 base::Base64Encode(stream_as_string, base64_result); |
| 121 base64_result->insert( | 121 base64_result->insert( |
| 122 0, base::StringPrintf("data:%s;base64,", mime_type.c_str())); | 122 0, base::StringPrintf("data:%s;base64,", mime_type.c_str())); |
| 123 | 123 |
| 124 return true; | 124 return true; |
| 125 } | 125 } |
| 126 | 126 |
| 127 } // namespace extensions | 127 } // namespace extensions |
| OLD | NEW |