[email protected] | eb8403c | 2011-08-10 05:38:56 | [diff] [blame^] | 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/common/content_notification_types.h" |
| 9 | #include "content/common/notification_details.h" |
| 10 | #include "content/common/notification_source.h" |
| 11 | |
| 12 | namespace chromeos { |
| 13 | |
| 14 | TabFirstRenderWatcher::TabFirstRenderWatcher(TabContents* tab, |
| 15 | Delegate* delegate) |
| 16 | : state_(NONE), |
| 17 | tab_contents_(tab), |
| 18 | delegate_(delegate) { |
| 19 | registrar_.Add(this, |
| 20 | content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, |
| 21 | Source<TabContents>(tab_contents_)); |
| 22 | registrar_.Add(this, |
| 23 | content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 24 | Source<TabContents>(tab_contents_)); |
| 25 | } |
| 26 | |
| 27 | void TabFirstRenderWatcher::Observe(int type, |
| 28 | const NotificationSource& source, const NotificationDetails& details) { |
| 29 | switch (type) { |
| 30 | case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { |
| 31 | RenderWidgetHost* rwh = Details<RenderWidgetHost>(details).ptr(); |
| 32 | registrar_.Add(this, |
| 33 | content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT, |
| 34 | Source<RenderWidgetHost>(rwh)); |
| 35 | break; |
| 36 | } |
| 37 | case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: |
| 38 | if (state_ == NONE) { |
| 39 | state_ = LOADED; |
| 40 | delegate_->OnTabMainFrameLoaded(); |
| 41 | } |
| 42 | break; |
| 43 | case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: |
| 44 | if (state_ == LOADED) { |
| 45 | state_ = FIRST_PAINT; |
| 46 | delegate_->OnTabMainFrameFirstRender(); |
| 47 | } |
| 48 | break; |
| 49 | default: |
| 50 | NOTREACHED() << "unknown type" << type; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | } // namespace chromeos |