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

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

Issue 2166023004: Cleanup in InstantTab and InstantController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/instant_tab.h" 5 #include "chrome/browser/ui/search/instant_tab.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/common/url_constants.h" 9 #include "chrome/common/url_constants.h"
10 #include "content/public/browser/render_frame_host.h" 10 #include "content/public/browser/render_frame_host.h"
11 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
12 12
13 InstantTab::Delegate::~Delegate() { 13 InstantTab::Delegate::~Delegate() {
14 } 14 }
15 15
16 InstantTab::~InstantTab() { 16 InstantTab::~InstantTab() {
17 if (web_contents()) { 17 if (web_contents()) {
18 SearchTabHelper::FromWebContents(web_contents())->model()->RemoveObserver( 18 SearchTabHelper::FromWebContents(web_contents())->model()->RemoveObserver(
19 this); 19 this);
20 } 20 }
21 } 21 }
22 22
23 bool InstantTab::supports_instant() const { 23 InstantTab::InstantTab(Delegate* delegate, content::WebContents* contents)
24 return web_contents() &&
25 SearchTabHelper::FromWebContents(web_contents())->SupportsInstant();
26 }
27
28 bool InstantTab::IsLocal() const {
29 return web_contents() &&
30 web_contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl);
31 }
32
33 InstantTab::InstantTab(Delegate* delegate)
34 : delegate_(delegate) { 24 : delegate_(delegate) {
35 } 25 if (!contents)
36
37 void InstantTab::Init(content::WebContents* new_web_contents) {
38 ClearContents();
39
40 if (!new_web_contents)
41 return; 26 return;
42 27
43 Observe(new_web_contents); 28 Observe(contents);
44 SearchModel* model = 29 SearchModel* model =
45 SearchTabHelper::FromWebContents(web_contents())->model(); 30 SearchTabHelper::FromWebContents(web_contents())->model();
46 model->AddObserver(this); 31 model->AddObserver(this);
47 32
48 // Already know whether the page supports instant. 33 // Already know whether the page supports instant.
49 if (model->instant_support() != INSTANT_SUPPORT_UNKNOWN) 34 if (model->instant_support() != INSTANT_SUPPORT_UNKNOWN)
50 InstantSupportDetermined(model->instant_support() == INSTANT_SUPPORT_YES); 35 InstantSupportDetermined(model->instant_support() == INSTANT_SUPPORT_YES);
51 } 36 }
52 37
53 void InstantTab::DidCommitProvisionalLoadForFrame( 38 void InstantTab::DidCommitProvisionalLoadForFrame(
54 content::RenderFrameHost* render_frame_host, 39 content::RenderFrameHost* render_frame_host,
55 const GURL& url, 40 const GURL& url,
56 ui::PageTransition /* transition_type */) { 41 ui::PageTransition /* transition_type */) {
57 if (!render_frame_host->GetParent()) { 42 if (!render_frame_host->GetParent()) {
58 delegate_->InstantTabAboutToNavigateMainFrame(web_contents(), url); 43 delegate_->InstantTabAboutToNavigateMainFrame(web_contents(), url);
59 } 44 }
60 } 45 }
61 46
62 void InstantTab::ModelChanged(const SearchModel::State& old_state, 47 void InstantTab::ModelChanged(const SearchModel::State& old_state,
63 const SearchModel::State& new_state) { 48 const SearchModel::State& new_state) {
64 if (old_state.instant_support != new_state.instant_support) 49 if (old_state.instant_support != new_state.instant_support)
65 InstantSupportDetermined(new_state.instant_support == INSTANT_SUPPORT_YES); 50 InstantSupportDetermined(new_state.instant_support == INSTANT_SUPPORT_YES);
66 } 51 }
67 52
68 void InstantTab::InstantSupportDetermined(bool supports_instant) { 53 void InstantTab::InstantSupportDetermined(bool supports_instant) {
69 delegate_->InstantSupportDetermined(web_contents(), supports_instant); 54 delegate_->InstantSupportDetermined(web_contents(), supports_instant);
70 55
71 // If the page doesn't support Instant, stop listening to it. 56 // If the page doesn't support Instant, stop listening to it.
72 if (!supports_instant) 57 if (!supports_instant)
73 ClearContents(); 58 ClearContents();
74 } 59 }
75 60
76 void InstantTab::ClearContents() { 61 void InstantTab::ClearContents() {
sfiera 2016/07/22 12:51:00 Now called only from InstantSupportDetermined(). M
Marc Treib 2016/07/22 13:11:17 Done.
77 if (web_contents()) { 62 if (web_contents()) {
78 SearchTabHelper::FromWebContents(web_contents())->model()->RemoveObserver( 63 SearchTabHelper::FromWebContents(web_contents())->model()->RemoveObserver(
79 this); 64 this);
80 } 65 }
81 66
82 Observe(NULL); 67 Observe(nullptr);
83 } 68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698