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..2e83475be34cb8e4345929747d52b3e5dc053d44 100644 |
--- a/content/browser/web_contents/navigation_controller_impl.cc |
+++ b/content/browser/web_contents/navigation_controller_impl.cc |
@@ -5,6 +5,7 @@ |
#include "content/browser/web_contents/navigation_controller_impl.h" |
#include "base/bind.h" |
+#include "base/command_line.h" |
#include "base/file_util.h" |
#include "base/logging.h" |
#include "base/string_number_conversions.h" // Temporary |
@@ -28,15 +29,20 @@ |
#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" |
#include "content/public/common/content_client.h" |
#include "content/public/common/content_constants.h" |
+#include "content/public/common/content_switches.h" |
#include "content/public/common/url_constants.h" |
#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 +476,64 @@ int NavigationControllerImpl::GetIndexForOffset(int offset) const { |
return GetCurrentEntryIndex() + offset; |
} |
+void NavigationControllerImpl::TakeScreenshot() { |
+ static bool overscroll_enabled = CommandLine::ForCurrentProcess()-> |
+ HasSwitch(switches::kEnableOverscrollHistoryNavigation); |
+ if (!overscroll_enabled) |
+ return; |
+ |
+ CHECK(web_contents_); |
Charlie Reis
2012/12/21 23:22:07
This CHECK isn't really necessary. A NavigationCo
sadrul
2012/12/22 00:07:10
Removed.
|
+ |
+ NavigationEntryImpl* active_entry = |
Charlie Reis
2012/12/21 23:22:07
Calling this active_entry is confusing. Perhaps j
sadrul
2012/12/22 00:07:10
Done.
|
+ NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry()); |
+ 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(), |
Charlie Reis
2012/12/21 23:22:07
What happens if the view size changes when you wan
sadrul
2012/12/22 00:07:10
Currently, we paint the screenshot in the original
|
+ base::Bind(&NavigationControllerImpl::TakingScreenshotComplete, |
+ base::Unretained(this), |
+ active_entry->GetUniqueID(), |
+ base::Owned(temp_bitmap)), |
+ temp_bitmap); |
+} |
+ |
+void NavigationControllerImpl::TakingScreenshotComplete( |
+ int unique_id, |
+ skia::PlatformBitmap* bitmap, |
+ bool success) { |
+ NavigationEntryImpl* entry = NULL; |
+ for (NavigationEntries::iterator i = entries_.begin(); |
+ i != entries_.end(); |
+ ++i) { |
+ if ((*i)->GetUniqueID() == unique_id) { |
+ entry = (*i).get(); |
+ break; |
+ } |
+ } |
+ |
+ if (!entry) { |
+ LOG(ERROR) << "Invalid entry with unique id: " << unique_id; |
+ return; |
+ } |
+ |
+ if (!success) { |
Charlie Reis
2012/12/21 23:22:07
Should we just move this to the top and skip searc
sadrul
2012/12/22 00:07:10
Sounds good. Done.
|
+ 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 +754,8 @@ void NavigationControllerImpl::DocumentLoadedInFrame() { |
bool NavigationControllerImpl::RendererDidNavigate( |
const ViewHostMsg_FrameNavigate_Params& params, |
LoadCommittedDetails* details) { |
+ if (details->is_main_frame) |
+ TakeScreenshot(); |
Charlie Reis
2012/12/21 23:22:07
Are we certain this is going to show the previous
sadrul
2012/12/22 00:07:10
Hm, good point. For the software compositing case,
|
// Save the previous state before we clobber it. |
if (GetLastCommittedEntry()) { |
@@ -1441,6 +1507,8 @@ void NavigationControllerImpl::PruneOldestEntryIfFull() { |
void NavigationControllerImpl::NavigateToPendingEntry(ReloadType reload_type) { |
needs_reload_ = false; |
+ TakeScreenshot(); |
Charlie Reis
2012/12/21 23:22:07
Why is this needed here? This isn't called for al
sadrul
2012/12/22 00:07:10
Removed.
|
+ |
// 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 |