| 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 "content/browser/frame_host/navigation_entry_screenshot_manager.h" | 5 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/task_scheduler/post_task.h" | 9 #include "base/task_scheduler/post_task.h" |
| 10 #include "content/browser/frame_host/navigation_controller_impl.h" | 10 #include "content/browser/frame_host/navigation_controller_impl.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 return; | 76 return; |
| 77 | 77 |
| 78 NavigationEntryImpl* entry = owner_->GetLastCommittedEntry(); | 78 NavigationEntryImpl* entry = owner_->GetLastCommittedEntry(); |
| 79 if (!entry) | 79 if (!entry) |
| 80 return; | 80 return; |
| 81 | 81 |
| 82 if (!owner_->delegate()->CanOverscrollContent()) | 82 if (!owner_->delegate()->CanOverscrollContent()) |
| 83 return; | 83 return; |
| 84 | 84 |
| 85 RenderViewHost* render_view_host = owner_->delegate()->GetRenderViewHost(); | 85 RenderViewHost* render_view_host = owner_->delegate()->GetRenderViewHost(); |
| 86 DCHECK(render_view_host && render_view_host->GetWidget()); |
| 86 content::RenderWidgetHostView* view = | 87 content::RenderWidgetHostView* view = |
| 87 render_view_host->GetWidget()->GetView(); | 88 render_view_host->GetWidget()->GetView(); |
| 88 if (!view) | 89 if (!view) |
| 89 return; | 90 return; |
| 90 | 91 |
| 91 // Make sure screenshots aren't taken too frequently. | 92 // Make sure screenshots aren't taken too frequently. |
| 92 base::Time now = base::Time::Now(); | 93 base::Time now = base::Time::Now(); |
| 93 if (now - last_screenshot_time_ < | 94 if (now - last_screenshot_time_ < |
| 94 base::TimeDelta::FromMilliseconds(min_screenshot_interval_ms_)) { | 95 base::TimeDelta::FromMilliseconds(min_screenshot_interval_ms_)) { |
| 95 return; | 96 return; |
| 96 } | 97 } |
| 97 | 98 |
| 99 WillTakeScreenshot(render_view_host); |
| 100 |
| 98 last_screenshot_time_ = now; | 101 last_screenshot_time_ = now; |
| 99 | 102 |
| 100 TakeScreenshotImpl(render_view_host, entry); | 103 // This screenshot is destined for the UI, so size the result to the actual |
| 104 // on-screen size of the view (and not its device-rendering size). |
| 105 const gfx::Size view_size_on_screen = view->GetViewBounds().size(); |
| 106 view->CopyFromSurface( |
| 107 gfx::Rect(), view_size_on_screen, |
| 108 base::Bind(&NavigationEntryScreenshotManager::OnScreenshotTaken, |
| 109 screenshot_factory_.GetWeakPtr(), entry->GetUniqueID()), |
| 110 kAlpha_8_SkColorType); |
| 101 } | 111 } |
| 102 | 112 |
| 103 // Implemented here and not in NavigationEntry because this manager keeps track | 113 // Implemented here and not in NavigationEntry because this manager keeps track |
| 104 // of the total number of screen shots across all entries. | 114 // of the total number of screen shots across all entries. |
| 105 void NavigationEntryScreenshotManager::ClearAllScreenshots() { | 115 void NavigationEntryScreenshotManager::ClearAllScreenshots() { |
| 106 int count = owner_->GetEntryCount(); | 116 int count = owner_->GetEntryCount(); |
| 107 for (int i = 0; i < count; ++i) { | 117 for (int i = 0; i < count; ++i) { |
| 108 ClearScreenshot(owner_->GetEntryAtIndex(i)); | 118 ClearScreenshot(owner_->GetEntryAtIndex(i)); |
| 109 } | 119 } |
| 110 DCHECK_EQ(GetScreenshotCount(), 0); | 120 DCHECK_EQ(GetScreenshotCount(), 0); |
| 111 } | 121 } |
| 112 | 122 |
| 113 void NavigationEntryScreenshotManager::TakeScreenshotImpl( | |
| 114 RenderViewHost* host, | |
| 115 NavigationEntryImpl* entry) { | |
| 116 DCHECK(host && host->GetWidget()->GetView()); | |
| 117 DCHECK(entry); | |
| 118 host->GetWidget()->CopyFromBackingStore( | |
| 119 gfx::Rect(), host->GetWidget()->GetView()->GetViewBounds().size(), | |
| 120 base::Bind(&NavigationEntryScreenshotManager::OnScreenshotTaken, | |
| 121 screenshot_factory_.GetWeakPtr(), entry->GetUniqueID()), | |
| 122 kAlpha_8_SkColorType); | |
| 123 } | |
| 124 | |
| 125 void NavigationEntryScreenshotManager::SetMinScreenshotIntervalMS( | 123 void NavigationEntryScreenshotManager::SetMinScreenshotIntervalMS( |
| 126 int interval_ms) { | 124 int interval_ms) { |
| 127 DCHECK_GE(interval_ms, 0); | 125 DCHECK_GE(interval_ms, 0); |
| 128 min_screenshot_interval_ms_ = interval_ms; | 126 min_screenshot_interval_ms_ = interval_ms; |
| 129 } | 127 } |
| 130 | 128 |
| 131 void NavigationEntryScreenshotManager::OnScreenshotTaken( | 129 void NavigationEntryScreenshotManager::OnScreenshotTaken( |
| 132 int unique_id, | 130 int unique_id, |
| 133 const SkBitmap& bitmap, | 131 const SkBitmap& bitmap, |
| 134 ReadbackResponse response) { | 132 ReadbackResponse response) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 NavigationEntryImpl* entry = owner_->GetEntryAtIndex(forward); | 241 NavigationEntryImpl* entry = owner_->GetEntryAtIndex(forward); |
| 244 if (ClearScreenshot(entry)) | 242 if (ClearScreenshot(entry)) |
| 245 --screenshot_count; | 243 --screenshot_count; |
| 246 ++forward; | 244 ++forward; |
| 247 } | 245 } |
| 248 CHECK_GE(screenshot_count, 0); | 246 CHECK_GE(screenshot_count, 0); |
| 249 CHECK_LE(screenshot_count, kMaxScreenshots); | 247 CHECK_LE(screenshot_count, kMaxScreenshots); |
| 250 } | 248 } |
| 251 | 249 |
| 252 } // namespace content | 250 } // namespace content |
| OLD | NEW |