Index: content/public/renderer/render_view_observer.cc |
diff --git a/content/public/renderer/render_view_observer.cc b/content/public/renderer/render_view_observer.cc |
index 612fb150234d6ce79d81ab207e9eb65b4f199807..8289da949e1311a2769928a660a532edc75c5b44 100644 |
--- a/content/public/renderer/render_view_observer.cc |
+++ b/content/public/renderer/render_view_observer.cc |
@@ -13,7 +13,7 @@ namespace content { |
RenderViewObserver::RenderViewObserver(RenderView* render_view) |
: render_view_(render_view), |
routing_id_(MSG_ROUTING_NONE) { |
- // |render_view| can be NULL on unit testing. |
+ // |render_view| can be NULL on unit testing or if Observe() is used. |
if (render_view) { |
RenderViewImpl* impl = static_cast<RenderViewImpl*>(render_view); |
routing_id_ = impl->routing_id(); |
@@ -53,4 +53,19 @@ void RenderViewObserver::RenderViewGone() { |
render_view_ = NULL; |
} |
+void RenderViewObserver::Observe(RenderView* render_view) { |
+ RenderViewImpl* impl = static_cast<RenderViewImpl*>(render_view_); |
+ if (impl) { |
+ impl->RemoveObserver(this); |
+ routing_id_ = 0; |
+ } |
+ |
+ render_view_ = render_view; |
+ impl = static_cast<RenderViewImpl*>(render_view_); |
+ if (impl) { |
+ routing_id_ = impl->routing_id(); |
+ impl->AddObserver(this); |
+ } |
+} |
+ |
} // namespace content |