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