| 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/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 return NONE; | 185 return NONE; |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 | 188 |
| 189 // ToolbarModelImpl Implementation. | 189 // ToolbarModelImpl Implementation. |
| 190 base::string16 ToolbarModelImpl::GetText() const { | 190 base::string16 ToolbarModelImpl::GetText() const { |
| 191 base::string16 search_terms(GetSearchTerms(false)); | 191 base::string16 search_terms(GetSearchTerms(false)); |
| 192 if (!search_terms.empty()) | 192 if (!search_terms.empty()) |
| 193 return search_terms; | 193 return search_terms; |
| 194 | 194 |
| 195 if (WouldOmitURLDueToOriginChip()) | |
| 196 return base::string16(); | |
| 197 | |
| 198 return GetFormattedURL(NULL); | 195 return GetFormattedURL(NULL); |
| 199 } | 196 } |
| 200 | 197 |
| 201 base::string16 ToolbarModelImpl::GetFormattedURL(size_t* prefix_end) const { | 198 base::string16 ToolbarModelImpl::GetFormattedURL(size_t* prefix_end) const { |
| 202 std::string languages; // Empty if we don't have a |navigation_controller|. | 199 std::string languages; // Empty if we don't have a |navigation_controller|. |
| 203 Profile* profile = GetProfile(); | 200 Profile* profile = GetProfile(); |
| 204 if (profile) | 201 if (profile) |
| 205 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 202 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 206 | 203 |
| 207 GURL url(GetURL()); | 204 GURL url(GetURL()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 251 |
| 255 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel( | 252 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel( |
| 256 bool ignore_editing) const { | 253 bool ignore_editing) const { |
| 257 // When editing, assume no security style. | 254 // When editing, assume no security style. |
| 258 return (input_in_progress() && !ignore_editing) ? | 255 return (input_in_progress() && !ignore_editing) ? |
| 259 NONE : GetSecurityLevelForWebContents(delegate_->GetActiveWebContents()); | 256 NONE : GetSecurityLevelForWebContents(delegate_->GetActiveWebContents()); |
| 260 } | 257 } |
| 261 | 258 |
| 262 int ToolbarModelImpl::GetIcon() const { | 259 int ToolbarModelImpl::GetIcon() const { |
| 263 if (WouldPerformSearchTermReplacement(false)) { | 260 if (WouldPerformSearchTermReplacement(false)) { |
| 264 // The secured version of the search icon is necessary if neither the search | 261 // The secured version of the search icon is necessary if the search button |
| 265 // button nor origin chip are present to indicate the security state. | 262 // is not present to indicate the security state. |
| 266 return (chrome::GetDisplaySearchButtonConditions() == | 263 return (chrome::GetDisplaySearchButtonConditions() == |
| 267 chrome::DISPLAY_SEARCH_BUTTON_NEVER) && | 264 chrome::DISPLAY_SEARCH_BUTTON_NEVER) ? |
| 268 !chrome::ShouldDisplayOriginChip() ? | |
| 269 IDR_OMNIBOX_SEARCH_SECURED : IDR_OMNIBOX_SEARCH; | 265 IDR_OMNIBOX_SEARCH_SECURED : IDR_OMNIBOX_SEARCH; |
| 270 } | 266 } |
| 271 | 267 |
| 272 return GetIconForSecurityLevel(GetSecurityLevel(false)); | 268 return GetIconForSecurityLevel(GetSecurityLevel(false)); |
| 273 } | 269 } |
| 274 | 270 |
| 275 int ToolbarModelImpl::GetIconForSecurityLevel(SecurityLevel level) const { | 271 int ToolbarModelImpl::GetIconForSecurityLevel(SecurityLevel level) const { |
| 276 static int icon_ids[NUM_SECURITY_LEVELS] = { | 272 static int icon_ids[NUM_SECURITY_LEVELS] = { |
| 277 IDR_LOCATION_BAR_HTTP, | 273 IDR_LOCATION_BAR_HTTP, |
| 278 IDR_OMNIBOX_HTTPS_VALID, | 274 IDR_OMNIBOX_HTTPS_VALID, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 virtual_url.SchemeIs(content::kChromeUIScheme)) { | 322 virtual_url.SchemeIs(content::kChromeUIScheme)) { |
| 327 if (!url.SchemeIs(content::kChromeUIScheme)) | 323 if (!url.SchemeIs(content::kChromeUIScheme)) |
| 328 url = virtual_url; | 324 url = virtual_url; |
| 329 return url.host() != chrome::kChromeUINewTabHost; | 325 return url.host() != chrome::kChromeUINewTabHost; |
| 330 } | 326 } |
| 331 } | 327 } |
| 332 | 328 |
| 333 return !chrome::IsInstantNTP(delegate_->GetActiveWebContents()); | 329 return !chrome::IsInstantNTP(delegate_->GetActiveWebContents()); |
| 334 } | 330 } |
| 335 | 331 |
| 336 bool ToolbarModelImpl::WouldOmitURLDueToOriginChip() const { | |
| 337 const char kInterstitialShownKey[] = "interstitial_shown"; | |
| 338 | |
| 339 // When users type URLs and hit enter, continue to show those URLs until | |
| 340 // the navigation commits or an interstitial is shown, because having the | |
| 341 // omnibox clear immediately feels like the input was ignored. | |
| 342 NavigationController* navigation_controller = GetNavigationController(); | |
| 343 if (navigation_controller) { | |
| 344 NavigationEntry* pending_entry = navigation_controller->GetPendingEntry(); | |
| 345 if (pending_entry) { | |
| 346 const NavigationEntry* visible_entry = | |
| 347 navigation_controller->GetVisibleEntry(); | |
| 348 base::string16 unused; | |
| 349 // Keep track that we've shown the origin chip on an interstitial so it | |
| 350 // can be shown even after the interstitial was dismissed, to avoid | |
| 351 // showing the chip, removing it and then showing it again. | |
| 352 if (visible_entry && | |
| 353 visible_entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL && | |
| 354 !pending_entry->GetExtraData(kInterstitialShownKey, &unused)) | |
| 355 pending_entry->SetExtraData(kInterstitialShownKey, base::string16()); | |
| 356 const ui::PageTransition transition_type = | |
| 357 pending_entry->GetTransitionType(); | |
| 358 if ((transition_type & ui::PAGE_TRANSITION_TYPED) != 0 && | |
| 359 !pending_entry->GetExtraData(kInterstitialShownKey, &unused)) | |
| 360 return false; | |
| 361 } | |
| 362 } | |
| 363 | |
| 364 if (!delegate_->InTabbedBrowser() || !ShouldDisplayURL() || | |
| 365 !url_replacement_enabled()) | |
| 366 return false; | |
| 367 | |
| 368 if (chrome::ShouldDisplayOriginChip()) | |
| 369 return true; | |
| 370 | |
| 371 const chrome::OriginChipCondition chip_condition = | |
| 372 chrome::GetOriginChipCondition(); | |
| 373 return (chip_condition == chrome::ORIGIN_CHIP_ALWAYS) || | |
| 374 ((chip_condition == chrome::ORIGIN_CHIP_ON_SRP) && | |
| 375 WouldPerformSearchTermReplacement(false)); | |
| 376 } | |
| 377 | |
| 378 NavigationController* ToolbarModelImpl::GetNavigationController() const { | 332 NavigationController* ToolbarModelImpl::GetNavigationController() const { |
| 379 // This |current_tab| can be NULL during the initialization of the | 333 // This |current_tab| can be NULL during the initialization of the |
| 380 // toolbar during window creation (i.e. before any tabs have been added | 334 // toolbar during window creation (i.e. before any tabs have been added |
| 381 // to the window). | 335 // to the window). |
| 382 WebContents* current_tab = delegate_->GetActiveWebContents(); | 336 WebContents* current_tab = delegate_->GetActiveWebContents(); |
| 383 return current_tab ? ¤t_tab->GetController() : NULL; | 337 return current_tab ? ¤t_tab->GetController() : NULL; |
| 384 } | 338 } |
| 385 | 339 |
| 386 Profile* ToolbarModelImpl::GetProfile() const { | 340 Profile* ToolbarModelImpl::GetProfile() const { |
| 387 NavigationController* navigation_controller = GetNavigationController(); | 341 NavigationController* navigation_controller = GetNavigationController(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 418 if (entry && | 372 if (entry && |
| 419 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) | 373 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) |
| 420 return search_terms; | 374 return search_terms; |
| 421 | 375 |
| 422 // Otherwise, extract search terms for HTTPS pages that do not have a security | 376 // Otherwise, extract search terms for HTTPS pages that do not have a security |
| 423 // error. | 377 // error. |
| 424 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing); | 378 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing); |
| 425 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ? | 379 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ? |
| 426 base::string16() : search_terms; | 380 base::string16() : search_terms; |
| 427 } | 381 } |
| OLD | NEW |