OLD | NEW |
---|---|
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_service.h" | |
10 #include "chrome/browser/search_engines/template_url_service_factory.h" | |
9 #include "chrome/browser/ui/search/search.h" | 11 #include "chrome/browser/ui/search/search.h" |
10 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
11 #include "content/public/browser/navigation_controller.h" | 13 #include "content/public/browser/navigation_controller.h" |
12 #include "content/public/browser/navigation_details.h" | 14 #include "content/public/browser/navigation_details.h" |
13 #include "content/public/browser/navigation_entry.h" | 15 #include "content/public/browser/navigation_entry.h" |
14 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
15 #include "content/public/browser/notification_types.h" | 17 #include "content/public/browser/notification_types.h" |
16 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
17 | 19 |
18 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome::search::SearchTabHelper) | 20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome::search::SearchTabHelper) |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 const content::NotificationDetails& details) { | 94 const content::NotificationDetails& details) { |
93 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); | 95 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); |
94 content::LoadCommittedDetails* committed_details = | 96 content::LoadCommittedDetails* committed_details = |
95 content::Details<content::LoadCommittedDetails>(details).ptr(); | 97 content::Details<content::LoadCommittedDetails>(details).ptr(); |
96 // See comment in |NavigateToPendingEntry()| about why |!IsNTP()| is used. | 98 // See comment in |NavigateToPendingEntry()| about why |!IsNTP()| is used. |
97 if (!IsNTP(committed_details->entry->GetURL())) { | 99 if (!IsNTP(committed_details->entry->GetURL())) { |
98 UpdateModelBasedOnURL(committed_details->entry->GetURL(), | 100 UpdateModelBasedOnURL(committed_details->entry->GetURL(), |
99 !is_initial_navigation_commit_); | 101 !is_initial_navigation_commit_); |
100 } | 102 } |
101 is_initial_navigation_commit_ = false; | 103 is_initial_navigation_commit_ = false; |
104 | |
105 // Update the extracted search terms (if any) in the model. | |
106 if (web_contents()) { | |
sky
2012/12/12 22:41:57
Do you really need this if?
Mathieu
2012/12/12 23:37:24
It comes from SearchModel and it is marked as "wea
sky
2012/12/13 00:48:18
From WebContentsUserData:
// A base class for cla
| |
107 const content::NavigationController* navigation_controller = | |
108 &web_contents()->GetController(); | |
109 if (navigation_controller) { | |
sky
2012/12/12 22:41:57
There is always a NavigationController.
Mathieu
2012/12/12 23:37:24
Done.
| |
110 content::NavigationEntry* entry = navigation_controller->GetActiveEntry(); | |
sky
2012/12/12 22:41:57
Use committed_details->entry
Mathieu
2012/12/12 23:37:24
Done.
| |
111 Profile* profile = | |
112 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | |
113 TemplateURLService* template_url_service = | |
114 TemplateURLServiceFactory::GetForProfile(profile); | |
115 string16 search_terms = | |
116 template_url_service->TryToExtractSearchTermsFromURL(entry->GetURL()); | |
117 if (!search_terms.empty()) | |
118 entry->SetSearchTerms(search_terms); | |
119 } | |
120 } | |
102 } | 121 } |
103 | 122 |
104 void SearchTabHelper::UpdateModelBasedOnURL(const GURL& url, bool animate) { | 123 void SearchTabHelper::UpdateModelBasedOnURL(const GURL& url, bool animate) { |
105 Mode::Type type = Mode::MODE_DEFAULT; | 124 Mode::Type type = Mode::MODE_DEFAULT; |
106 Mode::Origin origin = Mode::ORIGIN_DEFAULT; | 125 Mode::Origin origin = Mode::ORIGIN_DEFAULT; |
107 if (IsNTP(url)) { | 126 if (IsNTP(url)) { |
108 type = Mode::MODE_NTP; | 127 type = Mode::MODE_NTP; |
109 origin = Mode::ORIGIN_NTP; | 128 origin = Mode::ORIGIN_NTP; |
110 } else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) { | 129 } else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) { |
111 type = Mode::MODE_SEARCH_RESULTS; | 130 type = Mode::MODE_SEARCH_RESULTS; |
112 origin = Mode::ORIGIN_SEARCH; | 131 origin = Mode::ORIGIN_SEARCH; |
113 } | 132 } |
114 if (user_input_in_progress_) | 133 if (user_input_in_progress_) |
115 type = Mode::MODE_SEARCH_SUGGESTIONS; | 134 type = Mode::MODE_SEARCH_SUGGESTIONS; |
116 model_.SetMode(Mode(type, origin, animate)); | 135 model_.SetMode(Mode(type, origin, animate)); |
117 } | 136 } |
118 | 137 |
119 const content::WebContents* SearchTabHelper::web_contents() const { | 138 const content::WebContents* SearchTabHelper::web_contents() const { |
120 return model_.web_contents(); | 139 return model_.web_contents(); |
121 } | 140 } |
122 | 141 |
123 } // namespace search | 142 } // namespace search |
124 } // namespace chrome | 143 } // namespace chrome |
OLD | NEW |