OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/tab_contents/tab_contents_observer.h" | 5 #include "content/browser/tab_contents/tab_contents_observer.h" |
6 | 6 |
7 #include "content/browser/renderer_host/render_view_host.h" | 7 #include "content/browser/renderer_host/render_view_host.h" |
8 #include "content/browser/tab_contents/tab_contents.h" | 8 #include "content/browser/tab_contents/tab_contents.h" |
9 | 9 |
| 10 TabContentsObserver::Registrar::Registrar(TabContentsObserver* observer) |
| 11 : observer_(observer), tab_(NULL) { |
| 12 } |
| 13 |
| 14 TabContentsObserver::Registrar::~Registrar() { |
| 15 if (tab_) |
| 16 tab_->RemoveObserver(observer_); |
| 17 } |
| 18 |
| 19 void TabContentsObserver::Registrar::Observe(TabContents* tab) { |
| 20 if (tab_) |
| 21 tab_->RemoveObserver(observer_); |
| 22 tab_ = tab; |
| 23 tab_->AddObserver(observer_); |
| 24 } |
| 25 |
10 void TabContentsObserver::NavigateToPendingEntry() { | 26 void TabContentsObserver::NavigateToPendingEntry() { |
11 } | 27 } |
12 | 28 |
13 void TabContentsObserver::DidNavigateMainFramePostCommit( | 29 void TabContentsObserver::DidNavigateMainFramePostCommit( |
14 const NavigationController::LoadCommittedDetails& details, | 30 const NavigationController::LoadCommittedDetails& details, |
15 const ViewHostMsg_FrameNavigate_Params& params) { | 31 const ViewHostMsg_FrameNavigate_Params& params) { |
16 } | 32 } |
17 | 33 |
18 void TabContentsObserver::DidNavigateAnyFramePostCommit( | 34 void TabContentsObserver::DidNavigateAnyFramePostCommit( |
19 const NavigationController::LoadCommittedDetails& details, | 35 const NavigationController::LoadCommittedDetails& details, |
(...skipping 14 matching lines...) Expand all Loading... |
34 | 50 |
35 void TabContentsObserver::StopNavigation() { | 51 void TabContentsObserver::StopNavigation() { |
36 } | 52 } |
37 | 53 |
38 TabContentsObserver::TabContentsObserver(TabContents* tab_contents) | 54 TabContentsObserver::TabContentsObserver(TabContents* tab_contents) |
39 : tab_contents_(tab_contents), | 55 : tab_contents_(tab_contents), |
40 routing_id_(tab_contents->render_view_host()->routing_id()) { | 56 routing_id_(tab_contents->render_view_host()->routing_id()) { |
41 tab_contents_->AddObserver(this); | 57 tab_contents_->AddObserver(this); |
42 } | 58 } |
43 | 59 |
| 60 TabContentsObserver::TabContentsObserver() |
| 61 : tab_contents_(NULL), routing_id_(MSG_ROUTING_NONE) { |
| 62 } |
| 63 |
44 TabContentsObserver::~TabContentsObserver() { | 64 TabContentsObserver::~TabContentsObserver() { |
45 if (tab_contents_) | 65 if (tab_contents_) |
46 tab_contents_->RemoveObserver(this); | 66 tab_contents_->RemoveObserver(this); |
47 } | 67 } |
48 | 68 |
49 void TabContentsObserver::OnTabContentsDestroyed(TabContents* tab) { | 69 void TabContentsObserver::OnTabContentsDestroyed(TabContents* tab) { |
50 } | 70 } |
51 | 71 |
52 bool TabContentsObserver::OnMessageReceived(const IPC::Message& message) { | 72 bool TabContentsObserver::OnMessageReceived(const IPC::Message& message) { |
53 return false; | 73 return false; |
54 } | 74 } |
55 | 75 |
56 bool TabContentsObserver::Send(IPC::Message* message) { | 76 bool TabContentsObserver::Send(IPC::Message* message) { |
57 if (!tab_contents_ || !tab_contents_->render_view_host()) { | 77 if (!tab_contents_ || !tab_contents_->render_view_host()) { |
58 delete message; | 78 delete message; |
59 return false; | 79 return false; |
60 } | 80 } |
61 | 81 |
62 return tab_contents_->render_view_host()->Send(message); | 82 return tab_contents_->render_view_host()->Send(message); |
63 } | 83 } |
64 | 84 |
65 void TabContentsObserver::TabContentsDestroyed() { | 85 void TabContentsObserver::TabContentsDestroyed() { |
66 // Do cleanup so that 'this' can safely be deleted from | 86 // Do cleanup so that 'this' can safely be deleted from |
67 // OnTabContentsDestroyed. | 87 // OnTabContentsDestroyed. |
68 tab_contents_->RemoveObserver(this); | 88 tab_contents_->RemoveObserver(this); |
69 TabContents* tab = tab_contents_; | 89 TabContents* tab = tab_contents_; |
70 tab_contents_ = NULL; | 90 tab_contents_ = NULL; |
71 OnTabContentsDestroyed(tab); | 91 OnTabContentsDestroyed(tab); |
72 } | 92 } |
OLD | NEW |