blob: 4edb5ad6d4950fb4f96fbfedbea199fc875a9b3b [file] [log] [blame]
[email protected]f8764e42012-03-02 23:22:381// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]eb8403c2011-08-10 05:38:562// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]f8764e42012-03-02 23:22:385#include "chrome/browser/tab_render_watcher.h"
[email protected]eb8403c2011-08-10 05:38:566
7#include "content/browser/renderer_host/render_widget_host.h"
[email protected]83af80b22011-09-06 18:49:198#include "content/browser/renderer_host/render_view_host.h"
[email protected]86ab86b2011-10-19 03:07:559#include "content/public/browser/notification_details.h"
10#include "content/public/browser/notification_source.h"
[email protected]0d6e9bd2011-10-18 04:29:1611#include "content/public/browser/notification_types.h"
[email protected]fbc5e5f92012-01-02 06:08:3212#include "content/public/browser/web_contents.h"
[email protected]eb8403c2011-08-10 05:38:5613
[email protected]fbc5e5f92012-01-02 06:08:3214using content::WebContents;
15
[email protected]f8764e42012-03-02 23:22:3816TabRenderWatcher::TabRenderWatcher(WebContents* tab, Delegate* delegate)
17 : loaded_(false),
[email protected]fbc5e5f92012-01-02 06:08:3218 web_contents_(tab),
[email protected]eb8403c2011-08-10 05:38:5619 delegate_(delegate) {
20 registrar_.Add(this,
21 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:3222 content::Source<WebContents>(web_contents_));
[email protected]eb8403c2011-08-10 05:38:5623 registrar_.Add(this,
24 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:3225 content::Source<WebContents>(web_contents_));
[email protected]eb8403c2011-08-10 05:38:5626}
27
[email protected]f8764e42012-03-02 23:22:3828void TabRenderWatcher::Observe(int type,
29 const content::NotificationSource& source,
30 const content::NotificationDetails& details) {
[email protected]eb8403c2011-08-10 05:38:5631 switch (type) {
32 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: {
[email protected]86ab86b2011-10-19 03:07:5533 RenderWidgetHost* rwh = content::Details<RenderWidgetHost>(details).ptr();
[email protected]eb8403c2011-08-10 05:38:5634 registrar_.Add(this,
35 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT,
[email protected]86ab86b2011-10-19 03:07:5536 content::Source<RenderWidgetHost>(rwh));
[email protected]a0bbc402011-10-19 04:28:3037 delegate_->OnRenderHostCreated(
38 content::Details<RenderViewHost>(details).ptr());
[email protected]eb8403c2011-08-10 05:38:5639 break;
40 }
41 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME:
[email protected]f8764e42012-03-02 23:22:3842 if (!loaded_) {
43 loaded_ = true;
[email protected]eb8403c2011-08-10 05:38:5644 delegate_->OnTabMainFrameLoaded();
45 }
46 break;
47 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT:
[email protected]f8764e42012-03-02 23:22:3848 if (loaded_)
49 delegate_->OnTabMainFrameRender();
[email protected]eb8403c2011-08-10 05:38:5650 break;
51 default:
[email protected]f8764e42012-03-02 23:22:3852 NOTREACHED() << "Unknown notification " << type;
[email protected]eb8403c2011-08-10 05:38:5653 }
54}