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

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: rm 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 return true; 81 return true;
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 OnCaptureFailure(FAILURE_REASON_UNKNOWN);
92 WebContents* contents = GetWebContentsForID(context_id_);
93 if (!contents) {
94 OnCaptureFailure(FAILURE_REASON_CONTENT_NOT_FOUND);
95 return;
96 }
97
98 // Ask the renderer for a snapshot of the page.
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 } 92 }
114 93
115 void CaptureWebContentsFunction::OnCaptureSuccess(const SkBitmap& bitmap) { 94 void CaptureWebContentsFunction::OnCaptureSuccess(const SkBitmap& bitmap) {
116 std::vector<unsigned char> data; 95 std::vector<unsigned char> data;
117 SkAutoLockPixels screen_capture_lock(bitmap); 96 SkAutoLockPixels screen_capture_lock(bitmap);
118 bool encoded = false; 97 bool encoded = false;
119 std::string mime_type; 98 std::string mime_type;
120 switch (image_format_) { 99 switch (image_format_) {
121 case ImageDetails::FORMAT_JPEG: 100 case ImageDetails::FORMAT_JPEG:
122 encoded = gfx::JPEGCodec::Encode( 101 encoded = gfx::JPEGCodec::Encode(
(...skipping 27 matching lines...) Expand all
150 reinterpret_cast<const char*>(vector_as_array(&data)), data.size()); 129 reinterpret_cast<const char*>(vector_as_array(&data)), data.size());
151 130
152 base::Base64Encode(stream_as_string, &base64_result); 131 base::Base64Encode(stream_as_string, &base64_result);
153 base64_result.insert(0, base::StringPrintf("data:%s;base64,", 132 base64_result.insert(0, base::StringPrintf("data:%s;base64,",
154 mime_type.c_str())); 133 mime_type.c_str()));
155 SetResult(new base::StringValue(base64_result)); 134 SetResult(new base::StringValue(base64_result));
156 SendResponse(true); 135 SendResponse(true);
157 } 136 }
158 137
159 } // namespace extensions 138 } // 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