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. 4 5 #include "content/public/renderer/render_view_observer.h" 6 7 #include "content/renderer/render_view_impl.h" 8 9 using blink::WebFrame; 10 11 namespace content { 12 RenderViewObserver(RenderView * render_view)13RenderViewObserver::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. 17 if (render_view) { 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); 22 } 23 } 24 ~RenderViewObserver()25RenderViewObserver::~RenderViewObserver() { 26 if (render_view_) { 27 RenderViewImpl* impl = static_cast<RenderViewImpl*>(render_view_); 28 impl->RemoveObserver(this); 29 } 30 } 31 OnDestruct()32void RenderViewObserver::OnDestruct() { 33 delete this; 34 } 35 OnMessageReceived(const IPC::Message & message)36bool RenderViewObserver::OnMessageReceived(const IPC::Message& message) { 37 return false; 38 } 39 Send(IPC::Message * message)40bool RenderViewObserver::Send(IPC::Message* message) { 41 if (render_view_) 42 return render_view_->Send(message); 43 44 delete message; 45 return false; 46 } 47 render_view() const48RenderView* RenderViewObserver::render_view() const { 49 return render_view_; 50 } 51 RenderViewGone()52void RenderViewObserver::RenderViewGone() { 53 render_view_ = NULL; 54 } 55 Observe(RenderView * render_view)56void RenderViewObserver::Observe(RenderView* render_view) { 57 RenderViewImpl* impl = static_cast<RenderViewImpl*>(render_view_); 58 if (impl) { 59 impl->RemoveObserver(this); 60 routing_id_ = 0; 61 } 62 63 render_view_ = render_view; 64 impl = static_cast<RenderViewImpl*>(render_view_); 65 if (impl) { 66 routing_id_ = impl->routing_id(); 67 impl->AddObserver(this); 68 } 69 } 70 71 } // namespace content 72