blob: 160199f4d02288eb04b2ab4b75311a8885858486 [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
[email protected]86ab86b2011-10-19 03:07:557#include "content/public/browser/notification_details.h"
8#include "content/public/browser/notification_source.h"
[email protected]0d6e9bd2011-10-18 04:29:169#include "content/public/browser/notification_types.h"
[email protected]9c1662b2012-03-06 15:44:3310#include "content/public/browser/render_view_host.h"
[email protected]fbc5e5f92012-01-02 06:08:3211#include "content/public/browser/web_contents.h"
[email protected]eb8403c2011-08-10 05:38:5612
[email protected]eaabba22012-03-07 15:02:1113using content::RenderWidgetHost;
[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(
[email protected]eaabba22012-03-07 15:02:1138 content::Details<content::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}