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

Unified Diff: content/browser/web_contents/navigation_controller_impl.cc

Issue 11635059: navigation: Retain a screenshot of the page before it unloads (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years 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: content/browser/web_contents/navigation_controller_impl.cc
diff --git a/content/browser/web_contents/navigation_controller_impl.cc b/content/browser/web_contents/navigation_controller_impl.cc
index 9481ed69c3db1a195ad77c892530b855e293adf8..bb19cc86666b7c18fd671969f84b6a73ec9aaca0 100644
--- a/content/browser/web_contents/navigation_controller_impl.cc
+++ b/content/browser/web_contents/navigation_controller_impl.cc
@@ -28,6 +28,8 @@
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
+#include "content/public/browser/render_widget_host.h"
+#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents_delegate.h"
@@ -37,6 +39,8 @@
#include "net/base/escape.h"
#include "net/base/mime_util.h"
#include "net/base/net_util.h"
+#include "skia/ext/platform_canvas.h"
+#include "ui/gfx/codec/png_codec.h"
#include "webkit/glue/glue_serialize.h"
namespace content {
@@ -470,6 +474,50 @@ int NavigationControllerImpl::GetIndexForOffset(int offset) const {
return GetCurrentEntryIndex() + offset;
}
+void NavigationControllerImpl::TakeScreenshot() {
+ CHECK(web_contents_);
+
+ NavigationEntryImpl* active_entry =
+ NavigationEntryImpl::FromNavigationEntry(GetActiveEntry());
+ if (!active_entry)
+ return;
+
+ RenderViewHost* render_view_host = web_contents_->GetRenderViewHost();
+ content::RenderWidgetHostView* view = render_view_host->GetView();
+ if (!view)
+ return;
+
+ skia::PlatformBitmap* temp_bitmap = new skia::PlatformBitmap;
+ render_view_host->CopyFromBackingStore(gfx::Rect(),
+ view->GetViewBounds().size(),
+ base::Bind(&NavigationControllerImpl::TakingScreenshotComplete,
+ base::Unretained(this),
+ active_entry,
+ base::Owned(temp_bitmap)),
+ temp_bitmap);
+}
+
+void NavigationControllerImpl::TakingScreenshotComplete(
+ NavigationEntryImpl* entry,
+ skia::PlatformBitmap* bitmap,
+ bool success) {
+ int index = GetIndexOfEntry(entry);
+ if (index < 0) {
+ LOG(ERROR) << "Invalid entry";
+ return;
+ }
+
+ if (!success) {
+ LOG(ERROR) << "Taking snapshot was unsuccessful for "
+ << entry->GetURL().spec();
+ return;
+ }
+
+ std::vector<unsigned char> data;
+ if (gfx::PNGCodec::EncodeBGRASkBitmap(bitmap->GetBitmap(), true, &data))
+ entry->SetScreenshotPNGData(data);
+}
+
bool NavigationControllerImpl::CanGoBack() const {
return entries_.size() > 1 && GetCurrentEntryIndex() > 0;
}
@@ -1441,6 +1489,8 @@ void NavigationControllerImpl::PruneOldestEntryIfFull() {
void NavigationControllerImpl::NavigateToPendingEntry(ReloadType reload_type) {
needs_reload_ = false;
+ TakeScreenshot();
sadrul 2012/12/21 17:17:41 Calling this here seems to work only for navigatio
+
// If we were navigating to a slow-to-commit page, and the user performs
// a session history navigation to the last committed page, RenderViewHost
// will force the throbber to start, but WebKit will essentially ignore the
« no previous file with comments | « content/browser/web_contents/navigation_controller_impl.h ('k') | content/browser/web_contents/navigation_entry_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698