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/chromeos/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 | |
13 namespace chromeos { | |
14 | |
15 TabFirstRenderWatcher::TabFirstRenderWatcher(TabContents* tab, | |
16 Delegate* delegate) | |
17 : state_(NONE), | |
18 tab_contents_(tab), | |
19 delegate_(delegate) { | |
20 registrar_.Add(this, | |
21 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, | |
22 content::Source<TabContents>(tab_contents_)); | |
23 registrar_.Add(this, | |
24 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
25 content::Source<TabContents>(tab_contents_)); | |
26 } | |
27 | |
28 void TabFirstRenderWatcher::Observe(int type, | |
29 const content::NotificationSource& source, | |
30 const content::NotificationDetails& details) { | |
31 switch (type) { | |
32 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { | |
33 RenderWidgetHost* rwh = content::Details<RenderWidgetHost>(details).ptr(); | |
34 registrar_.Add(this, | |
35 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT, | |
36 content::Source<RenderWidgetHost>(rwh)); | |
37 delegate_->OnRenderHostCreated( | |
38 content::Details<RenderViewHost>(details).ptr()); | |
39 break; | |
40 } | |
41 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: | |
42 if (state_ == NONE) { | |
43 state_ = LOADED; | |
44 delegate_->OnTabMainFrameLoaded(); | |
45 } | |
46 break; | |
47 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: | |
48 if (state_ == LOADED) { | |
49 state_ = FIRST_PAINT; | |
50 delegate_->OnTabMainFrameFirstRender(); | |
51 } | |
52 break; | |
53 default: | |
54 NOTREACHED() << "unknown type" << type; | |
55 } | |
56 } | |
57 | |
58 } // namespace chromeos | |
OLD | NEW |