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

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

Issue 593503003: Support error handling for Surface readbacks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Formatted code and fixed build issue in test. Created 6 years, 1 month 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
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/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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 host->CopyFromBackingStore( 84 host->CopyFromBackingStore(
85 gfx::Rect(view_size), 85 gfx::Rect(view_size),
86 bitmap_size, 86 bitmap_size,
87 base::Bind(&CaptureWebContentsFunction::CopyFromBackingStoreComplete, 87 base::Bind(&CaptureWebContentsFunction::CopyFromBackingStoreComplete,
88 this), 88 this),
89 kN32_SkColorType); 89 kN32_SkColorType);
90 return true; 90 return true;
91 } 91 }
92 92
93 void CaptureWebContentsFunction::CopyFromBackingStoreComplete( 93 void CaptureWebContentsFunction::CopyFromBackingStoreComplete(
94 bool succeeded, 94 const SkBitmap& bitmap,
95 const SkBitmap& bitmap) { 95 content::ReadbackResponse response) {
96 if (succeeded) { 96 if (response == content::READBACK_SUCCESS) {
97 OnCaptureSuccess(bitmap); 97 OnCaptureSuccess(bitmap);
98 return; 98 return;
99 } 99 }
100 OnCaptureFailure(FAILURE_REASON_UNKNOWN); 100 OnCaptureFailure(FAILURE_REASON_UNKNOWN);
101 } 101 }
102 102
103 void CaptureWebContentsFunction::OnCaptureSuccess(const SkBitmap& bitmap) { 103 void CaptureWebContentsFunction::OnCaptureSuccess(const SkBitmap& bitmap) {
104 std::vector<unsigned char> data; 104 std::vector<unsigned char> data;
105 SkAutoLockPixels screen_capture_lock(bitmap); 105 SkAutoLockPixels screen_capture_lock(bitmap);
106 bool encoded = false; 106 bool encoded = false;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 reinterpret_cast<const char*>(vector_as_array(&data)), data.size()); 138 reinterpret_cast<const char*>(vector_as_array(&data)), data.size());
139 139
140 base::Base64Encode(stream_as_string, &base64_result); 140 base::Base64Encode(stream_as_string, &base64_result);
141 base64_result.insert( 141 base64_result.insert(
142 0, base::StringPrintf("data:%s;base64,", mime_type.c_str())); 142 0, base::StringPrintf("data:%s;base64,", mime_type.c_str()));
143 SetResult(new base::StringValue(base64_result)); 143 SetResult(new base::StringValue(base64_result));
144 SendResponse(true); 144 SendResponse(true);
145 } 145 }
146 146
147 } // namespace extensions 147 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698