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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/autocomplete/autocomplete_input.h" | 9 #include "chrome/browser/autocomplete/autocomplete_input.h" |
10 #include "chrome/browser/google/google_util.h" | 10 #include "chrome/browser/google/google_util.h" |
| 11 #include "chrome/browser/instant/instant_controller.h" |
11 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/search_engines/template_url.h" | 14 #include "chrome/browser/search_engines/template_url.h" |
14 #include "chrome/browser/search_engines/template_url_service.h" | 15 #include "chrome/browser/search_engines/template_url_service.h" |
15 #include "chrome/browser/search_engines/template_url_service_factory.h" | 16 #include "chrome/browser/search_engines/template_url_service_factory.h" |
16 #include "chrome/browser/ssl/ssl_error_info.h" | 17 #include "chrome/browser/ssl/ssl_error_info.h" |
17 #include "chrome/browser/ui/search/search.h" | 18 #include "chrome/browser/ui/search/search.h" |
18 #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h" | 19 #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h" |
19 #include "chrome/common/chrome_constants.h" | 20 #include "chrome/common/chrome_constants.h" |
20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 input_in_progress_(false) { | 66 input_in_progress_(false) { |
66 } | 67 } |
67 | 68 |
68 ToolbarModelImpl::~ToolbarModelImpl() { | 69 ToolbarModelImpl::~ToolbarModelImpl() { |
69 } | 70 } |
70 | 71 |
71 // ToolbarModelImpl Implementation. | 72 // ToolbarModelImpl Implementation. |
72 string16 ToolbarModelImpl::GetText( | 73 string16 ToolbarModelImpl::GetText( |
73 bool display_search_urls_as_search_terms) const { | 74 bool display_search_urls_as_search_terms) const { |
74 if (display_search_urls_as_search_terms) { | 75 if (display_search_urls_as_search_terms) { |
| 76 // If search terms were set explicitly on the NavigationEntry, use those. |
| 77 string16 entry_search_terms = GetSearchTermsFromNavigationEntry(); |
| 78 if (!entry_search_terms.empty()) |
| 79 return entry_search_terms; |
75 string16 search_terms = TryToExtractSearchTermsFromURL(); | 80 string16 search_terms = TryToExtractSearchTermsFromURL(); |
76 if (!search_terms.empty()) | 81 if (!search_terms.empty()) |
77 return search_terms; | 82 return search_terms; |
78 } | 83 } |
79 std::string languages; // Empty if we don't have a |navigation_controller|. | 84 std::string languages; // Empty if we don't have a |navigation_controller|. |
80 Profile* profile = GetProfile(); | 85 Profile* profile = GetProfile(); |
81 if (profile) | 86 if (profile) |
82 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 87 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
83 | 88 |
84 GURL url(GetURL()); | 89 GURL url(GetURL()); |
(...skipping 15 matching lines...) Expand all Loading... |
100 return ShouldDisplayURL() ? entry->GetVirtualURL() : GURL(); | 105 return ShouldDisplayURL() ? entry->GetVirtualURL() : GURL(); |
101 } | 106 } |
102 | 107 |
103 return GURL(chrome::kAboutBlankURL); | 108 return GURL(chrome::kAboutBlankURL); |
104 } | 109 } |
105 | 110 |
106 bool ToolbarModelImpl::WouldReplaceSearchURLWithSearchTerms() const { | 111 bool ToolbarModelImpl::WouldReplaceSearchURLWithSearchTerms() const { |
107 return !TryToExtractSearchTermsFromURL().empty(); | 112 return !TryToExtractSearchTermsFromURL().empty(); |
108 } | 113 } |
109 | 114 |
| 115 string16 ToolbarModelImpl::GetSearchTermsFromNavigationEntry() const { |
| 116 NavigationController* controller = GetNavigationController(); |
| 117 if (controller) { |
| 118 NavigationEntry* entry = controller->GetVisibleEntry(); |
| 119 if (entry) { |
| 120 string16 out_value; |
| 121 if (entry->GetExtraData( |
| 122 std::string(InstantController::kInstantExtendedSearchTermsKey), |
| 123 &out_value)) |
| 124 return out_value; |
| 125 } |
| 126 } |
| 127 return string16(); |
| 128 } |
| 129 |
110 bool ToolbarModelImpl::ShouldDisplayURL() const { | 130 bool ToolbarModelImpl::ShouldDisplayURL() const { |
111 // Note: The order here is important. | 131 // Note: The order here is important. |
112 // - The WebUI test must come before the extension scheme test because there | 132 // - The WebUI test must come before the extension scheme test because there |
113 // can be WebUIs that have extension schemes (e.g. the bookmark manager). In | 133 // can be WebUIs that have extension schemes (e.g. the bookmark manager). In |
114 // that case, we should prefer what the WebUI instance says. | 134 // that case, we should prefer what the WebUI instance says. |
115 // - The view-source test must come before the WebUI test because of the case | 135 // - The view-source test must come before the WebUI test because of the case |
116 // of view-source:chrome://newtab, which should display its URL despite what | 136 // of view-source:chrome://newtab, which should display its URL despite what |
117 // chrome://newtab's WebUI says. | 137 // chrome://newtab's WebUI says. |
118 NavigationController* controller = GetNavigationController(); | 138 NavigationController* controller = GetNavigationController(); |
119 NavigationEntry* entry = controller ? controller->GetVisibleEntry() : NULL; | 139 NavigationEntry* entry = controller ? controller->GetVisibleEntry() : NULL; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 template_url->ExtractSearchTermsFromURL(url, &result); | 281 template_url->ExtractSearchTermsFromURL(url, &result); |
262 return result; | 282 return result; |
263 } | 283 } |
264 | 284 |
265 Profile* ToolbarModelImpl::GetProfile() const { | 285 Profile* ToolbarModelImpl::GetProfile() const { |
266 NavigationController* navigation_controller = GetNavigationController(); | 286 NavigationController* navigation_controller = GetNavigationController(); |
267 return navigation_controller ? | 287 return navigation_controller ? |
268 Profile::FromBrowserContext(navigation_controller->GetBrowserContext()) : | 288 Profile::FromBrowserContext(navigation_controller->GetBrowserContext()) : |
269 NULL; | 289 NULL; |
270 } | 290 } |
OLD | NEW |