| 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/capture_web_contents_function.h" | 5 #include "extensions/browser/api/capture_web_contents_function.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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 default: | 130 default: |
| 131 NOTREACHED() << "Invalid image format."; | 131 NOTREACHED() << "Invalid image format."; |
| 132 } | 132 } |
| 133 | 133 |
| 134 if (!encoded) { | 134 if (!encoded) { |
| 135 OnCaptureFailure(FAILURE_REASON_ENCODING_FAILED); | 135 OnCaptureFailure(FAILURE_REASON_ENCODING_FAILED); |
| 136 return; | 136 return; |
| 137 } | 137 } |
| 138 | 138 |
| 139 std::string base64_result; | 139 std::string base64_result; |
| 140 base::StringPiece stream_as_string( | 140 base::StringPiece stream_as_string(reinterpret_cast<const char*>(data.data()), |
| 141 reinterpret_cast<const char*>(vector_as_array(&data)), data.size()); | 141 data.size()); |
| 142 | 142 |
| 143 base::Base64Encode(stream_as_string, &base64_result); | 143 base::Base64Encode(stream_as_string, &base64_result); |
| 144 base64_result.insert( | 144 base64_result.insert( |
| 145 0, base::StringPrintf("data:%s;base64,", mime_type.c_str())); | 145 0, base::StringPrintf("data:%s;base64,", mime_type.c_str())); |
| 146 SetResult(new base::StringValue(base64_result)); | 146 SetResult(new base::StringValue(base64_result)); |
| 147 SendResponse(true); | 147 SendResponse(true); |
| 148 } | 148 } |
| 149 | 149 |
| 150 } // namespace extensions | 150 } // namespace extensions |
| OLD | NEW |