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/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_number_conversions.h" // Temporary | 10 #include "base/string_number_conversions.h" // Temporary |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "content/browser/web_contents/interstitial_page_impl.h" | 21 #include "content/browser/web_contents/interstitial_page_impl.h" |
22 #include "content/browser/web_contents/navigation_entry_impl.h" | 22 #include "content/browser/web_contents/navigation_entry_impl.h" |
23 #include "content/browser/web_contents/web_contents_impl.h" | 23 #include "content/browser/web_contents/web_contents_impl.h" |
24 #include "content/common/view_messages.h" | 24 #include "content/common/view_messages.h" |
25 #include "content/public/browser/browser_context.h" | 25 #include "content/public/browser/browser_context.h" |
26 #include "content/public/browser/content_browser_client.h" | 26 #include "content/public/browser/content_browser_client.h" |
27 #include "content/public/browser/invalidate_type.h" | 27 #include "content/public/browser/invalidate_type.h" |
28 #include "content/public/browser/navigation_details.h" | 28 #include "content/public/browser/navigation_details.h" |
29 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
30 #include "content/public/browser/notification_types.h" | 30 #include "content/public/browser/notification_types.h" |
31 #include "content/public/browser/render_widget_host.h" | |
32 #include "content/public/browser/render_widget_host_view.h" | |
31 #include "content/public/browser/storage_partition.h" | 33 #include "content/public/browser/storage_partition.h" |
32 #include "content/public/browser/user_metrics.h" | 34 #include "content/public/browser/user_metrics.h" |
33 #include "content/public/browser/web_contents_delegate.h" | 35 #include "content/public/browser/web_contents_delegate.h" |
34 #include "content/public/common/content_client.h" | 36 #include "content/public/common/content_client.h" |
35 #include "content/public/common/content_constants.h" | 37 #include "content/public/common/content_constants.h" |
36 #include "content/public/common/url_constants.h" | 38 #include "content/public/common/url_constants.h" |
37 #include "net/base/escape.h" | 39 #include "net/base/escape.h" |
38 #include "net/base/mime_util.h" | 40 #include "net/base/mime_util.h" |
39 #include "net/base/net_util.h" | 41 #include "net/base/net_util.h" |
42 #include "skia/ext/platform_canvas.h" | |
43 #include "ui/gfx/codec/png_codec.h" | |
40 #include "webkit/glue/glue_serialize.h" | 44 #include "webkit/glue/glue_serialize.h" |
41 | 45 |
42 namespace content { | 46 namespace content { |
43 namespace { | 47 namespace { |
44 | 48 |
45 const int kInvalidateAll = 0xFFFFFFFF; | 49 const int kInvalidateAll = 0xFFFFFFFF; |
46 | 50 |
47 // Invoked when entries have been pruned, or removed. For example, if the | 51 // Invoked when entries have been pruned, or removed. For example, if the |
48 // current entries are [google, digg, yahoo], with the current entry google, | 52 // current entries are [google, digg, yahoo], with the current entry google, |
49 // and the user types in cnet, then digg and yahoo are pruned. | 53 // 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()) | 467 if (index < 0 || index >= GetEntryCount()) |
464 return NULL; | 468 return NULL; |
465 | 469 |
466 return entries_[index].get(); | 470 return entries_[index].get(); |
467 } | 471 } |
468 | 472 |
469 int NavigationControllerImpl::GetIndexForOffset(int offset) const { | 473 int NavigationControllerImpl::GetIndexForOffset(int offset) const { |
470 return GetCurrentEntryIndex() + offset; | 474 return GetCurrentEntryIndex() + offset; |
471 } | 475 } |
472 | 476 |
477 void NavigationControllerImpl::TakeScreenshot() { | |
478 CHECK(web_contents_); | |
479 | |
480 NavigationEntryImpl* active_entry = | |
481 NavigationEntryImpl::FromNavigationEntry(GetActiveEntry()); | |
482 if (!active_entry) | |
483 return; | |
484 | |
485 RenderViewHost* render_view_host = web_contents_->GetRenderViewHost(); | |
486 content::RenderWidgetHostView* view = render_view_host->GetView(); | |
487 if (!view) | |
488 return; | |
489 | |
490 skia::PlatformBitmap* temp_bitmap = new skia::PlatformBitmap; | |
491 render_view_host->CopyFromBackingStore(gfx::Rect(), | |
492 view->GetViewBounds().size(), | |
493 base::Bind(&NavigationControllerImpl::TakingScreenshotComplete, | |
494 base::Unretained(this), | |
495 active_entry, | |
496 base::Owned(temp_bitmap)), | |
497 temp_bitmap); | |
498 } | |
499 | |
500 void NavigationControllerImpl::TakingScreenshotComplete( | |
501 NavigationEntryImpl* entry, | |
502 skia::PlatformBitmap* bitmap, | |
503 bool success) { | |
504 int index = GetIndexOfEntry(entry); | |
505 if (index < 0) { | |
506 LOG(ERROR) << "Invalid entry"; | |
507 return; | |
508 } | |
509 | |
510 if (!success) { | |
511 LOG(ERROR) << "Taking snapshot was unsuccessful for " | |
512 << entry->GetURL().spec(); | |
513 return; | |
514 } | |
515 | |
516 std::vector<unsigned char> data; | |
517 if (gfx::PNGCodec::EncodeBGRASkBitmap(bitmap->GetBitmap(), true, &data)) | |
518 entry->SetScreenshotPNGData(data); | |
519 } | |
520 | |
473 bool NavigationControllerImpl::CanGoBack() const { | 521 bool NavigationControllerImpl::CanGoBack() const { |
474 return entries_.size() > 1 && GetCurrentEntryIndex() > 0; | 522 return entries_.size() > 1 && GetCurrentEntryIndex() > 0; |
475 } | 523 } |
476 | 524 |
477 bool NavigationControllerImpl::CanGoForward() const { | 525 bool NavigationControllerImpl::CanGoForward() const { |
478 int index = GetCurrentEntryIndex(); | 526 int index = GetCurrentEntryIndex(); |
479 return index >= 0 && index < (static_cast<int>(entries_.size()) - 1); | 527 return index >= 0 && index < (static_cast<int>(entries_.size()) - 1); |
480 } | 528 } |
481 | 529 |
482 bool NavigationControllerImpl::CanGoToOffset(int offset) const { | 530 bool NavigationControllerImpl::CanGoToOffset(int offset) const { |
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1434 DCHECK_EQ(max_entry_count(), entries_.size()); | 1482 DCHECK_EQ(max_entry_count(), entries_.size()); |
1435 DCHECK(last_committed_entry_index_ > 0); | 1483 DCHECK(last_committed_entry_index_ > 0); |
1436 RemoveEntryAtIndex(0); | 1484 RemoveEntryAtIndex(0); |
1437 NotifyPrunedEntries(this, true, 1); | 1485 NotifyPrunedEntries(this, true, 1); |
1438 } | 1486 } |
1439 } | 1487 } |
1440 | 1488 |
1441 void NavigationControllerImpl::NavigateToPendingEntry(ReloadType reload_type) { | 1489 void NavigationControllerImpl::NavigateToPendingEntry(ReloadType reload_type) { |
1442 needs_reload_ = false; | 1490 needs_reload_ = false; |
1443 | 1491 |
1492 TakeScreenshot(); | |
sadrul
2012/12/21 17:17:41
Calling this here seems to work only for navigatio
| |
1493 | |
1444 // If we were navigating to a slow-to-commit page, and the user performs | 1494 // 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 | 1495 // a session history navigation to the last committed page, RenderViewHost |
1446 // will force the throbber to start, but WebKit will essentially ignore the | 1496 // 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 | 1497 // 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 | 1498 // from happening, we drop the navigation here and stop the slow-to-commit |
1449 // page from loading (which would normally happen during the navigation). | 1499 // page from loading (which would normally happen during the navigation). |
1450 if (pending_entry_index_ != -1 && | 1500 if (pending_entry_index_ != -1 && |
1451 pending_entry_index_ == last_committed_entry_index_ && | 1501 pending_entry_index_ == last_committed_entry_index_ && |
1452 (entries_[pending_entry_index_]->restore_type() == | 1502 (entries_[pending_entry_index_]->restore_type() == |
1453 NavigationEntryImpl::RESTORE_NONE) && | 1503 NavigationEntryImpl::RESTORE_NONE) && |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1609 } | 1659 } |
1610 } | 1660 } |
1611 } | 1661 } |
1612 | 1662 |
1613 void NavigationControllerImpl::SetGetTimestampCallbackForTest( | 1663 void NavigationControllerImpl::SetGetTimestampCallbackForTest( |
1614 const base::Callback<base::Time()>& get_timestamp_callback) { | 1664 const base::Callback<base::Time()>& get_timestamp_callback) { |
1615 get_timestamp_callback_ = get_timestamp_callback; | 1665 get_timestamp_callback_ = get_timestamp_callback; |
1616 } | 1666 } |
1617 | 1667 |
1618 } // namespace content | 1668 } // namespace content |
OLD | NEW |