Re-enable index-basics-workers test to see if still times
[chromium-blink-merge.git] / content / public / browser / web_contents_observer.cc
blob14790293040c0f89c1893579653e5b9d1ca9ac39
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"
11 namespace content {
13 WebContentsObserver::WebContentsObserver(WebContents* web_contents)
14 : web_contents_(NULL) {
15 Observe(web_contents);
18 WebContentsObserver::WebContentsObserver()
19 : web_contents_(NULL) {
22 WebContentsObserver::~WebContentsObserver() {
23 if (web_contents_)
24 web_contents_->RemoveObserver(this);
27 WebContents* WebContentsObserver::web_contents() const {
28 return web_contents_;
31 void WebContentsObserver::Observe(WebContents* web_contents) {
32 if (web_contents_)
33 web_contents_->RemoveObserver(this);
34 web_contents_ = static_cast<WebContentsImpl*>(web_contents);
35 if (web_contents_) {
36 web_contents_->AddObserver(this);
40 bool WebContentsObserver::OnMessageReceived(const IPC::Message& message) {
41 return false;
44 bool WebContentsObserver::Send(IPC::Message* message) {
45 if (!web_contents_) {
46 delete message;
47 return false;
50 return web_contents_->Send(message);
53 int WebContentsObserver::routing_id() const {
54 if (!web_contents_)
55 return MSG_ROUTING_NONE;
57 return web_contents_->GetRoutingID();
60 void WebContentsObserver::WebContentsImplDestroyed() {
61 // Do cleanup so that 'this' can safely be deleted from WebContentsDestroyed.
62 web_contents_->RemoveObserver(this);
63 WebContentsImpl* contents = web_contents_;
64 web_contents_ = NULL;
65 WebContentsDestroyed(contents);
68 } // namespace content