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

Unified Diff: chrome/renderer/chrome_render_view_observer.cc

Issue 12746009: Revert 189969 "Add RenderWidgetHost::GetSnapshotFromRenderer met..." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1450/src/
Patch Set: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/chrome_render_view_observer.cc
===================================================================
--- chrome/renderer/chrome_render_view_observer.cc (revision 190011)
+++ chrome/renderer/chrome_render_view_observer.cc (working copy)
@@ -194,6 +194,7 @@
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message)
IPC_MESSAGE_HANDLER(ChromeViewMsg_WebUIJavaScript, OnWebUIJavaScript)
+ IPC_MESSAGE_HANDLER(ChromeViewMsg_CaptureSnapshot, OnCaptureSnapshot)
IPC_MESSAGE_HANDLER(ChromeViewMsg_HandleMessageFromExternalHost,
OnHandleMessageFromExternalHost)
IPC_MESSAGE_HANDLER(ChromeViewMsg_JavaScriptStressTestControl,
@@ -235,6 +236,24 @@
webui_javascript_->notify_result = notify_result;
}
+void ChromeRenderViewObserver::OnCaptureSnapshot() {
+ SkBitmap snapshot;
+ bool error = false;
+
+ WebFrame* main_frame = render_view()->GetWebView()->mainFrame();
+ if (!main_frame)
+ error = true;
+
+ if (!error && !CaptureSnapshot(render_view()->GetWebView(), &snapshot))
+ error = true;
+
+ DCHECK(error == snapshot.empty()) <<
+ "Snapshot should be empty on error, non-empty otherwise.";
+
+ // Send the snapshot to the browser process.
+ Send(new ChromeViewHostMsg_Snapshot(routing_id(), snapshot));
+}
+
void ChromeRenderViewObserver::OnHandleMessageFromExternalHost(
const std::string& message,
const std::string& origin,
@@ -776,6 +795,35 @@
}
}
+bool ChromeRenderViewObserver::CaptureSnapshot(WebView* view,
+ SkBitmap* snapshot) {
+ base::TimeTicks beginning_time = base::TimeTicks::Now();
+
+ view->layout();
+ const WebSize& size = view->size();
+
+ skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(
+ skia::CreatePlatformCanvas(
+ size.width, size.height, true, NULL, skia::RETURN_NULL_ON_FAILURE));
+ if (!canvas)
+ return false;
+
+ view->paint(webkit_glue::ToWebCanvas(canvas.get()),
+ WebRect(0, 0, size.width, size.height));
+ // TODO: Add a way to snapshot the whole page, not just the currently
+ // visible part.
+
+ SkDevice* device = skia::GetTopDevice(*canvas);
+
+ const SkBitmap& bitmap = device->accessBitmap(false);
+ if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
+ return false;
+
+ UMA_HISTOGRAM_TIMES("Renderer4.Snapshot",
+ base::TimeTicks::Now() - beginning_time);
+ return true;
+}
+
ExternalHostBindings* ChromeRenderViewObserver::GetExternalHostBindings() {
if (!external_host_bindings_.get()) {
external_host_bindings_.reset(new ExternalHostBindings(

Powered by Google App Engine
This is Rietveld 408576698