[email protected] | f8764e4 | 2012-03-02 23:22:38 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | eb8403c | 2011-08-10 05:38:56 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | f8764e4 | 2012-03-02 23:22:38 | [diff] [blame] | 5 | #include "chrome/browser/tab_render_watcher.h" |
[email protected] | eb8403c | 2011-08-10 05:38:56 | [diff] [blame] | 6 | |
[email protected] | 86ab86b | 2011-10-19 03:07:55 | [diff] [blame] | 7 | #include "content/public/browser/notification_details.h" |
| 8 | #include "content/public/browser/notification_source.h" |
[email protected] | 0d6e9bd | 2011-10-18 04:29:16 | [diff] [blame] | 9 | #include "content/public/browser/notification_types.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 10 | #include "content/public/browser/render_view_host.h" |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 11 | #include "content/public/browser/web_contents.h" |
[email protected] | eb8403c | 2011-08-10 05:38:56 | [diff] [blame] | 12 | |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 13 | using content::RenderWidgetHost; |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 14 | using content::WebContents; |
| 15 | |
[email protected] | f8764e4 | 2012-03-02 23:22:38 | [diff] [blame] | 16 | TabRenderWatcher::TabRenderWatcher(WebContents* tab, Delegate* delegate) |
| 17 | : loaded_(false), |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 18 | web_contents_(tab), |
[email protected] | eb8403c | 2011-08-10 05:38:56 | [diff] [blame] | 19 | delegate_(delegate) { |
| 20 | registrar_.Add(this, |
| 21 | content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 22 | content::Source<WebContents>(web_contents_)); |
[email protected] | eb8403c | 2011-08-10 05:38:56 | [diff] [blame] | 23 | registrar_.Add(this, |
| 24 | content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 25 | content::Source<WebContents>(web_contents_)); |
[email protected] | eb8403c | 2011-08-10 05:38:56 | [diff] [blame] | 26 | } |
| 27 | |
[email protected] | f8764e4 | 2012-03-02 23:22:38 | [diff] [blame] | 28 | void TabRenderWatcher::Observe(int type, |
| 29 | const content::NotificationSource& source, |
| 30 | const content::NotificationDetails& details) { |
[email protected] | eb8403c | 2011-08-10 05:38:56 | [diff] [blame] | 31 | switch (type) { |
| 32 | case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { |
[email protected] | 86ab86b | 2011-10-19 03:07:55 | [diff] [blame] | 33 | RenderWidgetHost* rwh = content::Details<RenderWidgetHost>(details).ptr(); |
[email protected] | eb8403c | 2011-08-10 05:38:56 | [diff] [blame] | 34 | registrar_.Add(this, |
| 35 | content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT, |
[email protected] | 86ab86b | 2011-10-19 03:07:55 | [diff] [blame] | 36 | content::Source<RenderWidgetHost>(rwh)); |
[email protected] | a0bbc40 | 2011-10-19 04:28:30 | [diff] [blame] | 37 | delegate_->OnRenderHostCreated( |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 38 | content::Details<content::RenderViewHost>(details).ptr()); |
[email protected] | eb8403c | 2011-08-10 05:38:56 | [diff] [blame] | 39 | break; |
| 40 | } |
| 41 | case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: |
[email protected] | f8764e4 | 2012-03-02 23:22:38 | [diff] [blame] | 42 | if (!loaded_) { |
| 43 | loaded_ = true; |
[email protected] | eb8403c | 2011-08-10 05:38:56 | [diff] [blame] | 44 | delegate_->OnTabMainFrameLoaded(); |
| 45 | } |
| 46 | break; |
| 47 | case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: |
[email protected] | f8764e4 | 2012-03-02 23:22:38 | [diff] [blame] | 48 | if (loaded_) |
| 49 | delegate_->OnTabMainFrameRender(); |
[email protected] | eb8403c | 2011-08-10 05:38:56 | [diff] [blame] | 50 | break; |
| 51 | default: |
[email protected] | f8764e4 | 2012-03-02 23:22:38 | [diff] [blame] | 52 | NOTREACHED() << "Unknown notification " << type; |
[email protected] | eb8403c | 2011-08-10 05:38:56 | [diff] [blame] | 53 | } |
| 54 | } |