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/search/search_tab_helper.h" | 5 #include "chrome/browser/ui/search/search_tab_helper.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 | 62 |
63 void RecordCacheableNTPLoadHistogram(bool succeeded) { | 63 void RecordCacheableNTPLoadHistogram(bool succeeded) { |
64 UMA_HISTOGRAM_ENUMERATION("InstantExtended.CacheableNTPLoad", | 64 UMA_HISTOGRAM_ENUMERATION("InstantExtended.CacheableNTPLoad", |
65 succeeded ? CACHEABLE_NTP_LOAD_SUCCEEDED : | 65 succeeded ? CACHEABLE_NTP_LOAD_SUCCEEDED : |
66 CACHEABLE_NTP_LOAD_FAILED, | 66 CACHEABLE_NTP_LOAD_FAILED, |
67 CACHEABLE_NTP_LOAD_MAX); | 67 CACHEABLE_NTP_LOAD_MAX); |
68 } | 68 } |
69 | 69 |
70 bool IsCacheableNTP(const content::WebContents* contents) { | 70 bool IsCacheableNTP(const content::WebContents* contents) { |
71 const content::NavigationEntry* entry = | 71 const content::NavigationEntry* entry = |
72 contents->GetController().GetActiveEntry(); | 72 contents->GetController().GetLastCommittedEntry(); |
Charlie Reis
2013/11/12 01:09:29
@sreeram: I see you specifically used GetVisibleEn
sreeram
2013/11/12 09:01:26
Based on the call sites below (i.e., where IsCache
jww
2013/11/12 22:32:50
Done.
| |
73 return chrome::ShouldUseCacheableNTP() && | 73 return chrome::ShouldUseCacheableNTP() && |
74 chrome::NavEntryIsInstantNTP(contents, entry) && | 74 chrome::NavEntryIsInstantNTP(contents, entry) && |
75 entry->GetURL() != GURL(chrome::kChromeSearchLocalNtpUrl); | 75 entry->GetURL() != GURL(chrome::kChromeSearchLocalNtpUrl); |
76 } | 76 } |
77 | 77 |
78 bool IsNTP(const content::WebContents* contents) { | 78 bool IsNTP(const content::WebContents* contents) { |
79 // We can't use WebContents::GetURL() because that uses the active entry, | 79 // We can't use WebContents::GetURL() because that uses the active entry, |
80 // whereas we want the visible entry. | 80 // whereas we want the visible entry. |
81 const content::NavigationEntry* entry = | 81 const content::NavigationEntry* entry = |
82 contents->GetController().GetVisibleEntry(); | 82 contents->GetController().GetVisibleEntry(); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 // resources. Normally, we set the title when we begin a NTP load, but it can | 297 // resources. Normally, we set the title when we begin a NTP load, but it can |
298 // get reset in several places (like when you press Reload). This check | 298 // get reset in several places (like when you press Reload). This check |
299 // ensures that the title is properly set to the string defined by the Chrome | 299 // ensures that the title is properly set to the string defined by the Chrome |
300 // UI language (rather than the server language) in all cases. | 300 // UI language (rather than the server language) in all cases. |
301 // | 301 // |
302 // We only override the title when it's nonempty to allow the page to set the | 302 // We only override the title when it's nonempty to allow the page to set the |
303 // title if it really wants. An empty title means to use the default. There's | 303 // title if it really wants. An empty title means to use the default. There's |
304 // also a race condition between this code and the page's SetTitle call which | 304 // also a race condition between this code and the page's SetTitle call which |
305 // this rule avoids. | 305 // this rule avoids. |
306 content::NavigationEntry* entry = | 306 content::NavigationEntry* entry = |
307 web_contents_->GetController().GetActiveEntry(); | 307 web_contents_->GetController().GetLastCommittedEntry(); |
samarth
2013/11/12 15:55:07
Just to confirm, this will be the entry that "trig
jww
2013/11/12 22:32:50
creis should confirm, but yes.
Charlie Reis
2013/11/13 18:40:03
Yes, this is the entry that just committed as part
| |
308 if (entry && entry->GetTitle().empty() && | 308 if (entry && entry->GetTitle().empty() && |
309 (entry->GetVirtualURL() == GURL(chrome::kChromeUINewTabURL) || | 309 (entry->GetVirtualURL() == GURL(chrome::kChromeUINewTabURL) || |
310 chrome::NavEntryIsInstantNTP(web_contents_, entry))) { | 310 chrome::NavEntryIsInstantNTP(web_contents_, entry))) { |
311 entry->SetTitle(l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); | 311 entry->SetTitle(l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); |
312 } | 312 } |
313 } | 313 } |
314 | 314 |
315 void SearchTabHelper::DidFailProvisionalLoad( | 315 void SearchTabHelper::DidFailProvisionalLoad( |
316 int64 /* frame_id */, | 316 int64 /* frame_id */, |
317 const string16& frame_unique_name, | 317 const string16& frame_unique_name, |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 void SearchTabHelper::RedirectToLocalNTP() { | 558 void SearchTabHelper::RedirectToLocalNTP() { |
559 // Extra parentheses to declare a variable. | 559 // Extra parentheses to declare a variable. |
560 content::NavigationController::LoadURLParams load_params( | 560 content::NavigationController::LoadURLParams load_params( |
561 (GURL(chrome::kChromeSearchLocalNtpUrl))); | 561 (GURL(chrome::kChromeSearchLocalNtpUrl))); |
562 load_params.referrer = content::Referrer(); | 562 load_params.referrer = content::Referrer(); |
563 load_params.transition_type = content::PAGE_TRANSITION_SERVER_REDIRECT; | 563 load_params.transition_type = content::PAGE_TRANSITION_SERVER_REDIRECT; |
564 // Don't push a history entry. | 564 // Don't push a history entry. |
565 load_params.should_replace_current_entry = true; | 565 load_params.should_replace_current_entry = true; |
566 web_contents_->GetController().LoadURLWithParams(load_params); | 566 web_contents_->GetController().LoadURLWithParams(load_params); |
567 } | 567 } |
OLD | NEW |