| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/tab_first_render_watcher.h" | |
| 6 | |
| 7 #include "content/browser/renderer_host/render_widget_host.h" | |
| 8 #include "content/browser/renderer_host/render_view_host.h" | |
| 9 #include "content/public/browser/notification_details.h" | |
| 10 #include "content/public/browser/notification_source.h" | |
| 11 #include "content/public/browser/notification_types.h" | |
| 12 #include "content/public/browser/web_contents.h" | |
| 13 | |
| 14 using content::WebContents; | |
| 15 | |
| 16 TabFirstRenderWatcher::TabFirstRenderWatcher(WebContents* tab, | |
| 17 Delegate* delegate) | |
| 18 : state_(NONE), | |
| 19 web_contents_(tab), | |
| 20 delegate_(delegate) { | |
| 21 registrar_.Add(this, | |
| 22 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, | |
| 23 content::Source<WebContents>(web_contents_)); | |
| 24 registrar_.Add(this, | |
| 25 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 26 content::Source<WebContents>(web_contents_)); | |
| 27 } | |
| 28 | |
| 29 void TabFirstRenderWatcher::Observe(int type, | |
| 30 const content::NotificationSource& source, | |
| 31 const content::NotificationDetails& details) { | |
| 32 switch (type) { | |
| 33 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { | |
| 34 RenderWidgetHost* rwh = content::Details<RenderWidgetHost>(details).ptr(); | |
| 35 registrar_.Add(this, | |
| 36 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT, | |
| 37 content::Source<RenderWidgetHost>(rwh)); | |
| 38 delegate_->OnRenderHostCreated( | |
| 39 content::Details<RenderViewHost>(details).ptr()); | |
| 40 break; | |
| 41 } | |
| 42 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: | |
| 43 if (state_ == NONE) { | |
| 44 state_ = LOADED; | |
| 45 delegate_->OnTabMainFrameLoaded(); | |
| 46 } | |
| 47 break; | |
| 48 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: | |
| 49 if (state_ == LOADED) { | |
| 50 state_ = FIRST_PAINT; | |
| 51 delegate_->OnTabMainFrameFirstRender(); | |
| 52 } | |
| 53 break; | |
| 54 default: | |
| 55 NOTREACHED() << "unknown type" << type; | |
| 56 } | |
| 57 } | |
| OLD | NEW |