Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(769)

Side by Side Diff: content/browser/tab_contents/tab_contents_observer.cc

Issue 6794035: Move dispatching and sending of the last extension specific messages out of TabContents and Rende... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 if (tab_)
24 tab_->AddObserver(observer_);
25 }
26
10 void TabContentsObserver::NavigateToPendingEntry() { 27 void TabContentsObserver::NavigateToPendingEntry() {
11 } 28 }
12 29
13 void TabContentsObserver::DidNavigateMainFramePostCommit( 30 void TabContentsObserver::DidNavigateMainFramePostCommit(
14 const NavigationController::LoadCommittedDetails& details, 31 const NavigationController::LoadCommittedDetails& details,
15 const ViewHostMsg_FrameNavigate_Params& params) { 32 const ViewHostMsg_FrameNavigate_Params& params) {
16 } 33 }
17 34
18 void TabContentsObserver::DidNavigateAnyFramePostCommit( 35 void TabContentsObserver::DidNavigateAnyFramePostCommit(
19 const NavigationController::LoadCommittedDetails& details, 36 const NavigationController::LoadCommittedDetails& details,
(...skipping 14 matching lines...) Expand all
34 51
35 void TabContentsObserver::StopNavigation() { 52 void TabContentsObserver::StopNavigation() {
36 } 53 }
37 54
38 TabContentsObserver::TabContentsObserver(TabContents* tab_contents) 55 TabContentsObserver::TabContentsObserver(TabContents* tab_contents)
39 : tab_contents_(tab_contents), 56 : tab_contents_(tab_contents),
40 routing_id_(tab_contents->render_view_host()->routing_id()) { 57 routing_id_(tab_contents->render_view_host()->routing_id()) {
41 tab_contents_->AddObserver(this); 58 tab_contents_->AddObserver(this);
42 } 59 }
43 60
61 TabContentsObserver::TabContentsObserver()
62 : tab_contents_(NULL), routing_id_(MSG_ROUTING_NONE) {
63 }
64
44 TabContentsObserver::~TabContentsObserver() { 65 TabContentsObserver::~TabContentsObserver() {
45 if (tab_contents_) 66 if (tab_contents_)
46 tab_contents_->RemoveObserver(this); 67 tab_contents_->RemoveObserver(this);
47 } 68 }
48 69
49 void TabContentsObserver::OnTabContentsDestroyed(TabContents* tab) { 70 void TabContentsObserver::OnTabContentsDestroyed(TabContents* tab) {
50 } 71 }
51 72
52 bool TabContentsObserver::OnMessageReceived(const IPC::Message& message) { 73 bool TabContentsObserver::OnMessageReceived(const IPC::Message& message) {
53 return false; 74 return false;
54 } 75 }
55 76
56 bool TabContentsObserver::Send(IPC::Message* message) { 77 bool TabContentsObserver::Send(IPC::Message* message) {
57 if (!tab_contents_ || !tab_contents_->render_view_host()) { 78 if (!tab_contents_ || !tab_contents_->render_view_host()) {
58 delete message; 79 delete message;
59 return false; 80 return false;
60 } 81 }
61 82
62 return tab_contents_->render_view_host()->Send(message); 83 return tab_contents_->render_view_host()->Send(message);
63 } 84 }
64 85
65 void TabContentsObserver::TabContentsDestroyed() { 86 void TabContentsObserver::TabContentsDestroyed() {
66 // Do cleanup so that 'this' can safely be deleted from 87 // Do cleanup so that 'this' can safely be deleted from
67 // OnTabContentsDestroyed. 88 // OnTabContentsDestroyed.
68 tab_contents_->RemoveObserver(this); 89 tab_contents_->RemoveObserver(this);
69 TabContents* tab = tab_contents_; 90 TabContents* tab = tab_contents_;
70 tab_contents_ = NULL; 91 tab_contents_ = NULL;
71 OnTabContentsDestroyed(tab); 92 OnTabContentsDestroyed(tab);
72 } 93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698