Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_model_impl.cc

Issue 768413003: TEST ONLY - DO NOT SUBMIT - FOR TRYBOTS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix bad merge Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 return NONE; 158 return NONE;
159 } 159 }
160 } 160 }
161 161
162 // ToolbarModelImpl Implementation. 162 // ToolbarModelImpl Implementation.
163 base::string16 ToolbarModelImpl::GetText() const { 163 base::string16 ToolbarModelImpl::GetText() const {
164 base::string16 search_terms(GetSearchTerms(false)); 164 base::string16 search_terms(GetSearchTerms(false));
165 if (!search_terms.empty()) 165 if (!search_terms.empty())
166 return search_terms; 166 return search_terms;
167 167
168 if (WouldOmitURLDueToOriginChip())
169 return base::string16();
170
171 return GetFormattedURL(NULL); 168 return GetFormattedURL(NULL);
172 } 169 }
173 170
174 base::string16 ToolbarModelImpl::GetFormattedURL(size_t* prefix_end) const { 171 base::string16 ToolbarModelImpl::GetFormattedURL(size_t* prefix_end) const {
175 std::string languages; // Empty if we don't have a |navigation_controller|. 172 std::string languages; // Empty if we don't have a |navigation_controller|.
176 Profile* profile = GetProfile(); 173 Profile* profile = GetProfile();
177 if (profile) 174 if (profile)
178 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); 175 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
179 176
180 GURL url(GetURL()); 177 GURL url(GetURL());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } 223 }
227 224
228 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel( 225 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel(
229 bool ignore_editing) const { 226 bool ignore_editing) const {
230 // When editing, assume no security style. 227 // When editing, assume no security style.
231 return (input_in_progress() && !ignore_editing) ? 228 return (input_in_progress() && !ignore_editing) ?
232 NONE : GetSecurityLevelForWebContents(delegate_->GetActiveWebContents()); 229 NONE : GetSecurityLevelForWebContents(delegate_->GetActiveWebContents());
233 } 230 }
234 231
235 int ToolbarModelImpl::GetIcon() const { 232 int ToolbarModelImpl::GetIcon() const {
236 if (WouldPerformSearchTermReplacement(false)) { 233 if (WouldPerformSearchTermReplacement(false))
237 // The secured version of the search icon is necessary if neither the search 234 return IDR_OMNIBOX_SEARCH_SECURED;
238 // button nor origin chip are present to indicate the security state.
239 return (chrome::GetDisplaySearchButtonConditions() ==
240 chrome::DISPLAY_SEARCH_BUTTON_NEVER) &&
241 !chrome::ShouldDisplayOriginChip() ?
242 IDR_OMNIBOX_SEARCH_SECURED : IDR_OMNIBOX_SEARCH;
243 }
244 235
245 return GetIconForSecurityLevel(GetSecurityLevel(false)); 236 return GetIconForSecurityLevel(GetSecurityLevel(false));
246 } 237 }
247 238
248 int ToolbarModelImpl::GetIconForSecurityLevel(SecurityLevel level) const { 239 int ToolbarModelImpl::GetIconForSecurityLevel(SecurityLevel level) const {
249 static int icon_ids[NUM_SECURITY_LEVELS] = { 240 static int icon_ids[NUM_SECURITY_LEVELS] = {
250 IDR_LOCATION_BAR_HTTP, 241 IDR_LOCATION_BAR_HTTP,
251 IDR_OMNIBOX_HTTPS_VALID, 242 IDR_OMNIBOX_HTTPS_VALID,
252 IDR_OMNIBOX_HTTPS_VALID, 243 IDR_OMNIBOX_HTTPS_VALID,
253 IDR_OMNIBOX_HTTPS_WARNING, 244 IDR_OMNIBOX_HTTPS_WARNING,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 virtual_url.SchemeIs(content::kChromeUIScheme)) { 290 virtual_url.SchemeIs(content::kChromeUIScheme)) {
300 if (!url.SchemeIs(content::kChromeUIScheme)) 291 if (!url.SchemeIs(content::kChromeUIScheme))
301 url = virtual_url; 292 url = virtual_url;
302 return url.host() != chrome::kChromeUINewTabHost; 293 return url.host() != chrome::kChromeUINewTabHost;
303 } 294 }
304 } 295 }
305 296
306 return !chrome::IsInstantNTP(delegate_->GetActiveWebContents()); 297 return !chrome::IsInstantNTP(delegate_->GetActiveWebContents());
307 } 298 }
308 299
309 bool ToolbarModelImpl::WouldOmitURLDueToOriginChip() const {
310 const char kInterstitialShownKey[] = "interstitial_shown";
311
312 // When users type URLs and hit enter, continue to show those URLs until
313 // the navigation commits or an interstitial is shown, because having the
314 // omnibox clear immediately feels like the input was ignored.
315 NavigationController* navigation_controller = GetNavigationController();
316 if (navigation_controller) {
317 NavigationEntry* pending_entry = navigation_controller->GetPendingEntry();
318 if (pending_entry) {
319 const NavigationEntry* visible_entry =
320 navigation_controller->GetVisibleEntry();
321 base::string16 unused;
322 // Keep track that we've shown the origin chip on an interstitial so it
323 // can be shown even after the interstitial was dismissed, to avoid
324 // showing the chip, removing it and then showing it again.
325 if (visible_entry &&
326 visible_entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL &&
327 !pending_entry->GetExtraData(kInterstitialShownKey, &unused))
328 pending_entry->SetExtraData(kInterstitialShownKey, base::string16());
329 const ui::PageTransition transition_type =
330 pending_entry->GetTransitionType();
331 if ((transition_type & ui::PAGE_TRANSITION_TYPED) != 0 &&
332 !pending_entry->GetExtraData(kInterstitialShownKey, &unused))
333 return false;
334 }
335 }
336
337 if (!delegate_->InTabbedBrowser() || !ShouldDisplayURL() ||
338 !url_replacement_enabled())
339 return false;
340
341 if (chrome::ShouldDisplayOriginChip())
342 return true;
343
344 const chrome::OriginChipCondition chip_condition =
345 chrome::GetOriginChipCondition();
346 return (chip_condition == chrome::ORIGIN_CHIP_ALWAYS) ||
347 ((chip_condition == chrome::ORIGIN_CHIP_ON_SRP) &&
348 WouldPerformSearchTermReplacement(false));
349 }
350
351 NavigationController* ToolbarModelImpl::GetNavigationController() const { 300 NavigationController* ToolbarModelImpl::GetNavigationController() const {
352 // This |current_tab| can be NULL during the initialization of the 301 // This |current_tab| can be NULL during the initialization of the
353 // toolbar during window creation (i.e. before any tabs have been added 302 // toolbar during window creation (i.e. before any tabs have been added
354 // to the window). 303 // to the window).
355 WebContents* current_tab = delegate_->GetActiveWebContents(); 304 WebContents* current_tab = delegate_->GetActiveWebContents();
356 return current_tab ? &current_tab->GetController() : NULL; 305 return current_tab ? &current_tab->GetController() : NULL;
357 } 306 }
358 307
359 Profile* ToolbarModelImpl::GetProfile() const { 308 Profile* ToolbarModelImpl::GetProfile() const {
360 NavigationController* navigation_controller = GetNavigationController(); 309 NavigationController* navigation_controller = GetNavigationController();
(...skipping 30 matching lines...) Expand all
391 if (entry && 340 if (entry &&
392 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) 341 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL()))
393 return search_terms; 342 return search_terms;
394 343
395 // Otherwise, extract search terms for HTTPS pages that do not have a security 344 // Otherwise, extract search terms for HTTPS pages that do not have a security
396 // error. 345 // error.
397 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing); 346 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing);
398 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ? 347 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ?
399 base::string16() : search_terms; 348 base::string16() : search_terms;
400 } 349 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/toolbar_model_impl.h ('k') | chrome/browser/ui/toolbar/toolbar_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698