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

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

Issue 259523008: Remove RenderWidgetHost::GetSnapshotFromRenderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: getsnapshotfromrenderer: Created 6 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 | Annotate | Revision Log
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 "chrome/browser/extensions/api/capture_web_contents_function.h" 5 #include "chrome/browser/extensions/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 "chrome/browser/extensions/api/tabs/tabs_constants.h" 9 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
10 #include "content/public/browser/render_view_host.h" 10 #include "content/public/browser/render_view_host.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } 82 }
83 83
84 void CaptureWebContentsFunction::CopyFromBackingStoreComplete( 84 void CaptureWebContentsFunction::CopyFromBackingStoreComplete(
85 bool succeeded, 85 bool succeeded,
86 const SkBitmap& bitmap) { 86 const SkBitmap& bitmap) {
87 if (succeeded) { 87 if (succeeded) {
88 OnCaptureSuccess(bitmap); 88 OnCaptureSuccess(bitmap);
89 return; 89 return;
90 } 90 }
91 91
92 WebContents* contents = GetWebContentsForID(context_id_); 92 WebContents* contents = GetWebContentsForID(context_id_);
Lei Zhang 2014/04/24 23:50:43 Do you need this anymore? The only reason we looke
danakj 2014/04/25 15:20:16 Done.
93 if (!contents) { 93 if (!contents) {
94 OnCaptureFailure(FAILURE_REASON_CONTENT_NOT_FOUND); 94 OnCaptureFailure(FAILURE_REASON_CONTENT_NOT_FOUND);
95 return; 95 return;
96 } 96 }
97 97
98 // Ask the renderer for a snapshot of the page. 98 OnCaptureFailure(FAILURE_REASON_UNKNOWN);
99 RenderWidgetHost* render_widget_host = contents->GetRenderViewHost();
100 render_widget_host->GetSnapshotFromRenderer(
101 gfx::Rect(),
102 base::Bind(&CaptureWebContentsFunction::GetSnapshotFromRendererComplete,
103 this));
104 }
105
106 void CaptureWebContentsFunction::GetSnapshotFromRendererComplete(
107 bool succeeded,
108 const SkBitmap& bitmap) {
109 if (succeeded)
110 OnCaptureSuccess(bitmap);
111 else
112 OnCaptureFailure(FAILURE_REASON_UNKNOWN);
113 } 99 }
114 100
115 void CaptureWebContentsFunction::OnCaptureSuccess(const SkBitmap& bitmap) { 101 void CaptureWebContentsFunction::OnCaptureSuccess(const SkBitmap& bitmap) {
116 std::vector<unsigned char> data; 102 std::vector<unsigned char> data;
117 SkAutoLockPixels screen_capture_lock(bitmap); 103 SkAutoLockPixels screen_capture_lock(bitmap);
118 bool encoded = false; 104 bool encoded = false;
119 std::string mime_type; 105 std::string mime_type;
120 switch (image_format_) { 106 switch (image_format_) {
121 case ImageDetails::FORMAT_JPEG: 107 case ImageDetails::FORMAT_JPEG:
122 encoded = gfx::JPEGCodec::Encode( 108 encoded = gfx::JPEGCodec::Encode(
(...skipping 27 matching lines...) Expand all
150 reinterpret_cast<const char*>(vector_as_array(&data)), data.size()); 136 reinterpret_cast<const char*>(vector_as_array(&data)), data.size());
151 137
152 base::Base64Encode(stream_as_string, &base64_result); 138 base::Base64Encode(stream_as_string, &base64_result);
153 base64_result.insert(0, base::StringPrintf("data:%s;base64,", 139 base64_result.insert(0, base::StringPrintf("data:%s;base64,",
154 mime_type.c_str())); 140 mime_type.c_str()));
155 SetResult(new base::StringValue(base64_result)); 141 SetResult(new base::StringValue(base64_result));
156 SendResponse(true); 142 SendResponse(true);
157 } 143 }
158 144
159 } // namespace extensions 145 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/capture_web_contents_function.h ('k') | chrome/browser/thumbnails/thumbnail_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698