Commit f6dfbfd6 authored by brettw@chromium.org's avatar brettw@chromium.org

Force set the new tab title in instant extended.

This eliminates the chance of getting a flash of the URL in the new tab title
before the page has loaded.

BUG=196422
R=samarth@chromium.org

Review URL: https://codereview.chromium.org/17022009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207918 0039d316-1c4b-4281-b951-d872f2087c98
parent e3e696d3
......@@ -868,8 +868,6 @@ function isGooglePage() {
* Google-provided page.
*/
function init() {
document.title = templateData.title;
tilesContainer = $(IDS.TILES);
notification = $(IDS.NOTIFICATION);
attribution = $(IDS.ATTRIBUTION);
......
......@@ -21,6 +21,8 @@
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents_view.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
namespace {
......@@ -56,6 +58,17 @@ void InstantLoader::Load() {
contents_->GetController().LoadURL(
instant_url_, content::Referrer(),
content::PAGE_TRANSITION_GENERATED, kInstantHeader);
// Explicitly set the new tab title and virtual URL.
//
// This ensures that the title is set even before we get a title from the
// page, preventing a potential flicker of the URL, and also ensures that
// (unless overridden by the page) the new tab title matches the browser UI
// locale.
content::NavigationEntry* entry = contents_->GetController().GetActiveEntry();
if (entry)
entry->SetTitle(l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE));
contents_->WasHidden();
int staleness_timeout_ms = chrome::GetInstantLoaderStalenessTimeoutSec() *
......
......@@ -14,7 +14,8 @@
#include "content/public/browser/navigation_type.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
DEFINE_WEB_CONTENTS_USER_DATA_KEY(SearchTabHelper);
......@@ -144,6 +145,28 @@ void SearchTabHelper::Observe(
model_.SetVoiceSearchSupported(false);
}
void SearchTabHelper::DidNavigateMainFrame(
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) {
// Always set the title on the new tab page to be the one from our UI
// resources. Normally, we set the title when we begin a NTP load, but it
// can get reset in several places (like when you press Reload). This check
// ensures that the title is properly set to the string defined by the Chrome
// UI language (rather than the server language) in all cases.
//
// We only override the title when it's nonempty to allow the page to set the
// title if it really wants. An empty title means to use the default. There's
// also a race condition between this code and the page's SetTitle call which
// this rule avoids.
content::NavigationEntry* entry =
web_contents_->GetController().GetActiveEntry();
if (entry && entry->GetTitle().empty() &&
(entry->GetVirtualURL() == GURL(chrome::kChromeUINewTabURL) ||
chrome::NavEntryIsInstantNTP(web_contents_, entry))) {
entry->SetTitle(l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE));
}
}
bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(SearchTabHelper, message)
......
......@@ -84,6 +84,9 @@ class SearchTabHelper : public content::NotificationObserver,
const content::NotificationDetails& details) OVERRIDE;
// Overridden from contents::WebContentsObserver:
virtual void DidNavigateMainFrame(
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void DidFinishLoad(
int64 frame_id,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment