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 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.
| |
486 | |
487 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.
| |
488 NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry()); | |
489 if (!active_entry) | |
490 return; | |
491 | |
492 RenderViewHost* render_view_host = web_contents_->GetRenderViewHost(); | |
493 content::RenderWidgetHostView* view = render_view_host->GetView(); | |
494 if (!view) | |
495 return; | |
496 | |
497 skia::PlatformBitmap* temp_bitmap = new skia::PlatformBitmap; | |
498 render_view_host->CopyFromBackingStore(gfx::Rect(), | |
499 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
| |
500 base::Bind(&NavigationControllerImpl::TakingScreenshotComplete, | |
501 base::Unretained(this), | |
502 active_entry->GetUniqueID(), | |
503 base::Owned(temp_bitmap)), | |
504 temp_bitmap); | |
505 } | |
506 | |
507 void NavigationControllerImpl::TakingScreenshotComplete( | |
508 int unique_id, | |
509 skia::PlatformBitmap* bitmap, | |
510 bool success) { | |
511 NavigationEntryImpl* entry = NULL; | |
512 for (NavigationEntries::iterator i = entries_.begin(); | |
513 i != entries_.end(); | |
514 ++i) { | |
515 if ((*i)->GetUniqueID() == unique_id) { | |
516 entry = (*i).get(); | |
517 break; | |
518 } | |
519 } | |
520 | |
521 if (!entry) { | |
522 LOG(ERROR) << "Invalid entry with unique id: " << unique_id; | |
523 return; | |
524 } | |
525 | |
526 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.
| |
527 LOG(ERROR) << "Taking snapshot was unsuccessful for " | |
528 << entry->GetURL().spec(); | |
529 return; | |
530 } | |
531 | |
532 std::vector<unsigned char> data; | |
533 if (gfx::PNGCodec::EncodeBGRASkBitmap(bitmap->GetBitmap(), true, &data)) | |
534 entry->SetScreenshotPNGData(data); | |
535 } | |
536 | |
473 bool NavigationControllerImpl::CanGoBack() const { | 537 bool NavigationControllerImpl::CanGoBack() const { |
474 return entries_.size() > 1 && GetCurrentEntryIndex() > 0; | 538 return entries_.size() > 1 && GetCurrentEntryIndex() > 0; |
475 } | 539 } |
476 | 540 |
477 bool NavigationControllerImpl::CanGoForward() const { | 541 bool NavigationControllerImpl::CanGoForward() const { |
478 int index = GetCurrentEntryIndex(); | 542 int index = GetCurrentEntryIndex(); |
479 return index >= 0 && index < (static_cast<int>(entries_.size()) - 1); | 543 return index >= 0 && index < (static_cast<int>(entries_.size()) - 1); |
480 } | 544 } |
481 | 545 |
482 bool NavigationControllerImpl::CanGoToOffset(int offset) const { | 546 bool NavigationControllerImpl::CanGoToOffset(int offset) const { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
683 LoadEntry(entry); | 747 LoadEntry(entry); |
684 } | 748 } |
685 | 749 |
686 void NavigationControllerImpl::DocumentLoadedInFrame() { | 750 void NavigationControllerImpl::DocumentLoadedInFrame() { |
687 is_initial_navigation_ = false; | 751 is_initial_navigation_ = false; |
688 } | 752 } |
689 | 753 |
690 bool NavigationControllerImpl::RendererDidNavigate( | 754 bool NavigationControllerImpl::RendererDidNavigate( |
691 const ViewHostMsg_FrameNavigate_Params& params, | 755 const ViewHostMsg_FrameNavigate_Params& params, |
692 LoadCommittedDetails* details) { | 756 LoadCommittedDetails* details) { |
757 if (details->is_main_frame) | |
758 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,
| |
693 | 759 |
694 // Save the previous state before we clobber it. | 760 // Save the previous state before we clobber it. |
695 if (GetLastCommittedEntry()) { | 761 if (GetLastCommittedEntry()) { |
696 details->previous_url = GetLastCommittedEntry()->GetURL(); | 762 details->previous_url = GetLastCommittedEntry()->GetURL(); |
697 details->previous_entry_index = GetLastCommittedEntryIndex(); | 763 details->previous_entry_index = GetLastCommittedEntryIndex(); |
698 } else { | 764 } else { |
699 details->previous_url = GURL(); | 765 details->previous_url = GURL(); |
700 details->previous_entry_index = -1; | 766 details->previous_entry_index = -1; |
701 } | 767 } |
702 | 768 |
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1434 DCHECK_EQ(max_entry_count(), entries_.size()); | 1500 DCHECK_EQ(max_entry_count(), entries_.size()); |
1435 DCHECK(last_committed_entry_index_ > 0); | 1501 DCHECK(last_committed_entry_index_ > 0); |
1436 RemoveEntryAtIndex(0); | 1502 RemoveEntryAtIndex(0); |
1437 NotifyPrunedEntries(this, true, 1); | 1503 NotifyPrunedEntries(this, true, 1); |
1438 } | 1504 } |
1439 } | 1505 } |
1440 | 1506 |
1441 void NavigationControllerImpl::NavigateToPendingEntry(ReloadType reload_type) { | 1507 void NavigationControllerImpl::NavigateToPendingEntry(ReloadType reload_type) { |
1442 needs_reload_ = false; | 1508 needs_reload_ = false; |
1443 | 1509 |
1510 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.
| |
1511 | |
1444 // If we were navigating to a slow-to-commit page, and the user performs | 1512 // If we were navigating to a slow-to-commit page, and the user performs |
1445 // a session history navigation to the last committed page, RenderViewHost | 1513 // a session history navigation to the last committed page, RenderViewHost |
1446 // will force the throbber to start, but WebKit will essentially ignore the | 1514 // will force the throbber to start, but WebKit will essentially ignore the |
1447 // navigation, and won't send a message to stop the throbber. To prevent this | 1515 // navigation, and won't send a message to stop the throbber. To prevent this |
1448 // from happening, we drop the navigation here and stop the slow-to-commit | 1516 // from happening, we drop the navigation here and stop the slow-to-commit |
1449 // page from loading (which would normally happen during the navigation). | 1517 // page from loading (which would normally happen during the navigation). |
1450 if (pending_entry_index_ != -1 && | 1518 if (pending_entry_index_ != -1 && |
1451 pending_entry_index_ == last_committed_entry_index_ && | 1519 pending_entry_index_ == last_committed_entry_index_ && |
1452 (entries_[pending_entry_index_]->restore_type() == | 1520 (entries_[pending_entry_index_]->restore_type() == |
1453 NavigationEntryImpl::RESTORE_NONE) && | 1521 NavigationEntryImpl::RESTORE_NONE) && |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1609 } | 1677 } |
1610 } | 1678 } |
1611 } | 1679 } |
1612 | 1680 |
1613 void NavigationControllerImpl::SetGetTimestampCallbackForTest( | 1681 void NavigationControllerImpl::SetGetTimestampCallbackForTest( |
1614 const base::Callback<base::Time()>& get_timestamp_callback) { | 1682 const base::Callback<base::Time()>& get_timestamp_callback) { |
1615 get_timestamp_callback_ = get_timestamp_callback; | 1683 get_timestamp_callback_ = get_timestamp_callback; |
1616 } | 1684 } |
1617 | 1685 |
1618 } // namespace content | 1686 } // namespace content |
OLD | NEW |