OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/web_contents/navigation_controller_impl.h" | 5 #include "content/browser/web_contents/navigation_controller_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" |
8 #include "base/file_util.h" | 9 #include "base/file_util.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/string_number_conversions.h" // Temporary | 11 #include "base/string_number_conversions.h" // Temporary |
11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
12 #include "base/time.h" | 13 #include "base/time.h" |
13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
14 #include "content/browser/browser_url_handler_impl.h" | 15 #include "content/browser/browser_url_handler_impl.h" |
15 #include "content/browser/child_process_security_policy_impl.h" | 16 #include "content/browser/child_process_security_policy_impl.h" |
16 #include "content/browser/dom_storage/dom_storage_context_impl.h" | 17 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
17 #include "content/browser/dom_storage/session_storage_namespace_impl.h" | 18 #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
18 #include "content/browser/renderer_host/render_view_host_impl.h" // Temporary | 19 #include "content/browser/renderer_host/render_view_host_impl.h" // Temporary |
19 #include "content/browser/site_instance_impl.h" | 20 #include "content/browser/site_instance_impl.h" |
20 #include "content/browser/web_contents/debug_urls.h" | 21 #include "content/browser/web_contents/debug_urls.h" |
21 #include "content/browser/web_contents/interstitial_page_impl.h" | 22 #include "content/browser/web_contents/interstitial_page_impl.h" |
22 #include "content/browser/web_contents/navigation_entry_impl.h" | 23 #include "content/browser/web_contents/navigation_entry_impl.h" |
23 #include "content/browser/web_contents/web_contents_impl.h" | 24 #include "content/browser/web_contents/web_contents_impl.h" |
24 #include "content/common/view_messages.h" | 25 #include "content/common/view_messages.h" |
25 #include "content/public/browser/browser_context.h" | 26 #include "content/public/browser/browser_context.h" |
26 #include "content/public/browser/content_browser_client.h" | 27 #include "content/public/browser/content_browser_client.h" |
27 #include "content/public/browser/invalidate_type.h" | 28 #include "content/public/browser/invalidate_type.h" |
28 #include "content/public/browser/navigation_details.h" | 29 #include "content/public/browser/navigation_details.h" |
29 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
30 #include "content/public/browser/notification_types.h" | 31 #include "content/public/browser/notification_types.h" |
| 32 #include "content/public/browser/render_widget_host.h" |
| 33 #include "content/public/browser/render_widget_host_view.h" |
31 #include "content/public/browser/storage_partition.h" | 34 #include "content/public/browser/storage_partition.h" |
32 #include "content/public/browser/user_metrics.h" | 35 #include "content/public/browser/user_metrics.h" |
33 #include "content/public/browser/web_contents_delegate.h" | 36 #include "content/public/browser/web_contents_delegate.h" |
34 #include "content/public/common/content_client.h" | 37 #include "content/public/common/content_client.h" |
35 #include "content/public/common/content_constants.h" | 38 #include "content/public/common/content_constants.h" |
| 39 #include "content/public/common/content_switches.h" |
36 #include "content/public/common/url_constants.h" | 40 #include "content/public/common/url_constants.h" |
37 #include "net/base/escape.h" | 41 #include "net/base/escape.h" |
38 #include "net/base/mime_util.h" | 42 #include "net/base/mime_util.h" |
39 #include "net/base/net_util.h" | 43 #include "net/base/net_util.h" |
| 44 #include "skia/ext/platform_canvas.h" |
| 45 #include "ui/gfx/codec/png_codec.h" |
40 #include "webkit/glue/glue_serialize.h" | 46 #include "webkit/glue/glue_serialize.h" |
41 | 47 |
42 namespace content { | 48 namespace content { |
43 namespace { | 49 namespace { |
44 | 50 |
45 const int kInvalidateAll = 0xFFFFFFFF; | 51 const int kInvalidateAll = 0xFFFFFFFF; |
46 | 52 |
47 // Invoked when entries have been pruned, or removed. For example, if the | 53 // Invoked when entries have been pruned, or removed. For example, if the |
48 // current entries are [google, digg, yahoo], with the current entry google, | 54 // current entries are [google, digg, yahoo], with the current entry google, |
49 // and the user types in cnet, then digg and yahoo are pruned. | 55 // and the user types in cnet, then digg and yahoo are pruned. |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 if (index < 0 || index >= GetEntryCount()) | 469 if (index < 0 || index >= GetEntryCount()) |
464 return NULL; | 470 return NULL; |
465 | 471 |
466 return entries_[index].get(); | 472 return entries_[index].get(); |
467 } | 473 } |
468 | 474 |
469 int NavigationControllerImpl::GetIndexForOffset(int offset) const { | 475 int NavigationControllerImpl::GetIndexForOffset(int offset) const { |
470 return GetCurrentEntryIndex() + offset; | 476 return GetCurrentEntryIndex() + offset; |
471 } | 477 } |
472 | 478 |
| 479 void NavigationControllerImpl::TakeScreenshot() { |
| 480 static bool overscroll_enabled = CommandLine::ForCurrentProcess()-> |
| 481 HasSwitch(switches::kEnableOverscrollHistoryNavigation); |
| 482 if (!overscroll_enabled) |
| 483 return; |
| 484 |
| 485 NavigationEntryImpl* entry = |
| 486 NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry()); |
| 487 if (!entry) |
| 488 return; |
| 489 |
| 490 RenderViewHost* render_view_host = web_contents_->GetRenderViewHost(); |
| 491 content::RenderWidgetHostView* view = render_view_host->GetView(); |
| 492 if (!view) |
| 493 return; |
| 494 |
| 495 skia::PlatformBitmap* temp_bitmap = new skia::PlatformBitmap; |
| 496 render_view_host->CopyFromBackingStore(gfx::Rect(), |
| 497 view->GetViewBounds().size(), |
| 498 base::Bind(&NavigationControllerImpl::OnScreenshotTaken, |
| 499 base::Unretained(this), |
| 500 entry->GetUniqueID(), |
| 501 base::Owned(temp_bitmap)), |
| 502 temp_bitmap); |
| 503 } |
| 504 |
| 505 void NavigationControllerImpl::OnScreenshotTaken( |
| 506 int unique_id, |
| 507 skia::PlatformBitmap* bitmap, |
| 508 bool success) { |
| 509 if (!success) { |
| 510 LOG(ERROR) << "Taking snapshot was unsuccessful for " |
| 511 << unique_id; |
| 512 return; |
| 513 } |
| 514 |
| 515 NavigationEntryImpl* entry = NULL; |
| 516 for (NavigationEntries::iterator i = entries_.begin(); |
| 517 i != entries_.end(); |
| 518 ++i) { |
| 519 if ((*i)->GetUniqueID() == unique_id) { |
| 520 entry = (*i).get(); |
| 521 break; |
| 522 } |
| 523 } |
| 524 |
| 525 if (!entry) { |
| 526 LOG(ERROR) << "Invalid entry with unique id: " << unique_id; |
| 527 return; |
| 528 } |
| 529 |
| 530 std::vector<unsigned char> data; |
| 531 if (gfx::PNGCodec::EncodeBGRASkBitmap(bitmap->GetBitmap(), true, &data)) |
| 532 entry->SetScreenshotPNGData(data); |
| 533 } |
| 534 |
473 bool NavigationControllerImpl::CanGoBack() const { | 535 bool NavigationControllerImpl::CanGoBack() const { |
474 return entries_.size() > 1 && GetCurrentEntryIndex() > 0; | 536 return entries_.size() > 1 && GetCurrentEntryIndex() > 0; |
475 } | 537 } |
476 | 538 |
477 bool NavigationControllerImpl::CanGoForward() const { | 539 bool NavigationControllerImpl::CanGoForward() const { |
478 int index = GetCurrentEntryIndex(); | 540 int index = GetCurrentEntryIndex(); |
479 return index >= 0 && index < (static_cast<int>(entries_.size()) - 1); | 541 return index >= 0 && index < (static_cast<int>(entries_.size()) - 1); |
480 } | 542 } |
481 | 543 |
482 bool NavigationControllerImpl::CanGoToOffset(int offset) const { | 544 bool NavigationControllerImpl::CanGoToOffset(int offset) const { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 LoadEntry(entry); | 745 LoadEntry(entry); |
684 } | 746 } |
685 | 747 |
686 void NavigationControllerImpl::DocumentLoadedInFrame() { | 748 void NavigationControllerImpl::DocumentLoadedInFrame() { |
687 is_initial_navigation_ = false; | 749 is_initial_navigation_ = false; |
688 } | 750 } |
689 | 751 |
690 bool NavigationControllerImpl::RendererDidNavigate( | 752 bool NavigationControllerImpl::RendererDidNavigate( |
691 const ViewHostMsg_FrameNavigate_Params& params, | 753 const ViewHostMsg_FrameNavigate_Params& params, |
692 LoadCommittedDetails* details) { | 754 LoadCommittedDetails* details) { |
| 755 // When navigating away from the current page, take a screenshot of it in the |
| 756 // current state so that it can be used during an overscroll-navigation |
| 757 // gesture. |
| 758 if (details->is_main_frame) |
| 759 TakeScreenshot(); |
693 | 760 |
694 // Save the previous state before we clobber it. | 761 // Save the previous state before we clobber it. |
695 if (GetLastCommittedEntry()) { | 762 if (GetLastCommittedEntry()) { |
696 details->previous_url = GetLastCommittedEntry()->GetURL(); | 763 details->previous_url = GetLastCommittedEntry()->GetURL(); |
697 details->previous_entry_index = GetLastCommittedEntryIndex(); | 764 details->previous_entry_index = GetLastCommittedEntryIndex(); |
698 } else { | 765 } else { |
699 details->previous_url = GURL(); | 766 details->previous_url = GURL(); |
700 details->previous_entry_index = -1; | 767 details->previous_entry_index = -1; |
701 } | 768 } |
702 | 769 |
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1609 } | 1676 } |
1610 } | 1677 } |
1611 } | 1678 } |
1612 | 1679 |
1613 void NavigationControllerImpl::SetGetTimestampCallbackForTest( | 1680 void NavigationControllerImpl::SetGetTimestampCallbackForTest( |
1614 const base::Callback<base::Time()>& get_timestamp_callback) { | 1681 const base::Callback<base::Time()>& get_timestamp_callback) { |
1615 get_timestamp_callback_ = get_timestamp_callback; | 1682 get_timestamp_callback_ = get_timestamp_callback; |
1616 } | 1683 } |
1617 | 1684 |
1618 } // namespace content | 1685 } // namespace content |
OLD | NEW |