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

Side by Side Diff: chrome/browser/ui/search/search_delegate.cc

Issue 10944016: Switch SearchTabHelper to use WebContentsUserData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: const Created 8 years, 3 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) 2012 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/ui/search/search_delegate.h" 5 #include "chrome/browser/ui/search/search_delegate.h"
6 6
7 #include "chrome/browser/ui/search/search_model.h" 7 #include "chrome/browser/ui/search/search_model.h"
8 #include "chrome/browser/ui/search/search_tab_helper.h" 8 #include "chrome/browser/ui/search/search_tab_helper.h"
9 #include "chrome/browser/ui/search/toolbar_search_animator.h" 9 #include "chrome/browser/ui/search/toolbar_search_animator.h"
10 #include "chrome/browser/ui/tab_contents/tab_contents.h"
11 10
12 namespace chrome { 11 namespace chrome {
13 namespace search { 12 namespace search {
14 13
15 SearchDelegate::SearchDelegate(SearchModel* browser_search_model, 14 SearchDelegate::SearchDelegate(SearchModel* browser_search_model,
16 ToolbarModel* toolbar_model) 15 ToolbarModel* toolbar_model)
17 : browser_model_(browser_search_model), 16 : browser_model_(browser_search_model),
18 tab_model_(NULL), 17 tab_model_(NULL),
19 toolbar_search_animator_(browser_search_model, toolbar_model) { 18 toolbar_search_animator_(browser_search_model, toolbar_model) {
20 } 19 }
21 20
22 SearchDelegate::~SearchDelegate() { 21 SearchDelegate::~SearchDelegate() {
23 DCHECK(!tab_model_) << "All tabs should have been deactivated or closed."; 22 DCHECK(!tab_model_) << "All tabs should have been deactivated or closed.";
24 } 23 }
25 24
26 void SearchDelegate::ModeChanged(const Mode& old_mode, const Mode& new_mode) { 25 void SearchDelegate::ModeChanged(const Mode& old_mode, const Mode& new_mode) {
27 browser_model_->SetMode(new_mode); 26 browser_model_->SetMode(new_mode);
28 } 27 }
29 28
30 void SearchDelegate::OnTabActivated(TabContents* contents) { 29 void SearchDelegate::OnTabActivated(content::WebContents* web_contents) {
31 if (tab_model_) 30 if (tab_model_)
32 tab_model_->RemoveObserver(this); 31 tab_model_->RemoveObserver(this);
33 tab_model_ = contents->search_tab_helper()->model(); 32 tab_model_ =
34 DCHECK_EQ(tab_model_->tab_contents(), contents); 33 chrome::search::SearchTabHelper::FromWebContents(web_contents)->model();
35 browser_model_->set_tab_contents(contents); 34 DCHECK_EQ(tab_model_->web_contents(), web_contents);
35 browser_model_->set_web_contents(web_contents);
36 browser_model_->SetMode(tab_model_->mode()); 36 browser_model_->SetMode(tab_model_->mode());
37 tab_model_->AddObserver(this); 37 tab_model_->AddObserver(this);
38 } 38 }
39 39
40 void SearchDelegate::OnTabDeactivated(TabContents* contents) { 40 void SearchDelegate::OnTabDeactivated(content::WebContents* web_contents) {
41 StopObserveringTab(contents); 41 StopObservingTab(web_contents);
42 } 42 }
43 43
44 void SearchDelegate::OnTabDetached(TabContents* contents) { 44 void SearchDelegate::OnTabDetached(content::WebContents* web_contents) {
45 StopObserveringTab(contents); 45 StopObservingTab(web_contents);
46 } 46 }
47 47
48 void SearchDelegate::StopObserveringTab( 48 void SearchDelegate::StopObservingTab(content::WebContents* web_contents) {
49 TabContents* contents) { 49 chrome::search::SearchTabHelper* search_tab_helper =
50 if (contents->search_tab_helper()->model() == tab_model_) { 50 chrome::search::SearchTabHelper::FromWebContents(web_contents);
51 if (search_tab_helper->model() == tab_model_) {
51 tab_model_->RemoveObserver(this); 52 tab_model_->RemoveObserver(this);
52 browser_model_->set_tab_contents(NULL); 53 browser_model_->set_web_contents(NULL);
53 tab_model_ = NULL; 54 tab_model_ = NULL;
54 toolbar_search_animator_.FinishAnimation(contents); 55 toolbar_search_animator_.FinishAnimation(web_contents);
55 } 56 }
56 } 57 }
57 58
58 } // namespace search 59 } // namespace search
59 } // namespace chrome 60 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_delegate.h ('k') | chrome/browser/ui/search/search_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698