| 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 |
| 98 last_screenshot_time_ = now; | 99 last_screenshot_time_ = now; |
| 99 | 100 |
| 100 TakeScreenshotImpl(render_view_host, entry); | 101 // This screenshot is destined for the UI, so size the result to the actual |
| 102 // on-screen size of the view (and not its device-rendering size). |
| 103 const gfx::Size view_size_on_screen = view->GetViewBounds().size(); |
| 104 view->CopyFromSurface( |
| 105 gfx::Rect(), view_size_on_screen, |
| 106 base::Bind(&NavigationEntryScreenshotManager::OnScreenshotTaken, |
| 107 screenshot_factory_.GetWeakPtr(), entry->GetUniqueID()), |
| 108 kAlpha_8_SkColorType); |
| 101 } | 109 } |
| 102 | 110 |
| 103 // Implemented here and not in NavigationEntry because this manager keeps track | 111 // Implemented here and not in NavigationEntry because this manager keeps track |
| 104 // of the total number of screen shots across all entries. | 112 // of the total number of screen shots across all entries. |
| 105 void NavigationEntryScreenshotManager::ClearAllScreenshots() { | 113 void NavigationEntryScreenshotManager::ClearAllScreenshots() { |
| 106 int count = owner_->GetEntryCount(); | 114 int count = owner_->GetEntryCount(); |
| 107 for (int i = 0; i < count; ++i) { | 115 for (int i = 0; i < count; ++i) { |
| 108 ClearScreenshot(owner_->GetEntryAtIndex(i)); | 116 ClearScreenshot(owner_->GetEntryAtIndex(i)); |
| 109 } | 117 } |
| 110 DCHECK_EQ(GetScreenshotCount(), 0); | 118 DCHECK_EQ(GetScreenshotCount(), 0); |
| 111 } | 119 } |
| 112 | 120 |
| 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( | 121 void NavigationEntryScreenshotManager::SetMinScreenshotIntervalMS( |
| 126 int interval_ms) { | 122 int interval_ms) { |
| 127 DCHECK_GE(interval_ms, 0); | 123 DCHECK_GE(interval_ms, 0); |
| 128 min_screenshot_interval_ms_ = interval_ms; | 124 min_screenshot_interval_ms_ = interval_ms; |
| 129 } | 125 } |
| 130 | 126 |
| 131 void NavigationEntryScreenshotManager::OnScreenshotTaken( | 127 void NavigationEntryScreenshotManager::OnScreenshotTaken( |
| 132 int unique_id, | 128 int unique_id, |
| 133 const SkBitmap& bitmap, | 129 const SkBitmap& bitmap, |
| 134 ReadbackResponse response) { | 130 ReadbackResponse response) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 NavigationEntryImpl* entry = owner_->GetEntryAtIndex(forward); | 239 NavigationEntryImpl* entry = owner_->GetEntryAtIndex(forward); |
| 244 if (ClearScreenshot(entry)) | 240 if (ClearScreenshot(entry)) |
| 245 --screenshot_count; | 241 --screenshot_count; |
| 246 ++forward; | 242 ++forward; |
| 247 } | 243 } |
| 248 CHECK_GE(screenshot_count, 0); | 244 CHECK_GE(screenshot_count, 0); |
| 249 CHECK_LE(screenshot_count, kMaxScreenshots); | 245 CHECK_LE(screenshot_count, kMaxScreenshots); |
| 250 } | 246 } |
| 251 | 247 |
| 252 } // namespace content | 248 } // namespace content |
| OLD | NEW |