1 // Copyright (c) 2012 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/browser/web_contents_observer.h"
7 #include "content/browser/web_contents/web_contents_impl.h"
8 #include "content/public/browser/navigation_details.h"
9 #include "content/public/browser/render_view_host.h"
13 WebContentsObserver::WebContentsObserver(WebContents
* web_contents
)
14 : web_contents_(nullptr) {
15 Observe(web_contents
);
18 WebContentsObserver::WebContentsObserver()
19 : web_contents_(nullptr) {
22 WebContentsObserver::~WebContentsObserver() {
24 web_contents_
->RemoveObserver(this);
27 WebContents
* WebContentsObserver::web_contents() const {
31 void WebContentsObserver::Observe(WebContents
* web_contents
) {
32 if (web_contents
== web_contents_
) {
33 // Early exit to avoid infinite loops if we're in the middle of a callback.
37 web_contents_
->RemoveObserver(this);
38 web_contents_
= static_cast<WebContentsImpl
*>(web_contents
);
40 web_contents_
->AddObserver(this);
44 bool WebContentsObserver::OnMessageReceived(
45 const IPC::Message
& message
,
46 RenderFrameHost
* render_frame_host
) {
50 bool WebContentsObserver::OnMessageReceived(const IPC::Message
& message
) {
54 bool WebContentsObserver::Send(IPC::Message
* message
) {
60 return web_contents_
->Send(message
);
63 int WebContentsObserver::routing_id() const {
65 return MSG_ROUTING_NONE
;
67 return web_contents_
->GetRoutingID();
70 void WebContentsObserver::ResetWebContents() {
71 web_contents_
->RemoveObserver(this);
72 web_contents_
= nullptr;
75 } // namespace content