OLD | NEW |
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 | 1 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 2 // found in the LICENSE file. |
4 | 3 |
5 #include "chrome/browser/ui/toolbar/toolbar_model_impl.h" | 4 #include "chrome/browser/ui/toolbar/toolbar_model_impl.h" |
6 | 5 |
7 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/autocomplete/autocomplete_input.h" | 7 #include "chrome/browser/autocomplete/autocomplete_input.h" |
9 #include "chrome/browser/google/google_util.h" | 8 #include "chrome/browser/google/google_util.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 30 matching lines...) Expand all Loading... |
42 : delegate_(delegate), | 41 : delegate_(delegate), |
43 input_in_progress_(false) { | 42 input_in_progress_(false) { |
44 } | 43 } |
45 | 44 |
46 ToolbarModelImpl::~ToolbarModelImpl() { | 45 ToolbarModelImpl::~ToolbarModelImpl() { |
47 } | 46 } |
48 | 47 |
49 // ToolbarModelImpl Implementation. | 48 // ToolbarModelImpl Implementation. |
50 string16 ToolbarModelImpl::GetText( | 49 string16 ToolbarModelImpl::GetText( |
51 bool display_search_urls_as_search_terms) const { | 50 bool display_search_urls_as_search_terms) const { |
| 51 NavigationEntry* entry; |
52 if (display_search_urls_as_search_terms) { | 52 if (display_search_urls_as_search_terms) { |
| 53 const NavigationController* navigation_controller = |
| 54 GetNavigationController(); |
| 55 if (navigation_controller) { |
| 56 entry = navigation_controller->GetVisibleEntry(); |
| 57 if (entry && !entry->GetSearchTerms().empty()) { |
| 58 // Entry has existing search terms. |
| 59 return entry->GetSearchTerms(); |
| 60 } |
| 61 } |
53 string16 search_terms = TryToExtractSearchTermsFromURL(); | 62 string16 search_terms = TryToExtractSearchTermsFromURL(); |
54 if (!search_terms.empty()) | 63 if (!search_terms.empty()) { |
| 64 if (entry) |
| 65 entry->SetSearchTerms(search_terms); |
55 return search_terms; | 66 return search_terms; |
| 67 } |
56 } | 68 } |
57 std::string languages; // Empty if we don't have a |navigation_controller|. | 69 std::string languages; // Empty if we don't have a |navigation_controller|. |
58 Profile* profile = GetProfile(); | 70 Profile* profile = GetProfile(); |
59 if (profile) | 71 if (profile) |
60 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 72 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
61 | 73 |
62 GURL url(GetURL()); | 74 GURL url(GetURL()); |
63 if (url.spec().length() > content::kMaxURLDisplayChars) | 75 if (url.spec().length() > content::kMaxURLDisplayChars) |
64 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":"); | 76 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":"); |
65 // Note that we can't unescape spaces here, because if the user copies this | 77 // Note that we can't unescape spaces here, because if the user copies this |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 template_url->ExtractSearchTermsFromURL(url, &result); | 244 template_url->ExtractSearchTermsFromURL(url, &result); |
233 return result; | 245 return result; |
234 } | 246 } |
235 | 247 |
236 Profile* ToolbarModelImpl::GetProfile() const { | 248 Profile* ToolbarModelImpl::GetProfile() const { |
237 NavigationController* navigation_controller = GetNavigationController(); | 249 NavigationController* navigation_controller = GetNavigationController(); |
238 return navigation_controller ? | 250 return navigation_controller ? |
239 Profile::FromBrowserContext(navigation_controller->GetBrowserContext()) : | 251 Profile::FromBrowserContext(navigation_controller->GetBrowserContext()) : |
240 NULL; | 252 NULL; |
241 } | 253 } |
OLD | NEW |