| 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/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 10 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 const NavigationController* navigation_controller = GetNavigationController(); | 147 const NavigationController* navigation_controller = GetNavigationController(); |
| 148 if (navigation_controller) { | 148 if (navigation_controller) { |
| 149 const NavigationEntry* entry = navigation_controller->GetVisibleEntry(); | 149 const NavigationEntry* entry = navigation_controller->GetVisibleEntry(); |
| 150 if (entry) | 150 if (entry) |
| 151 return ShouldDisplayURL() ? entry->GetVirtualURL() : GURL(); | 151 return ShouldDisplayURL() ? entry->GetVirtualURL() : GURL(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 return GURL(content::kAboutBlankURL); | 154 return GURL(content::kAboutBlankURL); |
| 155 } | 155 } |
| 156 | 156 |
| 157 bool ToolbarModelImpl::WouldOmitURLDueToOriginChip() const { | |
| 158 const char kInterstitialShownKey[] = "interstitial_shown"; | |
| 159 | |
| 160 // When users type URLs and hit enter, continue to show those URLs until | |
| 161 // the navigation commits or an interstitial is shown, because having the | |
| 162 // omnibox clear immediately feels like the input was ignored. | |
| 163 NavigationController* navigation_controller = GetNavigationController(); | |
| 164 if (navigation_controller) { | |
| 165 NavigationEntry* pending_entry = navigation_controller->GetPendingEntry(); | |
| 166 if (pending_entry) { | |
| 167 const NavigationEntry* visible_entry = | |
| 168 navigation_controller->GetVisibleEntry(); | |
| 169 base::string16 unused; | |
| 170 // Keep track that we've shown the origin chip on an interstitial so it | |
| 171 // can be shown even after the interstitial was dismissed, to avoid | |
| 172 // showing the chip, removing it and then showing it again. | |
| 173 if (visible_entry && | |
| 174 visible_entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL && | |
| 175 !pending_entry->GetExtraData(kInterstitialShownKey, &unused)) | |
| 176 pending_entry->SetExtraData(kInterstitialShownKey, base::string16()); | |
| 177 const content::PageTransition transition_type = | |
| 178 pending_entry->GetTransitionType(); | |
| 179 if ((transition_type & content::PAGE_TRANSITION_TYPED) != 0 && | |
| 180 !pending_entry->GetExtraData(kInterstitialShownKey, &unused)) | |
| 181 return false; | |
| 182 } | |
| 183 } | |
| 184 | |
| 185 bool should_display_origin_chip = | |
| 186 chrome::ShouldDisplayOriginChip() || chrome::ShouldDisplayOriginChipV2(); | |
| 187 return should_display_origin_chip && delegate_->InTabbedBrowser() && | |
| 188 ShouldDisplayURL() && url_replacement_enabled(); | |
| 189 } | |
| 190 | |
| 191 bool ToolbarModelImpl::WouldPerformSearchTermReplacement( | 157 bool ToolbarModelImpl::WouldPerformSearchTermReplacement( |
| 192 bool ignore_editing) const { | 158 bool ignore_editing) const { |
| 193 return !GetSearchTerms(ignore_editing).empty(); | 159 return !GetSearchTerms(ignore_editing).empty(); |
| 194 } | 160 } |
| 195 | 161 |
| 196 bool ToolbarModelImpl::ShouldDisplayURL() const { | 162 bool ToolbarModelImpl::ShouldDisplayURL() const { |
| 197 // Note: The order here is important. | 163 // Note: The order here is important. |
| 198 // - The WebUI test must come before the extension scheme test because there | 164 // - The WebUI test must come before the extension scheme test because there |
| 199 // can be WebUIs that have extension schemes (e.g. the bookmark manager). In | 165 // can be WebUIs that have extension schemes (e.g. the bookmark manager). In |
| 200 // that case, we should prefer what the WebUI instance says. | 166 // that case, we should prefer what the WebUI instance says. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 218 return url.host() != chrome::kChromeUINewTabHost; | 184 return url.host() != chrome::kChromeUINewTabHost; |
| 219 } | 185 } |
| 220 } | 186 } |
| 221 | 187 |
| 222 if (chrome::IsInstantNTP(delegate_->GetActiveWebContents())) | 188 if (chrome::IsInstantNTP(delegate_->GetActiveWebContents())) |
| 223 return false; | 189 return false; |
| 224 | 190 |
| 225 return true; | 191 return true; |
| 226 } | 192 } |
| 227 | 193 |
| 194 bool ToolbarModelImpl::WouldOmitURLDueToOriginChip() const { |
| 195 const char kInterstitialShownKey[] = "interstitial_shown"; |
| 196 |
| 197 // When users type URLs and hit enter, continue to show those URLs until |
| 198 // the navigation commits or an interstitial is shown, because having the |
| 199 // omnibox clear immediately feels like the input was ignored. |
| 200 NavigationController* navigation_controller = GetNavigationController(); |
| 201 if (navigation_controller) { |
| 202 NavigationEntry* pending_entry = navigation_controller->GetPendingEntry(); |
| 203 if (pending_entry) { |
| 204 const NavigationEntry* visible_entry = |
| 205 navigation_controller->GetVisibleEntry(); |
| 206 base::string16 unused; |
| 207 // Keep track that we've shown the origin chip on an interstitial so it |
| 208 // can be shown even after the interstitial was dismissed, to avoid |
| 209 // showing the chip, removing it and then showing it again. |
| 210 if (visible_entry && |
| 211 visible_entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL && |
| 212 !pending_entry->GetExtraData(kInterstitialShownKey, &unused)) |
| 213 pending_entry->SetExtraData(kInterstitialShownKey, base::string16()); |
| 214 const content::PageTransition transition_type = |
| 215 pending_entry->GetTransitionType(); |
| 216 if ((transition_type & content::PAGE_TRANSITION_TYPED) != 0 && |
| 217 !pending_entry->GetExtraData(kInterstitialShownKey, &unused)) |
| 218 return false; |
| 219 } |
| 220 } |
| 221 |
| 222 bool should_display_origin_chip = |
| 223 chrome::ShouldDisplayOriginChip() || chrome::ShouldDisplayOriginChipV2(); |
| 224 return should_display_origin_chip && delegate_->InTabbedBrowser() && |
| 225 ShouldDisplayURL() && url_replacement_enabled(); |
| 226 } |
| 227 |
| 228 bool ToolbarModelImpl::ShouldShowOriginChip() const { |
| 229 return (chrome::ShouldDisplayOriginChipV2() && |
| 230 WouldOmitURLDueToOriginChip() && |
| 231 origin_chip_enabled()); |
| 232 } |
| 233 |
| 228 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel( | 234 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel( |
| 229 bool ignore_editing) const { | 235 bool ignore_editing) const { |
| 230 // When editing, assume no security style. | 236 // When editing, assume no security style. |
| 231 return (input_in_progress() && !ignore_editing) ? | 237 return (input_in_progress() && !ignore_editing) ? |
| 232 NONE : GetSecurityLevelForWebContents(delegate_->GetActiveWebContents()); | 238 NONE : GetSecurityLevelForWebContents(delegate_->GetActiveWebContents()); |
| 233 } | 239 } |
| 234 | 240 |
| 235 int ToolbarModelImpl::GetIcon() const { | 241 int ToolbarModelImpl::GetIcon() const { |
| 236 if (WouldPerformSearchTermReplacement(false)) { | 242 if (WouldPerformSearchTermReplacement(false)) { |
| 237 // The secured version of the search icon is necessary if neither the search | 243 // The secured version of the search icon is necessary if neither the search |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 if (entry && | 338 if (entry && |
| 333 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) | 339 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) |
| 334 return search_terms; | 340 return search_terms; |
| 335 | 341 |
| 336 // Otherwise, extract search terms for HTTPS pages that do not have a security | 342 // Otherwise, extract search terms for HTTPS pages that do not have a security |
| 337 // error. | 343 // error. |
| 338 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing); | 344 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing); |
| 339 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ? | 345 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ? |
| 340 base::string16() : search_terms; | 346 base::string16() : search_terms; |
| 341 } | 347 } |
| OLD | NEW |