summaryrefslogtreecommitdiffstats
path: root/content/public/renderer/render_view_observer.cc
blob: 980985c382cd0ca703fd23897971fef31138ffd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/public/renderer/render_view_observer.h"

#include "content/renderer/render_view.h"

using WebKit::WebFrame;

// TODO(jam): temporary until RenderView is renamed to RenderViewImpl since
// trying ::RenderView* below gives compile errors in gcc.
typedef RenderView RenderViewImpl;

namespace content {

RenderViewObserver::RenderViewObserver(RenderView* render_view)
    : render_view_(NULL),
      routing_id_(MSG_ROUTING_NONE) {
  // |render_view| can be NULL on unit testing.
  if (render_view) {
    render_view_ = static_cast<RenderViewImpl*>(render_view);
    routing_id_ = render_view_->routing_id();
    render_view_->AddObserver(this);
  }
}

RenderViewObserver::~RenderViewObserver() {
  if (render_view_)
    render_view_->RemoveObserver(this);
}

void RenderViewObserver::OnDestruct() {
  delete this;
}

bool RenderViewObserver::OnMessageReceived(const IPC::Message& message) {
  return false;
}

bool RenderViewObserver::Send(IPC::Message* message) {
  if (render_view_)
    return render_view_->Send(message);

  delete message;
  return false;
}

RenderView* RenderViewObserver::render_view() {
  return render_view_;
}

void RenderViewObserver::set_render_view(::RenderView* rv) {
  render_view_ = rv;
}

}  // namespace content