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.
5 #include "content/public/renderer/render_view_observer.h"
7 #include "content/renderer/render_view_impl.h"
13 RenderViewObserver::RenderViewObserver(RenderView
* render_view
)
14 : render_view_(render_view
),
15 routing_id_(MSG_ROUTING_NONE
) {
16 // |render_view| can be NULL on unit testing or if Observe() is used.
18 RenderViewImpl
* impl
= static_cast<RenderViewImpl
*>(render_view
);
19 routing_id_
= impl
->routing_id();
20 // TODO(jam): bring this back DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
21 impl
->AddObserver(this);
25 RenderViewObserver::~RenderViewObserver() {
27 RenderViewImpl
* impl
= static_cast<RenderViewImpl
*>(render_view_
);
28 impl
->RemoveObserver(this);
32 void RenderViewObserver::OnDestruct() {
36 bool RenderViewObserver::OnMessageReceived(const IPC::Message
& message
) {
40 bool RenderViewObserver::Send(IPC::Message
* message
) {
42 return render_view_
->Send(message
);
48 RenderView
* RenderViewObserver::render_view() const {
52 void RenderViewObserver::RenderViewGone() {
56 void RenderViewObserver::Observe(RenderView
* render_view
) {
57 RenderViewImpl
* impl
= static_cast<RenderViewImpl
*>(render_view_
);
59 impl
->RemoveObserver(this);
63 render_view_
= render_view
;
64 impl
= static_cast<RenderViewImpl
*>(render_view_
);
66 routing_id_
= impl
->routing_id();
67 impl
->AddObserver(this);
71 } // namespace content