| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "content/browser/frame_host/navigation_controller_impl.h" | 14 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 15 #include "content/browser/frame_host/navigation_entry_impl.h" | 15 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 16 #include "content/browser/frame_host/web_contents_screenshot_manager.h" | 16 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" |
| 17 #include "content/browser/renderer_host/test_render_view_host.h" | 17 #include "content/browser/renderer_host/test_render_view_host.h" |
| 18 #include "content/browser/site_instance_impl.h" | 18 #include "content/browser/site_instance_impl.h" |
| 19 #include "content/browser/web_contents/web_contents_impl.h" | 19 #include "content/browser/web_contents/web_contents_impl.h" |
| 20 #include "content/common/view_messages.h" | 20 #include "content/common/view_messages.h" |
| 21 #include "content/public/browser/navigation_details.h" | 21 #include "content/public/browser/navigation_details.h" |
| 22 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
| 23 #include "content/public/browser/notification_types.h" | 23 #include "content/public/browser/notification_types.h" |
| 24 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
| 25 #include "content/public/browser/web_contents_delegate.h" | 25 #include "content/public/browser/web_contents_delegate.h" |
| 26 #include "content/public/browser/web_contents_observer.h" | 26 #include "content/public/browser/web_contents_observer.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 57 a_bitmap.height() != b_bitmap.height()) { | 57 a_bitmap.height() != b_bitmap.height()) { |
| 58 return false; | 58 return false; |
| 59 } | 59 } |
| 60 SkAutoLockPixels a_bitmap_lock(a_bitmap); | 60 SkAutoLockPixels a_bitmap_lock(a_bitmap); |
| 61 SkAutoLockPixels b_bitmap_lock(b_bitmap); | 61 SkAutoLockPixels b_bitmap_lock(b_bitmap); |
| 62 return memcmp(a_bitmap.getPixels(), | 62 return memcmp(a_bitmap.getPixels(), |
| 63 b_bitmap.getPixels(), | 63 b_bitmap.getPixels(), |
| 64 a_bitmap.getSize()) == 0; | 64 a_bitmap.getSize()) == 0; |
| 65 } | 65 } |
| 66 | 66 |
| 67 class MockScreenshotManager : public content::WebContentsScreenshotManager { | 67 class MockScreenshotManager : public content::NavigationEntryScreenshotManager { |
| 68 public: | 68 public: |
| 69 explicit MockScreenshotManager(content::NavigationControllerImpl* owner) | 69 explicit MockScreenshotManager(content::NavigationControllerImpl* owner) |
| 70 : content::WebContentsScreenshotManager(owner), | 70 : content::NavigationEntryScreenshotManager(owner), |
| 71 encoding_screenshot_in_progress_(false) { | 71 encoding_screenshot_in_progress_(false) { |
| 72 } | 72 } |
| 73 | 73 |
| 74 virtual ~MockScreenshotManager() { | 74 virtual ~MockScreenshotManager() { |
| 75 } | 75 } |
| 76 | 76 |
| 77 void TakeScreenshotFor(content::NavigationEntryImpl* entry) { | 77 void TakeScreenshotFor(content::NavigationEntryImpl* entry) { |
| 78 SkBitmap bitmap; | 78 SkBitmap bitmap; |
| 79 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); | 79 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); |
| 80 bitmap.allocPixels(); | 80 bitmap.allocPixels(); |
| 81 bitmap.eraseRGB(0, 0, 0); | 81 bitmap.eraseRGB(0, 0, 0); |
| 82 encoding_screenshot_in_progress_ = true; | 82 encoding_screenshot_in_progress_ = true; |
| 83 OnScreenshotTaken(entry->GetUniqueID(), true, bitmap); | 83 OnScreenshotTaken(entry->GetUniqueID(), true, bitmap); |
| 84 WaitUntilScreenshotIsReady(); | 84 WaitUntilScreenshotIsReady(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 int GetScreenshotCount() { | 87 int GetScreenshotCount() { |
| 88 return content::WebContentsScreenshotManager::GetScreenshotCount(); | 88 return content::NavigationEntryScreenshotManager::GetScreenshotCount(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void WaitUntilScreenshotIsReady() { | 91 void WaitUntilScreenshotIsReady() { |
| 92 if (!encoding_screenshot_in_progress_) | 92 if (!encoding_screenshot_in_progress_) |
| 93 return; | 93 return; |
| 94 message_loop_runner_ = new content::MessageLoopRunner; | 94 message_loop_runner_ = new content::MessageLoopRunner; |
| 95 message_loop_runner_->Run(); | 95 message_loop_runner_->Run(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 private: | 98 private: |
| 99 // Overridden from content::WebContentsScreenshotManager: | 99 // Overridden from content::NavigationEntryScreenshotManager: |
| 100 virtual void TakeScreenshotImpl( | 100 virtual void TakeScreenshotImpl( |
| 101 content::RenderViewHost* host, | 101 content::RenderViewHost* host, |
| 102 content::NavigationEntryImpl* entry) OVERRIDE { | 102 content::NavigationEntryImpl* entry) OVERRIDE { |
| 103 } | 103 } |
| 104 | 104 |
| 105 virtual void OnScreenshotSet(content::NavigationEntryImpl* entry) OVERRIDE { | 105 virtual void OnScreenshotSet(content::NavigationEntryImpl* entry) OVERRIDE { |
| 106 encoding_screenshot_in_progress_ = false; | 106 encoding_screenshot_in_progress_ = false; |
| 107 WebContentsScreenshotManager::OnScreenshotSet(entry); | 107 NavigationEntryScreenshotManager::OnScreenshotSet(entry); |
| 108 if (message_loop_runner_.get()) | 108 if (message_loop_runner_.get()) |
| 109 message_loop_runner_->Quit(); | 109 message_loop_runner_->Quit(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 112 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 113 bool encoding_screenshot_in_progress_; | 113 bool encoding_screenshot_in_progress_; |
| 114 | 114 |
| 115 DISALLOW_COPY_AND_ASSIGN(MockScreenshotManager); | 115 DISALLOW_COPY_AND_ASSIGN(MockScreenshotManager); |
| 116 }; | 116 }; |
| 117 | 117 |
| (...skipping 3717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3835 EXPECT_EQ(1, controller.GetEntryCount()); | 3835 EXPECT_EQ(1, controller.GetEntryCount()); |
| 3836 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 3836 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
| 3837 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 3837 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 3838 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 3838 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 3839 EXPECT_FALSE(controller.CanGoBack()); | 3839 EXPECT_FALSE(controller.CanGoBack()); |
| 3840 EXPECT_FALSE(controller.CanGoForward()); | 3840 EXPECT_FALSE(controller.CanGoForward()); |
| 3841 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 3841 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
| 3842 } | 3842 } |
| 3843 | 3843 |
| 3844 } // namespace content | 3844 } // namespace content |
| OLD | NEW |