| 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 #ifndef CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ | 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ |
| 6 #define CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ | 6 #define CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 class PlatformCanvas; | 38 class PlatformCanvas; |
| 39 } | 39 } |
| 40 | 40 |
| 41 class ThumbnailGenerator : public content::NotificationObserver, | 41 class ThumbnailGenerator : public content::NotificationObserver, |
| 42 public content::WebContentsObserver { | 42 public content::WebContentsObserver { |
| 43 public: | 43 public: |
| 44 typedef base::Callback<void(const SkBitmap&)> ThumbnailReadyCallback; | 44 typedef base::Callback<void(const SkBitmap&)> ThumbnailReadyCallback; |
| 45 // The result of clipping. This can be used to determine if the | 45 // The result of clipping. This can be used to determine if the |
| 46 // generated thumbnail is good or not. | 46 // generated thumbnail is good or not. |
| 47 enum ClipResult { | 47 enum ClipResult { |
| 48 // Clipping is not done yet. |
| 49 kUnprocessed, |
| 48 // The source image is smaller. | 50 // The source image is smaller. |
| 49 kSourceIsSmaller, | 51 kSourceIsSmaller, |
| 50 // Wider than tall by twice or more, clip horizontally. | 52 // Wider than tall by twice or more, clip horizontally. |
| 51 kTooWiderThanTall, | 53 kTooWiderThanTall, |
| 52 // Wider than tall, clip horizontally. | 54 // Wider than tall, clip horizontally. |
| 53 kWiderThanTall, | 55 kWiderThanTall, |
| 54 // Taller than wide, clip vertically. | 56 // Taller than wide, clip vertically. |
| 55 kTallerThanWide, | 57 kTallerThanWide, |
| 56 // The source and destination aspect ratios are identical. | 58 // The source and destination aspect ratios are identical. |
| 57 kNotClipped, | 59 kNotClipped, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 int desired_width, | 108 int desired_width, |
| 107 int desired_height, | 109 int desired_height, |
| 108 ClipResult* clip_result); | 110 ClipResult* clip_result); |
| 109 | 111 |
| 110 // Update the thumbnail of the given tab contents if necessary. | 112 // Update the thumbnail of the given tab contents if necessary. |
| 111 void UpdateThumbnailIfNecessary(content::WebContents* webb_contents); | 113 void UpdateThumbnailIfNecessary(content::WebContents* webb_contents); |
| 112 | 114 |
| 113 // Update the thumbnail of the given tab. | 115 // Update the thumbnail of the given tab. |
| 114 void UpdateThumbnail(content::WebContents* web_contents, | 116 void UpdateThumbnail(content::WebContents* web_contents, |
| 115 const SkBitmap& bitmap, | 117 const SkBitmap& bitmap, |
| 116 const ThumbnailGenerator::ClipResult& clip_result); | 118 const ClipResult& clip_result); |
| 117 | 119 |
| 118 // Returns true if we should update the thumbnail of the given URL. | 120 // Returns true if we should update the thumbnail of the given URL. |
| 119 static bool ShouldUpdateThumbnail(Profile* profile, | 121 static bool ShouldUpdateThumbnail(Profile* profile, |
| 120 history::TopSites* top_sites, | 122 history::TopSites* top_sites, |
| 121 const GURL& url); | 123 const GURL& url); |
| 122 | 124 |
| 123 // content::WebContentsObserver overrides. | 125 // content::WebContentsObserver overrides. |
| 124 virtual void DidStartLoading( | 126 virtual void DidStartLoading( |
| 125 content::RenderViewHost* render_view_host) OVERRIDE; | 127 content::RenderViewHost* render_view_host) OVERRIDE; |
| 126 virtual void StopNavigation() OVERRIDE; | 128 virtual void StopNavigation() OVERRIDE; |
| 127 | 129 |
| 128 private: | 130 private: |
| 129 virtual void WidgetDidReceivePaintAtSizeAck( | 131 virtual void WidgetDidReceivePaintAtSizeAck( |
| 130 content::RenderWidgetHost* widget, | 132 content::RenderWidgetHost* widget, |
| 131 int tag, | 133 int tag, |
| 132 const gfx::Size& size); | 134 const gfx::Size& size); |
| 133 | 135 |
| 134 // Asynchronously updates the thumbnail of the given tab. The caller must | 136 // Asynchronously updates the thumbnail of the given tab. The caller must |
| 135 // ensure that |web_contents| outlives ThumbnailGenerator so that the | 137 // ensure that |web_contents| outlives ThumbnailGenerator so that the |
| 136 // asynchronous callback can accesses |web_contents|. This must be called on | 138 // asynchronous callback can accesses |web_contents|. This must be called on |
| 137 // the UI thread. | 139 // the UI thread. |
| 138 void AsyncUpdateThumbnail(content::WebContents* web_contents); | 140 void AsyncUpdateThumbnail(content::WebContents* web_contents); |
| 139 | 141 |
| 140 // Called when the bitmap for generating a thumbnail is ready after the | 142 // Called when the bitmap for generating a thumbnail is ready after the |
| 141 // AsyncUpdateThumbnail invocation. This runs on the UI thread. | 143 // AsyncUpdateThumbnail invocation. This runs on the UI thread. |
| 142 void UpdateThumbnailWithBitmap( | 144 void UpdateThumbnailWithBitmap( |
| 143 content::WebContents* web_contents, | 145 content::WebContents* web_contents, |
| 146 ClipResult clip_result, |
| 144 const SkBitmap& bitmap); | 147 const SkBitmap& bitmap); |
| 145 | 148 |
| 146 // Called when the canvas for generating a thumbnail is ready after the | 149 // Called when the canvas for generating a thumbnail is ready after the |
| 147 // AsyncUpdateThumbnail invocation. This runs on the UI thread. | 150 // AsyncUpdateThumbnail invocation. This runs on the UI thread. |
| 148 void UpdateThumbnailWithCanvas( | 151 void UpdateThumbnailWithCanvas( |
| 149 content::WebContents* web_contents, | 152 content::WebContents* web_contents, |
| 153 ClipResult clip_result, |
| 150 skia::PlatformCanvas* temp_canvas, | 154 skia::PlatformCanvas* temp_canvas, |
| 151 bool result); | 155 bool result); |
| 152 | 156 |
| 153 // content::NotificationObserver interface. | 157 // content::NotificationObserver interface. |
| 154 virtual void Observe(int type, | 158 virtual void Observe(int type, |
| 155 const content::NotificationSource& source, | 159 const content::NotificationSource& source, |
| 156 const content::NotificationDetails& details) OVERRIDE; | 160 const content::NotificationDetails& details) OVERRIDE; |
| 157 | 161 |
| 158 // Indicates that the given widget has changed is visibility. | 162 // Indicates that the given widget has changed is visibility. |
| 159 void WidgetHidden(content::RenderWidgetHost* widget); | 163 void WidgetHidden(content::RenderWidgetHost* widget); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 172 ThumbnailCallbackMap callback_map_; | 176 ThumbnailCallbackMap callback_map_; |
| 173 | 177 |
| 174 bool load_interrupted_; | 178 bool load_interrupted_; |
| 175 | 179 |
| 176 base::WeakPtrFactory<ThumbnailGenerator> weak_factory_; | 180 base::WeakPtrFactory<ThumbnailGenerator> weak_factory_; |
| 177 | 181 |
| 178 DISALLOW_COPY_AND_ASSIGN(ThumbnailGenerator); | 182 DISALLOW_COPY_AND_ASSIGN(ThumbnailGenerator); |
| 179 }; | 183 }; |
| 180 | 184 |
| 181 #endif // CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ | 185 #endif // CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ |
| OLD | NEW |