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/toolbar/toolbar_model_impl.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_model_impl.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/autocomplete/autocomplete_input.h" | 8 #include "chrome/browser/autocomplete/autocomplete_input.h" |
9 #include "chrome/browser/google/google_util.h" | 9 #include "chrome/browser/google/google_util.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 | 45 |
46 ToolbarModelImpl::~ToolbarModelImpl() { | 46 ToolbarModelImpl::~ToolbarModelImpl() { |
47 } | 47 } |
48 | 48 |
49 // ToolbarModelImpl Implementation. | 49 // ToolbarModelImpl Implementation. |
50 string16 ToolbarModelImpl::GetText( | 50 string16 ToolbarModelImpl::GetText( |
51 bool display_search_urls_as_search_terms) const { | 51 bool display_search_urls_as_search_terms) const { |
52 GURL url(GetURL()); | 52 GURL url(GetURL()); |
53 | 53 |
54 if (display_search_urls_as_search_terms) { | 54 if (display_search_urls_as_search_terms) { |
55 NavigationEntry* entry; | |
56 const NavigationController* navigation_controller = | |
57 GetNavigationController(); | |
58 if (navigation_controller) { | |
59 entry = navigation_controller->GetVisibleEntry(); | |
60 if (entry && !entry->GetSearchTerms().empty()) { | |
61 // Entry has existing search terms. | |
62 return entry->GetSearchTerms(); | |
63 } | |
64 } | |
55 string16 search_terms = TryToExtractSearchTermsFromURL(url); | 65 string16 search_terms = TryToExtractSearchTermsFromURL(url); |
56 if (!search_terms.empty()) | 66 if (!search_terms.empty()) { |
67 if (entry) | |
akalin
2012/12/05 19:40:27
bug! entry isn't always initialized
Mathieu
2012/12/05 20:42:16
Done. Thanks.
| |
68 entry->SetSearchTerms(search_terms); | |
57 return search_terms; | 69 return search_terms; |
70 } | |
58 } | 71 } |
59 std::string languages; // Empty if we don't have a |navigation_controller|. | 72 std::string languages; // Empty if we don't have a |navigation_controller|. |
60 Profile* profile = GetProfile(); | 73 Profile* profile = GetProfile(); |
61 if (profile) | 74 if (profile) |
62 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 75 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
63 | 76 |
64 if (url.spec().length() > content::kMaxURLDisplayChars) | 77 if (url.spec().length() > content::kMaxURLDisplayChars) |
65 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":"); | 78 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":"); |
66 // Note that we can't unescape spaces here, because if the user copies this | 79 // Note that we can't unescape spaces here, because if the user copies this |
67 // and pastes it into another program, that program may think the URL ends at | 80 // and pastes it into another program, that program may think the URL ends at |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 template_url->ExtractSearchTermsFromURL(url, &result); | 244 template_url->ExtractSearchTermsFromURL(url, &result); |
232 return result; | 245 return result; |
233 } | 246 } |
234 | 247 |
235 Profile* ToolbarModelImpl::GetProfile() const { | 248 Profile* ToolbarModelImpl::GetProfile() const { |
236 NavigationController* navigation_controller = GetNavigationController(); | 249 NavigationController* navigation_controller = GetNavigationController(); |
237 return navigation_controller ? | 250 return navigation_controller ? |
238 Profile::FromBrowserContext(navigation_controller->GetBrowserContext()) : | 251 Profile::FromBrowserContext(navigation_controller->GetBrowserContext()) : |
239 NULL; | 252 NULL; |
240 } | 253 } |
OLD | NEW |