| 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..ace043c4ba84c2d6fac9b060ebd11067dfa95f1c 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;
|
| }
|
| @@ -690,6 +738,8 @@ void NavigationControllerImpl::DocumentLoadedInFrame() {
|
| bool NavigationControllerImpl::RendererDidNavigate(
|
| const ViewHostMsg_FrameNavigate_Params& params,
|
| LoadCommittedDetails* details) {
|
| + if (details->is_main_frame)
|
| + TakeScreenshot();
|
|
|
| // Save the previous state before we clobber it.
|
| if (GetLastCommittedEntry()) {
|
| @@ -1441,6 +1491,8 @@ void NavigationControllerImpl::PruneOldestEntryIfFull() {
|
| void NavigationControllerImpl::NavigateToPendingEntry(ReloadType reload_type) {
|
| needs_reload_ = false;
|
|
|
| + TakeScreenshot();
|
| +
|
| // 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
|
|
|