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

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

Issue 11824050: InstantExtended: Committed NTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 7 years, 10 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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_tab_helper.h" 5 #include "chrome/browser/ui/search/search_tab_helper.h"
6 6
7 #include "chrome/browser/google/google_util.h" 7 #include "chrome/browser/google/google_util.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/search_engines/template_url.h" 9 #include "chrome/browser/search_engines/template_url.h"
10 #include "chrome/browser/search_engines/template_url_service.h" 10 #include "chrome/browser/search_engines/template_url_service.h"
11 #include "chrome/browser/search_engines/template_url_service_factory.h" 11 #include "chrome/browser/search_engines/template_url_service_factory.h"
12 #include "chrome/browser/ui/search/search.h" 12 #include "chrome/browser/ui/search/search.h"
13 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
14 #include "content/public/browser/navigation_controller.h" 14 #include "content/public/browser/navigation_controller.h"
15 #include "content/public/browser/navigation_details.h" 15 #include "content/public/browser/navigation_details.h"
16 #include "content/public/browser/navigation_entry.h" 16 #include "content/public/browser/navigation_entry.h"
17 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/notification_types.h" 18 #include "content/public/browser/notification_types.h"
19 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 20
21 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome::search::SearchTabHelper); 21 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome::search::SearchTabHelper);
22 22
23 namespace { 23 namespace {
24 24
25 bool IsNTP(const GURL& url) { 25 bool IsNTP(const GURL& url) {
26 return url.SchemeIs(chrome::kChromeUIScheme) && 26 return url.SchemeIs(chrome::kChromeUIScheme) &&
27 url.host() == chrome::kChromeUINewTabHost; 27 url.host() == chrome::kChromeUINewTabHost;
sreeram 2013/02/07 21:17:50 Why not just: return url == GURL(chrome::kChrome
samarth 2013/02/07 22:11:55 No idea (to avoid creating another GURL?). It prob
sreeram 2013/02/07 22:18:15 I don't feel that strongly. I'm continuing to send
28 } 28 }
29 29
30 Profile* ProfileFromWebContents(const content::WebContents* web_contents) { 30 Profile* ProfileFromWebContents(const content::WebContents* web_contents) {
31 return Profile::FromBrowserContext(web_contents->GetBrowserContext()); 31 return Profile::FromBrowserContext(web_contents->GetBrowserContext());
32 } 32 }
33 33
34 bool IsSearchEnabled(Profile* profile) { 34 bool IsSearchEnabled(Profile* profile) {
35 return chrome::search::IsInstantExtendedAPIEnabled(profile); 35 return chrome::search::IsInstantExtendedAPIEnabled(profile);
36 } 36 }
37 37
(...skipping 16 matching lines...) Expand all
54 return template_url->HasSearchTermsReplacementKey(url) && 54 return template_url->HasSearchTermsReplacementKey(url) &&
55 template_url->ExtractSearchTermsFromURL(url, &result) && !result.empty(); 55 template_url->ExtractSearchTermsFromURL(url, &result) && !result.empty();
56 } 56 }
57 57
58 } // namespace 58 } // namespace
59 59
60 namespace chrome { 60 namespace chrome {
61 namespace search { 61 namespace search {
62 62
63 SearchTabHelper::SearchTabHelper(content::WebContents* web_contents) 63 SearchTabHelper::SearchTabHelper(content::WebContents* web_contents)
64 : WebContentsObserver(web_contents), 64 : is_search_enabled_(IsSearchEnabled(ProfileFromWebContents(web_contents))),
65 is_search_enabled_(IsSearchEnabled(ProfileFromWebContents(web_contents))),
66 user_input_in_progress_(false), 65 user_input_in_progress_(false),
67 model_(web_contents) { 66 model_(web_contents) {
68 if (!is_search_enabled_) 67 if (!is_search_enabled_)
69 return; 68 return;
70 69
71 registrar_.Add( 70 registrar_.Add(
72 this, 71 this,
73 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 72 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
74 content::Source<content::NavigationController>( 73 content::Source<content::NavigationController>(
75 &web_contents->GetController())); 74 &web_contents->GetController()));
(...skipping 13 matching lines...) Expand all
89 88
90 UpdateModelBasedOnURL(web_contents()->GetURL()); 89 UpdateModelBasedOnURL(web_contents()->GetURL());
91 } 90 }
92 91
93 void SearchTabHelper::NavigationEntryUpdated() { 92 void SearchTabHelper::NavigationEntryUpdated() {
94 if (!is_search_enabled_) 93 if (!is_search_enabled_)
95 return; 94 return;
96 UpdateModelBasedOnURL(web_contents()->GetURL()); 95 UpdateModelBasedOnURL(web_contents()->GetURL());
97 } 96 }
98 97
99 void SearchTabHelper::NavigateToPendingEntry(
100 const GURL& url,
101 content::NavigationController::ReloadType reload_type) {
102 if (!is_search_enabled_)
103 return;
104
105 // NTP mode changes are initiated at "pending", all others are initiated
106 // when "committed". This is because NTP is rendered natively so is faster
107 // to render than the web contents and we need to coordinate the animations.
108 if (IsNTP(url))
109 UpdateModelBasedOnURL(url);
110 }
111
112 void SearchTabHelper::Observe( 98 void SearchTabHelper::Observe(
113 int type, 99 int type,
114 const content::NotificationSource& source, 100 const content::NotificationSource& source,
115 const content::NotificationDetails& details) { 101 const content::NotificationDetails& details) {
116 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); 102 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type);
117 content::LoadCommittedDetails* committed_details = 103 content::LoadCommittedDetails* committed_details =
118 content::Details<content::LoadCommittedDetails>(details).ptr(); 104 content::Details<content::LoadCommittedDetails>(details).ptr();
119 // See comment in |NavigateToPendingEntry()| about why |!IsNTP()| is used. 105 UpdateModelBasedOnURL(committed_details->entry->GetVirtualURL());
120 if (!IsNTP(committed_details->entry->GetURL())) {
121 UpdateModelBasedOnURL(committed_details->entry->GetURL());
122 }
123 } 106 }
124 107
125 void SearchTabHelper::UpdateModelBasedOnURL(const GURL& url) { 108 void SearchTabHelper::UpdateModelBasedOnURL(const GURL& url) {
126 Mode::Type type = Mode::MODE_DEFAULT; 109 Mode::Type type = Mode::MODE_DEFAULT;
127 Mode::Origin origin = Mode::ORIGIN_DEFAULT; 110 Mode::Origin origin = Mode::ORIGIN_DEFAULT;
128 if (IsNTP(url)) { 111 if (IsNTP(url)) {
129 type = Mode::MODE_NTP; 112 type = Mode::MODE_NTP;
130 origin = Mode::ORIGIN_NTP; 113 origin = Mode::ORIGIN_NTP;
131 } else if (IsSearchResults(url, ProfileFromWebContents(web_contents()))) { 114 } else if (IsSearchResults(url, ProfileFromWebContents(web_contents()))) {
132 type = Mode::MODE_SEARCH_RESULTS; 115 type = Mode::MODE_SEARCH_RESULTS;
133 origin = Mode::ORIGIN_SEARCH; 116 origin = Mode::ORIGIN_SEARCH;
134 } 117 }
135 if (user_input_in_progress_) 118 if (user_input_in_progress_)
136 type = Mode::MODE_SEARCH_SUGGESTIONS; 119 type = Mode::MODE_SEARCH_SUGGESTIONS;
137 model_.SetMode(Mode(type, origin)); 120 model_.SetMode(Mode(type, origin));
138 } 121 }
139 122
140 const content::WebContents* SearchTabHelper::web_contents() const { 123 const content::WebContents* SearchTabHelper::web_contents() const {
141 return model_.web_contents(); 124 return model_.web_contents();
142 } 125 }
143 126
144 } // namespace search 127 } // namespace search
145 } // namespace chrome 128 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698