| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
| 15 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
| 16 #include "base/timer.h" | 16 #include "base/timer.h" |
| 17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/public/browser/web_contents_observer.h" | 19 #include "content/public/browser/web_contents_observer.h" |
| 20 | 20 |
| 21 class GURL; | 21 class GURL; |
| 22 class Profile; | 22 class Profile; |
| 23 class SkBitmap; |
| 24 |
| 25 namespace content { |
| 23 class RenderWidgetHost; | 26 class RenderWidgetHost; |
| 24 class SkBitmap; | 27 } |
| 25 | 28 |
| 26 namespace gfx { | 29 namespace gfx { |
| 27 class Size; | 30 class Size; |
| 28 } | 31 } |
| 29 | 32 |
| 30 namespace history { | 33 namespace history { |
| 31 class TopSites; | 34 class TopSites; |
| 32 } | 35 } |
| 33 | 36 |
| 34 class ThumbnailGenerator : public content::NotificationObserver, | 37 class ThumbnailGenerator : public content::NotificationObserver, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // Takes ownership of the callback object. | 76 // Takes ownership of the callback object. |
| 74 // | 77 // |
| 75 // If |prefer_backing_store| is set, then the function will try and | 78 // If |prefer_backing_store| is set, then the function will try and |
| 76 // use the backing store for the page if it exists. |page_size| is | 79 // use the backing store for the page if it exists. |page_size| is |
| 77 // the size to render the page, and |desired_size| is the size to | 80 // the size to render the page, and |desired_size| is the size to |
| 78 // scale the resulting rendered page to (which is done efficiently | 81 // scale the resulting rendered page to (which is done efficiently |
| 79 // if done in the rendering thread). If |prefer_backing_store| is | 82 // if done in the rendering thread). If |prefer_backing_store| is |
| 80 // set, and the backing store is used, then the resulting image will | 83 // set, and the backing store is used, then the resulting image will |
| 81 // be less then twice the size of the |desired_size| in both | 84 // be less then twice the size of the |desired_size| in both |
| 82 // dimensions, but might not be the exact size requested. | 85 // dimensions, but might not be the exact size requested. |
| 83 void AskForSnapshot(RenderWidgetHost* renderer, | 86 void AskForSnapshot(content::RenderWidgetHost* renderer, |
| 84 bool prefer_backing_store, | 87 bool prefer_backing_store, |
| 85 const ThumbnailReadyCallback& callback, | 88 const ThumbnailReadyCallback& callback, |
| 86 gfx::Size page_size, | 89 gfx::Size page_size, |
| 87 gfx::Size desired_size); | 90 gfx::Size desired_size); |
| 88 | 91 |
| 89 // This returns a thumbnail of a fixed, small size for the given | 92 // This returns a thumbnail of a fixed, small size for the given |
| 90 // renderer. | 93 // renderer. |
| 91 SkBitmap GetThumbnailForRenderer(RenderWidgetHost* renderer) const; | 94 SkBitmap GetThumbnailForRenderer(content::RenderWidgetHost* renderer) const; |
| 92 | 95 |
| 93 // This returns a thumbnail of a fixed, small size for the given | 96 // This returns a thumbnail of a fixed, small size for the given |
| 94 // renderer. |options| is a bitmask of ThumbnailOptions. If | 97 // renderer. |options| is a bitmask of ThumbnailOptions. If |
| 95 // |clip_result| is non-NULL, the result of clipping will be written. | 98 // |clip_result| is non-NULL, the result of clipping will be written. |
| 96 SkBitmap GetThumbnailForRendererWithOptions(RenderWidgetHost* renderer, | 99 SkBitmap GetThumbnailForRendererWithOptions( |
| 97 int options, | 100 content::RenderWidgetHost* renderer, |
| 98 ClipResult* clip_result) const; | 101 int options, |
| 102 ClipResult* clip_result) const; |
| 99 | 103 |
| 100 // Start or stop monitoring notifications for |renderer| based on the value | 104 // Start or stop monitoring notifications for |renderer| based on the value |
| 101 // of |monitor|. | 105 // of |monitor|. |
| 102 void MonitorRenderer(RenderWidgetHost* renderer, bool monitor); | 106 void MonitorRenderer(content::RenderWidgetHost* renderer, bool monitor); |
| 103 | 107 |
| 104 // Calculates how "boring" a thumbnail is. The boring score is the | 108 // Calculates how "boring" a thumbnail is. The boring score is the |
| 105 // 0,1 ranged percentage of pixels that are the most common | 109 // 0,1 ranged percentage of pixels that are the most common |
| 106 // luma. Higher boring scores indicate that a higher percentage of a | 110 // luma. Higher boring scores indicate that a higher percentage of a |
| 107 // bitmap are all the same brightness. | 111 // bitmap are all the same brightness. |
| 108 static double CalculateBoringScore(SkBitmap* bitmap); | 112 static double CalculateBoringScore(SkBitmap* bitmap); |
| 109 | 113 |
| 110 // Gets the clipped bitmap from |bitmap| per the aspect ratio of the | 114 // Gets the clipped bitmap from |bitmap| per the aspect ratio of the |
| 111 // desired width and the desired height. For instance, if the input | 115 // desired width and the desired height. For instance, if the input |
| 112 // bitmap is vertically long (ex. 400x900) and the desired size is | 116 // bitmap is vertically long (ex. 400x900) and the desired size is |
| (...skipping 15 matching lines...) Expand all Loading... |
| 128 static bool ShouldUpdateThumbnail(Profile* profile, | 132 static bool ShouldUpdateThumbnail(Profile* profile, |
| 129 history::TopSites* top_sites, | 133 history::TopSites* top_sites, |
| 130 const GURL& url); | 134 const GURL& url); |
| 131 | 135 |
| 132 // content::WebContentsObserver overrides. | 136 // content::WebContentsObserver overrides. |
| 133 virtual void DidStartLoading() OVERRIDE; | 137 virtual void DidStartLoading() OVERRIDE; |
| 134 virtual void StopNavigation() OVERRIDE; | 138 virtual void StopNavigation() OVERRIDE; |
| 135 | 139 |
| 136 private: | 140 private: |
| 137 virtual void WidgetDidReceivePaintAtSizeAck( | 141 virtual void WidgetDidReceivePaintAtSizeAck( |
| 138 RenderWidgetHost* widget, | 142 content::RenderWidgetHost* widget, |
| 139 int tag, | 143 int tag, |
| 140 const gfx::Size& size); | 144 const gfx::Size& size); |
| 141 | 145 |
| 142 // content::NotificationObserver interface. | 146 // content::NotificationObserver interface. |
| 143 virtual void Observe(int type, | 147 virtual void Observe(int type, |
| 144 const content::NotificationSource& source, | 148 const content::NotificationSource& source, |
| 145 const content::NotificationDetails& details) OVERRIDE; | 149 const content::NotificationDetails& details) OVERRIDE; |
| 146 | 150 |
| 147 // Indicates that the given widget has changed is visibility. | 151 // Indicates that the given widget has changed is visibility. |
| 148 void WidgetHidden(RenderWidgetHost* widget); | 152 void WidgetHidden(content::RenderWidgetHost* widget); |
| 149 | 153 |
| 150 // Called when the given web contents are disconnected (either | 154 // Called when the given web contents are disconnected (either |
| 151 // through being closed, or because the renderer is no longer there). | 155 // through being closed, or because the renderer is no longer there). |
| 152 void WebContentsDisconnected(content::WebContents* contents); | 156 void WebContentsDisconnected(content::WebContents* contents); |
| 153 | 157 |
| 154 content::NotificationRegistrar registrar_; | 158 content::NotificationRegistrar registrar_; |
| 155 | 159 |
| 156 // Map of callback objects by sequence number. | 160 // Map of callback objects by sequence number. |
| 157 struct AsyncRequestInfo; | 161 struct AsyncRequestInfo; |
| 158 typedef std::map<int, | 162 typedef std::map<int, |
| 159 linked_ptr<AsyncRequestInfo> > ThumbnailCallbackMap; | 163 linked_ptr<AsyncRequestInfo> > ThumbnailCallbackMap; |
| 160 ThumbnailCallbackMap callback_map_; | 164 ThumbnailCallbackMap callback_map_; |
| 161 | 165 |
| 162 bool load_interrupted_; | 166 bool load_interrupted_; |
| 163 | 167 |
| 164 DISALLOW_COPY_AND_ASSIGN(ThumbnailGenerator); | 168 DISALLOW_COPY_AND_ASSIGN(ThumbnailGenerator); |
| 165 }; | 169 }; |
| 166 | 170 |
| 167 #endif // CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ | 171 #endif // CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ |
| OLD | NEW |