| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/tab_contents/thumbnail_generator.h" | 5 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } | 139 } |
| 140 | 140 |
| 141 void ThumbnailGenerator::StartThumbnailing(TabContents* tab_contents) { | 141 void ThumbnailGenerator::StartThumbnailing(TabContents* tab_contents) { |
| 142 TabContentsObserver::Observe(tab_contents); | 142 TabContentsObserver::Observe(tab_contents); |
| 143 | 143 |
| 144 if (registrar_.IsEmpty()) { | 144 if (registrar_.IsEmpty()) { |
| 145 // Even though we deal in RenderWidgetHosts, we only care about its | 145 // Even though we deal in RenderWidgetHosts, we only care about its |
| 146 // subclass, RenderViewHost when it is in a tab. We don't make thumbnails | 146 // subclass, RenderViewHost when it is in a tab. We don't make thumbnails |
| 147 // for RenderViewHosts that aren't in tabs, or RenderWidgetHosts that | 147 // for RenderViewHosts that aren't in tabs, or RenderWidgetHosts that |
| 148 // aren't views like select popups. | 148 // aren't views like select popups. |
| 149 registrar_.Add(this, NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB, | 149 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, |
| 150 Source<TabContents>(tab_contents)); | 150 Source<TabContents>(tab_contents)); |
| 151 registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED, | 151 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, |
| 152 Source<TabContents>(tab_contents)); | 152 Source<TabContents>(tab_contents)); |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 | 155 |
| 156 void ThumbnailGenerator::MonitorRenderer(RenderWidgetHost* renderer, | 156 void ThumbnailGenerator::MonitorRenderer(RenderWidgetHost* renderer, |
| 157 bool monitor) { | 157 bool monitor) { |
| 158 Source<RenderWidgetHost> renderer_source = Source<RenderWidgetHost>(renderer); | 158 Source<RenderWidgetHost> renderer_source = Source<RenderWidgetHost>(renderer); |
| 159 bool currently_monitored = | 159 bool currently_monitored = |
| 160 registrar_.IsRegistered( | 160 registrar_.IsRegistered( |
| 161 this, | 161 this, |
| 162 NotificationType::RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK, | 162 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK, |
| 163 renderer_source); | 163 renderer_source); |
| 164 if (monitor != currently_monitored) { | 164 if (monitor != currently_monitored) { |
| 165 if (monitor) { | 165 if (monitor) { |
| 166 registrar_.Add( | 166 registrar_.Add( |
| 167 this, | 167 this, |
| 168 NotificationType::RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK, | 168 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK
, |
| 169 renderer_source); | 169 renderer_source); |
| 170 registrar_.Add( | 170 registrar_.Add( |
| 171 this, | 171 this, |
| 172 NotificationType::RENDER_WIDGET_VISIBILITY_CHANGED, | 172 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
| 173 renderer_source); | 173 renderer_source); |
| 174 } else { | 174 } else { |
| 175 registrar_.Remove( | 175 registrar_.Remove( |
| 176 this, | 176 this, |
| 177 NotificationType::RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK, | 177 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK
, |
| 178 renderer_source); | 178 renderer_source); |
| 179 registrar_.Remove( | 179 registrar_.Remove( |
| 180 this, | 180 this, |
| 181 NotificationType::RENDER_WIDGET_VISIBILITY_CHANGED, | 181 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
| 182 renderer_source); | 182 renderer_source); |
| 183 } | 183 } |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 | 186 |
| 187 void ThumbnailGenerator::AskForSnapshot(RenderWidgetHost* renderer, | 187 void ThumbnailGenerator::AskForSnapshot(RenderWidgetHost* renderer, |
| 188 bool prefer_backing_store, | 188 bool prefer_backing_store, |
| 189 ThumbnailReadyCallback* callback, | 189 ThumbnailReadyCallback* callback, |
| 190 gfx::Size page_size, | 190 gfx::Size page_size, |
| 191 gfx::Size desired_size) { | 191 gfx::Size desired_size) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 // TODO: Figure out a way to avoid this copy? | 300 // TODO: Figure out a way to avoid this copy? |
| 301 non_owned_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config); | 301 non_owned_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config); |
| 302 | 302 |
| 303 item->second->callback->Run(result); | 303 item->second->callback->Run(result); |
| 304 | 304 |
| 305 // We're done with the callback, and with the DIB, so delete both. | 305 // We're done with the callback, and with the DIB, so delete both. |
| 306 callback_map_.erase(item); | 306 callback_map_.erase(item); |
| 307 } | 307 } |
| 308 } | 308 } |
| 309 | 309 |
| 310 void ThumbnailGenerator::Observe(NotificationType type, | 310 void ThumbnailGenerator::Observe(int type, |
| 311 const NotificationSource& source, | 311 const NotificationSource& source, |
| 312 const NotificationDetails& details) { | 312 const NotificationDetails& details) { |
| 313 switch (type.value) { | 313 switch (type) { |
| 314 case NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB: { | 314 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { |
| 315 // Install our observer for all new RVHs. | 315 // Install our observer for all new RVHs. |
| 316 RenderViewHost* renderer = Details<RenderViewHost>(details).ptr(); | 316 RenderViewHost* renderer = Details<RenderViewHost>(details).ptr(); |
| 317 MonitorRenderer(renderer, true); | 317 MonitorRenderer(renderer, true); |
| 318 break; | 318 break; |
| 319 } | 319 } |
| 320 | 320 |
| 321 case NotificationType::RENDER_WIDGET_VISIBILITY_CHANGED: | 321 case content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED: |
| 322 if (!*Details<bool>(details).ptr()) | 322 if (!*Details<bool>(details).ptr()) |
| 323 WidgetHidden(Source<RenderWidgetHost>(source).ptr()); | 323 WidgetHidden(Source<RenderWidgetHost>(source).ptr()); |
| 324 break; | 324 break; |
| 325 | 325 |
| 326 case NotificationType::RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK: { | 326 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK:
{ |
| 327 RenderWidgetHost::PaintAtSizeAckDetails* size_ack_details = | 327 RenderWidgetHost::PaintAtSizeAckDetails* size_ack_details = |
| 328 Details<RenderWidgetHost::PaintAtSizeAckDetails>(details).ptr(); | 328 Details<RenderWidgetHost::PaintAtSizeAckDetails>(details).ptr(); |
| 329 WidgetDidReceivePaintAtSizeAck( | 329 WidgetDidReceivePaintAtSizeAck( |
| 330 Source<RenderWidgetHost>(source).ptr(), | 330 Source<RenderWidgetHost>(source).ptr(), |
| 331 size_ack_details->tag, | 331 size_ack_details->tag, |
| 332 size_ack_details->size); | 332 size_ack_details->size); |
| 333 break; | 333 break; |
| 334 } | 334 } |
| 335 | 335 |
| 336 case NotificationType::TAB_CONTENTS_DISCONNECTED: | 336 case content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED: |
| 337 TabContentsDisconnected(Source<TabContents>(source).ptr()); | 337 TabContentsDisconnected(Source<TabContents>(source).ptr()); |
| 338 break; | 338 break; |
| 339 | 339 |
| 340 default: | 340 default: |
| 341 NOTREACHED() << "Unexpected notification type: " << type.value; | 341 NOTREACHED() << "Unexpected notification type: " << type; |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 | 344 |
| 345 void ThumbnailGenerator::WidgetHidden(RenderWidgetHost* widget) { | 345 void ThumbnailGenerator::WidgetHidden(RenderWidgetHost* widget) { |
| 346 // tab_contents_ can be NULL, if StartThumbnailing() is not called, but | 346 // tab_contents_ can be NULL, if StartThumbnailing() is not called, but |
| 347 // MonitorRenderer() is called. The use case is found in | 347 // MonitorRenderer() is called. The use case is found in |
| 348 // chrome/test/ui_test_utils.cc. | 348 // chrome/test/ui_test_utils.cc. |
| 349 if (!tab_contents()) | 349 if (!tab_contents()) |
| 350 return; | 350 return; |
| 351 UpdateThumbnailIfNecessary(tab_contents()); | 351 UpdateThumbnailIfNecessary(tab_contents()); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 | 489 |
| 490 void ThumbnailGenerator::DidStartLoading() { | 490 void ThumbnailGenerator::DidStartLoading() { |
| 491 load_interrupted_ = false; | 491 load_interrupted_ = false; |
| 492 } | 492 } |
| 493 | 493 |
| 494 void ThumbnailGenerator::StopNavigation() { | 494 void ThumbnailGenerator::StopNavigation() { |
| 495 // This function gets called when the page loading is interrupted by the | 495 // This function gets called when the page loading is interrupted by the |
| 496 // stop button. | 496 // stop button. |
| 497 load_interrupted_ = true; | 497 load_interrupted_ = true; |
| 498 } | 498 } |
| OLD | NEW |