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

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

Issue 731423002: Remove OriginChip code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // The secured version of the search icon is necessary if the search button
238 // button nor origin chip are present to indicate the security state. 235 // is not present to indicate the security state.
239 return (chrome::GetDisplaySearchButtonConditions() == 236 return (chrome::GetDisplaySearchButtonConditions() ==
240 chrome::DISPLAY_SEARCH_BUTTON_NEVER) && 237 chrome::DISPLAY_SEARCH_BUTTON_NEVER) ?
241 !chrome::ShouldDisplayOriginChip() ?
242 IDR_OMNIBOX_SEARCH_SECURED : IDR_OMNIBOX_SEARCH; 238 IDR_OMNIBOX_SEARCH_SECURED : IDR_OMNIBOX_SEARCH;
243 } 239 }
244 240
245 return GetIconForSecurityLevel(GetSecurityLevel(false)); 241 return GetIconForSecurityLevel(GetSecurityLevel(false));
246 } 242 }
247 243
248 int ToolbarModelImpl::GetIconForSecurityLevel(SecurityLevel level) const { 244 int ToolbarModelImpl::GetIconForSecurityLevel(SecurityLevel level) const {
249 static int icon_ids[NUM_SECURITY_LEVELS] = { 245 static int icon_ids[NUM_SECURITY_LEVELS] = {
250 IDR_LOCATION_BAR_HTTP, 246 IDR_LOCATION_BAR_HTTP,
251 IDR_OMNIBOX_HTTPS_VALID, 247 IDR_OMNIBOX_HTTPS_VALID,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 virtual_url.SchemeIs(content::kChromeUIScheme)) { 295 virtual_url.SchemeIs(content::kChromeUIScheme)) {
300 if (!url.SchemeIs(content::kChromeUIScheme)) 296 if (!url.SchemeIs(content::kChromeUIScheme))
301 url = virtual_url; 297 url = virtual_url;
302 return url.host() != chrome::kChromeUINewTabHost; 298 return url.host() != chrome::kChromeUINewTabHost;
303 } 299 }
304 } 300 }
305 301
306 return !chrome::IsInstantNTP(delegate_->GetActiveWebContents()); 302 return !chrome::IsInstantNTP(delegate_->GetActiveWebContents());
307 } 303 }
308 304
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() ||
Justin Donnelly 2014/11/21 19:15:24 This is the only place InTabbedBrowser is called.
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 { 305 NavigationController* ToolbarModelImpl::GetNavigationController() const {
352 // This |current_tab| can be NULL during the initialization of the 306 // This |current_tab| can be NULL during the initialization of the
353 // toolbar during window creation (i.e. before any tabs have been added 307 // toolbar during window creation (i.e. before any tabs have been added
354 // to the window). 308 // to the window).
355 WebContents* current_tab = delegate_->GetActiveWebContents(); 309 WebContents* current_tab = delegate_->GetActiveWebContents();
356 return current_tab ? &current_tab->GetController() : NULL; 310 return current_tab ? &current_tab->GetController() : NULL;
357 } 311 }
358 312
359 Profile* ToolbarModelImpl::GetProfile() const { 313 Profile* ToolbarModelImpl::GetProfile() const {
360 NavigationController* navigation_controller = GetNavigationController(); 314 NavigationController* navigation_controller = GetNavigationController();
(...skipping 30 matching lines...) Expand all
391 if (entry && 345 if (entry &&
392 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) 346 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL()))
393 return search_terms; 347 return search_terms;
394 348
395 // Otherwise, extract search terms for HTTPS pages that do not have a security 349 // Otherwise, extract search terms for HTTPS pages that do not have a security
396 // error. 350 // error.
397 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing); 351 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing);
398 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ? 352 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ?
399 base::string16() : search_terms; 353 base::string16() : search_terms;
400 } 354 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698