summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-23 03:17:28 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-23 03:17:28 +0000
commit40ead7b6ab0a6de7f8c572e5ff4987433b17a066 (patch)
tree6b0565f4cab63a822342645061f4819730809488
parentfd8db6c4eaeb557c2b9e142a289d9a1b80fb5756 (diff)
downloadchromium_src-40ead7b6ab0a6de7f8c572e5ff4987433b17a066.zip
chromium_src-40ead7b6ab0a6de7f8c572e5ff4987433b17a066.tar.gz
chromium_src-40ead7b6ab0a6de7f8c572e5ff4987433b17a066.tar.bz2
Change NavigationEntry's title fields to carry the text direction.
Mark most of the users with a tag pointing at the bug, so they can be fixed incrementally. BUG=27094 Review URL: http://codereview.chromium.org/6894009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82778 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/i18n/rtl.h5
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc4
-rw-r--r--chrome/browser/debugger/devtools_http_protocol_handler.cc4
-rw-r--r--chrome/browser/external_tab_container_win.cc4
-rw-r--r--chrome/browser/sessions/base_session_service.cc7
-rw-r--r--chrome/browser/sessions/session_service_unittest.cc6
-rw-r--r--chrome/browser/sessions/session_types.cc11
-rw-r--r--chrome/browser/ui/browser.cc2
-rw-r--r--chrome/browser/ui/cocoa/applescript/tab_applescript.mm7
-rw-r--r--chrome/browser/ui/toolbar/back_forward_menu_model.cc15
-rw-r--r--chrome/browser/ui/toolbar/back_forward_menu_model_unittest.cc4
-rw-r--r--chrome/test/ui_test_utils.cc4
-rw-r--r--content/browser/site_instance_unittest.cc8
-rw-r--r--content/browser/tab_contents/interstitial_page.cc4
-rw-r--r--content/browser/tab_contents/interstitial_page.h3
-rw-r--r--content/browser/tab_contents/navigation_controller.cc2
-rw-r--r--content/browser/tab_contents/navigation_entry.cc18
-rw-r--r--content/browser/tab_contents/navigation_entry.h22
-rw-r--r--content/browser/tab_contents/navigation_entry_unittest.cc40
-rw-r--r--content/browser/tab_contents/render_view_host_manager_unittest.cc18
-rw-r--r--content/browser/tab_contents/tab_contents.cc42
-rw-r--r--content/browser/tab_contents/tab_contents.h3
22 files changed, 148 insertions, 85 deletions
diff --git a/base/i18n/rtl.h b/base/i18n/rtl.h
index 5159b46..85ecf58 100644
--- a/base/i18n/rtl.h
+++ b/base/i18n/rtl.h
@@ -43,6 +43,11 @@ class String16WithDirection {
const string16& string() const { return string_; }
TextDirection direction() const { return direction_; }
+ bool is_empty() const { return string_.empty(); }
+ bool operator==(const String16WithDirection& other) const {
+ return string_ == other.string_ && direction_ == other.direction_;
+ }
+
private:
string16 string_;
TextDirection direction_;
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 2fba820..f331e4e 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -1025,7 +1025,9 @@ void TestingAutomationProvider::GetTabTitle(int handle,
NavigationController* tab = tab_tracker_->GetResource(handle);
NavigationEntry* entry = tab->GetActiveEntry();
if (entry != NULL) {
- *title = UTF16ToWideHack(entry->GetTitleForDisplay(""));
+ // TODO(evan): use directionality of title.
+ // http://code.google.com/p/chromium/issues/detail?id=27094
+ *title = UTF16ToWideHack(entry->GetTitleForDisplay("").string());
} else {
*title = std::wstring();
}
diff --git a/chrome/browser/debugger/devtools_http_protocol_handler.cc b/chrome/browser/debugger/devtools_http_protocol_handler.cc
index 175de35..514b506 100644
--- a/chrome/browser/debugger/devtools_http_protocol_handler.cc
+++ b/chrome/browser/debugger/devtools_http_protocol_handler.cc
@@ -253,7 +253,9 @@ static PageList GeneratePageList(
page_info.id = controller.session_id().id();
page_info.attached = client_host != NULL;
page_info.url = entry->url().spec();
- page_info.title = UTF16ToUTF8(entry->title());
+ // TODO(evan): use directionality of title?
+ // http://code.google.com/p/chromium/issues/detail?id=27094
+ page_info.title = UTF16ToUTF8(entry->title().string());
page_info.favicon_url = entry->favicon().url().spec();
page_list.push_back(page_info);
}
diff --git a/chrome/browser/external_tab_container_win.cc b/chrome/browser/external_tab_container_win.cc
index c483a78..59950d1 100644
--- a/chrome/browser/external_tab_container_win.cc
+++ b/chrome/browser/external_tab_container_win.cc
@@ -884,7 +884,9 @@ bool ExternalTabContainer::InitNavigationInfo(NavigationInfo* nav_info,
tab_contents_->controller().GetCurrentEntryIndex();
nav_info->url = entry->url();
nav_info->referrer = entry->referrer();
- nav_info->title = UTF16ToWideHack(entry->title());
+ // TODO(evan): use directionality of title.
+ // http://code.google.com/p/chromium/issues/detail?id=27094
+ nav_info->title = UTF16ToWideHack(entry->title().string());
if (nav_info->title.empty())
nav_info->title = UTF8ToWide(nav_info->url.spec());
diff --git a/chrome/browser/sessions/base_session_service.cc b/chrome/browser/sessions/base_session_service.cc
index b9faaa1..455f376 100644
--- a/chrome/browser/sessions/base_session_service.cc
+++ b/chrome/browser/sessions/base_session_service.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -158,7 +158,10 @@ SessionCommand* BaseSessionService::CreateUpdateTabNavigationCommand(
WriteStringToPickle(pickle, &bytes_written, max_state_size,
entry.virtual_url().spec());
- WriteString16ToPickle(pickle, &bytes_written, max_state_size, entry.title());
+ // TODO(evan): use directionality of title.
+ // http://code.google.com/p/chromium/issues/detail?id=27094
+ WriteString16ToPickle(pickle, &bytes_written, max_state_size,
+ entry.title().string());
if (entry.has_post_data()) {
// Remove the form data, it may contain sensitive information.
diff --git a/chrome/browser/sessions/session_service_unittest.cc b/chrome/browser/sessions/session_service_unittest.cc
index d10548e9..b04c015 100644
--- a/chrome/browser/sessions/session_service_unittest.cc
+++ b/chrome/browser/sessions/session_service_unittest.cc
@@ -71,7 +71,11 @@ class SessionServiceTest : public BrowserWithTestWindowTest,
NavigationEntry entry;
entry.set_url(navigation.virtual_url());
entry.set_referrer(navigation.referrer());
- entry.set_title(navigation.title());
+ // TODO(evan): use directionality of title.
+ // http://code.google.com/p/chromium/issues/detail?id=27094
+ entry.set_title(
+ base::i18n::String16WithDirection(navigation.title(),
+ base::i18n::LEFT_TO_RIGHT));
entry.set_content_state(navigation.state());
entry.set_transition_type(navigation.transition());
entry.set_has_post_data(
diff --git a/chrome/browser/sessions/session_types.cc b/chrome/browser/sessions/session_types.cc
index f9b1ffd..c4dba83 100644
--- a/chrome/browser/sessions/session_types.cc
+++ b/chrome/browser/sessions/session_types.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -68,7 +68,10 @@ NavigationEntry* TabNavigation::ToNavigationEntry(int page_id,
profile);
entry->set_page_id(page_id);
- entry->set_title(title_);
+ // TODO(evan): use directionality of title.
+ // http://code.google.com/p/chromium/issues/detail?id=27094
+ entry->set_title(
+ base::i18n::String16WithDirection(title_, base::i18n::LEFT_TO_RIGHT));
entry->set_content_state(state_);
entry->set_has_post_data(type_mask_ & TabNavigation::HAS_POST_DATA);
@@ -78,7 +81,9 @@ NavigationEntry* TabNavigation::ToNavigationEntry(int page_id,
void TabNavigation::SetFromNavigationEntry(const NavigationEntry& entry) {
virtual_url_ = entry.virtual_url();
referrer_ = entry.referrer();
- title_ = entry.title();
+ // TODO(evan): use directionality of title.
+ // http://code.google.com/p/chromium/issues/detail?id=27094
+ title_ = entry.title().string();
state_ = entry.content_state();
transition_ = entry.transition_type();
type_mask_ = entry.has_post_data() ? TabNavigation::HAS_POST_DATA : 0;
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index 6b6f8ee..61ba1bc 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -4427,7 +4427,7 @@ void Browser::ViewSource(TabContentsWrapper* contents,
webkit_glue::RemoveScrollOffsetFromHistoryState(content_state));
// Do not restore title, derive it from the url.
- active_entry->set_title(string16());
+ active_entry->set_title(base::i18n::String16WithDirection());
// Now show view-source entry.
if (CanSupportWindowFeature(FEATURE_TABSTRIP)) {
diff --git a/chrome/browser/ui/cocoa/applescript/tab_applescript.mm b/chrome/browser/ui/cocoa/applescript/tab_applescript.mm
index 401eb6b..38295ed 100644
--- a/chrome/browser/ui/cocoa/applescript/tab_applescript.mm
+++ b/chrome/browser/ui/cocoa/applescript/tab_applescript.mm
@@ -125,9 +125,10 @@
return nil;
std::wstring title;
- if (entry != NULL) {
- title = UTF16ToWideHack(entry->title());
- }
+ // TODO(evan): use directionality of title.
+ // http://code.google.com/p/chromium/issues/detail?id=27094
+ if (entry != NULL)
+ title = UTF16ToWideHack(entry->title().string());
return base::SysWideToNSString(title);
}
diff --git a/chrome/browser/ui/toolbar/back_forward_menu_model.cc b/chrome/browser/ui/toolbar/back_forward_menu_model.cc
index 9577003..b73deef 100644
--- a/chrome/browser/ui/toolbar/back_forward_menu_model.cc
+++ b/chrome/browser/ui/toolbar/back_forward_menu_model.cc
@@ -84,19 +84,22 @@ string16 BackForwardMenuModel::GetLabelAt(int index) const {
// Return the entry title, escaping any '&' characters and eliding it if it's
// super long.
NavigationEntry* entry = GetNavigationEntry(index);
- string16 menu_text(entry->GetTitleForDisplay(
+ base::i18n::String16WithDirection menu_text(entry->GetTitleForDisplay(
GetTabContents()->profile()->GetPrefs()->
GetString(prefs::kAcceptLanguages)));
- menu_text = ui::ElideText(menu_text, gfx::Font(), kMaxWidth, false);
+ string16 elided =
+ ui::ElideText(menu_text.string(), gfx::Font(), kMaxWidth, false);
#if !defined(OS_MACOSX)
- for (size_t i = menu_text.find('&'); i != string16::npos;
- i = menu_text.find('&', i + 2)) {
- menu_text.insert(i, 1, '&');
+ for (size_t i = elided.find('&'); i != string16::npos;
+ i = elided.find('&', i + 2)) {
+ elided.insert(i, 1, '&');
}
#endif
- return menu_text;
+ // TODO(evan): use directionality of title.
+ // http://code.google.com/p/chromium/issues/detail?id=27094
+ return elided;
}
bool BackForwardMenuModel::IsItemDynamicAt(int index) const {
diff --git a/chrome/browser/ui/toolbar/back_forward_menu_model_unittest.cc b/chrome/browser/ui/toolbar/back_forward_menu_model_unittest.cc
index f7dbd76..3eef4a6 100644
--- a/chrome/browser/ui/toolbar/back_forward_menu_model_unittest.cc
+++ b/chrome/browser/ui/toolbar/back_forward_menu_model_unittest.cc
@@ -73,7 +73,9 @@ class BackFwdMenuModelTest : public RenderViewHostTestHarness {
void LoadURLAndUpdateState(const char* url, const char* title) {
NavigateAndCommit(GURL(url));
- controller().GetLastCommittedEntry()->set_title(UTF8ToUTF16(title));
+ controller().GetLastCommittedEntry()->set_title(
+ base::i18n::String16WithDirection(UTF8ToUTF16(title),
+ base::i18n::LEFT_TO_RIGHT));
}
// Navigate back or forward the given amount and commits the entry (which
diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc
index 6ab4429..7c44a19 100644
--- a/chrome/test/ui_test_utils.cc
+++ b/chrome/test/ui_test_utils.cc
@@ -399,7 +399,9 @@ bool GetCurrentTabTitle(const Browser* browser, string16* title) {
NavigationEntry* last_entry = tab_contents->controller().GetActiveEntry();
if (!last_entry)
return false;
- title->assign(last_entry->GetTitleForDisplay(""));
+ // TODO(evan): use directionality of title.
+ // http://code.google.com/p/chromium/issues/detail?id=27094
+ title->assign(last_entry->GetTitleForDisplay("").string());
return true;
}
diff --git a/content/browser/site_instance_unittest.cc b/content/browser/site_instance_unittest.cc
index b2cb51ca..12e269d 100644
--- a/content/browser/site_instance_unittest.cc
+++ b/content/browser/site_instance_unittest.cc
@@ -137,7 +137,7 @@ TEST_F(SiteInstanceTest, SiteInstanceDestructor) {
EXPECT_EQ(0, siteDeleteCounter);
NavigationEntry* e1 = new NavigationEntry(instance, 0, url, GURL(),
- string16(),
+ base::i18n::String16WithDirection(),
PageTransition::LINK);
// Redundantly setting e1's SiteInstance shouldn't affect the ref count.
@@ -145,8 +145,8 @@ TEST_F(SiteInstanceTest, SiteInstanceDestructor) {
EXPECT_EQ(0, siteDeleteCounter);
// Add a second reference
- NavigationEntry* e2 = new NavigationEntry(instance, 0, url,
- GURL(), string16(),
+ NavigationEntry* e2 = new NavigationEntry(instance, 0, url, GURL(),
+ base::i18n::String16WithDirection(),
PageTransition::LINK);
// Now delete both entries and be sure the SiteInstance goes away.
@@ -197,7 +197,7 @@ TEST_F(SiteInstanceTest, CloneNavigationEntry) {
&browsingDeleteCounter);
NavigationEntry* e1 = new NavigationEntry(instance1, 0, url, GURL(),
- string16(),
+ base::i18n::String16WithDirection(),
PageTransition::LINK);
// Clone the entry
NavigationEntry* e2 = new NavigationEntry(*e1);
diff --git a/content/browser/tab_contents/interstitial_page.cc b/content/browser/tab_contents/interstitial_page.cc
index c3d7291..269336c 100644
--- a/content/browser/tab_contents/interstitial_page.cc
+++ b/content/browser/tab_contents/interstitial_page.cc
@@ -270,7 +270,7 @@ void InterstitialPage::Hide() {
// Let's revert to the original title if necessary.
NavigationEntry* entry = tab_->controller().GetActiveEntry();
if (!new_navigation_ && should_revert_tab_title_) {
- entry->set_title(WideToUTF16Hack(original_tab_title_));
+ entry->set_title(original_tab_title_);
tab_->NotifyNavigationStateChanged(TabContents::INVALIDATE_TITLE);
}
delete this;
@@ -405,7 +405,7 @@ void InterstitialPage::UpdateTitle(
// If this interstitial is shown on an existing navigation entry, we'll need
// to remember its title so we can revert to it when hidden.
if (!new_navigation_ && !should_revert_tab_title_) {
- original_tab_title_ = UTF16ToWideHack(entry->title());
+ original_tab_title_ = entry->title();
should_revert_tab_title_ = true;
}
entry->set_title(title);
diff --git a/content/browser/tab_contents/interstitial_page.h b/content/browser/tab_contents/interstitial_page.h
index 7523050..759d8b3 100644
--- a/content/browser/tab_contents/interstitial_page.h
+++ b/content/browser/tab_contents/interstitial_page.h
@@ -9,6 +9,7 @@
#include <map>
#include <string>
+#include "base/i18n/rtl.h"
#include "base/memory/scoped_ptr.h"
#include "base/process_util.h"
#include "content/browser/renderer_host/render_view_host_delegate.h"
@@ -227,7 +228,7 @@ class InterstitialPage : public NotificationObserver,
// The original title of the tab that should be reverted to when the
// interstitial is hidden.
- std::wstring original_tab_title_;
+ base::i18n::String16WithDirection original_tab_title_;
// Our RenderViewHostViewDelegate, necessary for accelerators to work.
scoped_ptr<InterstitialPageRVHViewDelegate> rvh_view_delegate_;
diff --git a/content/browser/tab_contents/navigation_controller.cc b/content/browser/tab_contents/navigation_controller.cc
index 310e1cf..0049d68 100644
--- a/content/browser/tab_contents/navigation_controller.cc
+++ b/content/browser/tab_contents/navigation_controller.cc
@@ -242,7 +242,7 @@ NavigationEntry* NavigationController::CreateNavigationEntry(
-1,
loaded_url,
referrer,
- string16(),
+ base::i18n::String16WithDirection(),
transition);
entry->set_virtual_url(url);
entry->set_user_typed_url(url);
diff --git a/content/browser/tab_contents/navigation_entry.cc b/content/browser/tab_contents/navigation_entry.cc
index 01a8c77..099d2e4 100644
--- a/content/browser/tab_contents/navigation_entry.cc
+++ b/content/browser/tab_contents/navigation_entry.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -54,7 +54,7 @@ NavigationEntry::NavigationEntry(SiteInstance* instance,
int page_id,
const GURL& url,
const GURL& referrer,
- const string16& title,
+ const base::i18n::String16WithDirection& title,
PageTransition::Type transition_type)
: unique_id_(GetUniqueID()),
site_instance_(instance),
@@ -76,16 +76,16 @@ void NavigationEntry::set_site_instance(SiteInstance* site_instance) {
site_instance_ = site_instance;
}
-const string16& NavigationEntry::GetTitleForDisplay(
+const base::i18n::String16WithDirection& NavigationEntry::GetTitleForDisplay(
const std::string& languages) {
// Most pages have real titles. Don't even bother caching anything if this is
// the case.
- if (!title_.empty())
+ if (!title_.is_empty())
return title_;
// More complicated cases will use the URLs as the title. This result we will
// cache since it's more complicated to compute.
- if (!cached_display_title_.empty())
+ if (!cached_display_title_.is_empty())
return cached_display_title_;
// Use the virtual URL first if any, and fall back on using the real URL.
@@ -103,7 +103,13 @@ const string16& NavigationEntry::GetTitleForDisplay(
title = title.substr(slashpos + 1);
}
- ui::ElideString(title, content::kMaxTitleChars, &cached_display_title_);
+ string16 elided_title;
+ ui::ElideString(title, content::kMaxTitleChars, &elided_title);
+
+ // The computed title is a URL or a filename; assume it's LTR.
+ cached_display_title_ =
+ base::i18n::String16WithDirection(elided_title,
+ base::i18n::LEFT_TO_RIGHT);
return cached_display_title_;
}
diff --git a/content/browser/tab_contents/navigation_entry.h b/content/browser/tab_contents/navigation_entry.h
index 2a25f57..28ffa99 100644
--- a/content/browser/tab_contents/navigation_entry.h
+++ b/content/browser/tab_contents/navigation_entry.h
@@ -184,7 +184,7 @@ class NavigationEntry {
int page_id,
const GURL& url,
const GURL& referrer,
- const string16& title,
+ const base::i18n::String16WithDirection& title,
PageTransition::Type transition_type);
~NavigationEntry();
@@ -227,7 +227,7 @@ class NavigationEntry {
// the user.
void set_url(const GURL& url) {
url_ = url;
- cached_display_title_.clear();
+ cached_display_title_ = base::i18n::String16WithDirection();
}
const GURL& url() const {
return url_;
@@ -250,7 +250,7 @@ class NavigationEntry {
// if there is no overridden display URL, it will return the actual one.
void set_virtual_url(const GURL& url) {
virtual_url_ = (url == url_) ? GURL() : url;
- cached_display_title_.clear();
+ cached_display_title_ = base::i18n::String16WithDirection();
}
bool has_virtual_url() const {
return !virtual_url_.is_empty();
@@ -271,15 +271,10 @@ class NavigationEntry {
// displaying the appropriate "Untitled" label if this is being displayed to
// the user.
void set_title(const base::i18n::String16WithDirection& title) {
- set_title(title.string());
- }
- // TODO(evan): remove the string16-setter once callers are updated.
- // http://code.google.com/p/chromium/issues/detail?id=27094
- void set_title(const string16& title) {
title_ = title;
- cached_display_title_.clear();
+ cached_display_title_ = base::i18n::String16WithDirection();
}
- const string16& title() const {
+ const base::i18n::String16WithDirection& title() const {
return title_;
}
@@ -330,7 +325,8 @@ class NavigationEntry {
// the page if it is available or the URL. |languages| is the list of
// accpeted languages (e.g., prefs::kAcceptLanguages) or empty if proper
// URL formatting isn't needed (e.g., unit tests).
- const string16& GetTitleForDisplay(const std::string& languages);
+ const base::i18n::String16WithDirection& GetTitleForDisplay(
+ const std::string& languages);
// Returns true if the current tab is in view source mode. This will be false
// if there is no navigation.
@@ -413,7 +409,7 @@ class NavigationEntry {
GURL referrer_;
GURL virtual_url_;
bool update_virtual_url_with_url_;
- string16 title_;
+ base::i18n::String16WithDirection title_;
FaviconStatus favicon_;
std::string content_state_;
int32 page_id_;
@@ -427,7 +423,7 @@ class NavigationEntry {
// us from having to do URL formatting on the URL evey time the title is
// displayed. When the URL, virtual URL, or title is set, this should be
// cleared to force a refresh.
- string16 cached_display_title_;
+ base::i18n::String16WithDirection cached_display_title_;
// Copy and assignment is explicitly allowed for this class.
};
diff --git a/content/browser/tab_contents/navigation_entry_unittest.cc b/content/browser/tab_contents/navigation_entry_unittest.cc
index 9d5edc83..6fbc98f 100644
--- a/content/browser/tab_contents/navigation_entry_unittest.cc
+++ b/content/browser/tab_contents/navigation_entry_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -18,11 +18,13 @@ class NavigationEntryTest : public testing::Test {
entry1_.reset(new NavigationEntry);
instance_ = SiteInstance::CreateSiteInstance(NULL);
- entry2_.reset(new NavigationEntry(instance_, 3,
- GURL("test:url"),
- GURL("from"),
- ASCIIToUTF16("title"),
- PageTransition::TYPED));
+ entry2_.reset(new NavigationEntry(
+ instance_, 3,
+ GURL("test:url"),
+ GURL("from"),
+ base::i18n::String16WithDirection(ASCIIToUTF16("title"),
+ base::i18n::LEFT_TO_RIGHT),
+ PageTransition::TYPED));
}
virtual void TearDown() {
@@ -53,23 +55,26 @@ TEST_F(NavigationEntryTest, NavigationEntryURLs) {
EXPECT_EQ(GURL(), entry1_.get()->url());
EXPECT_EQ(GURL(), entry1_.get()->virtual_url());
- EXPECT_TRUE(entry1_.get()->GetTitleForDisplay("").empty());
+ EXPECT_TRUE(entry1_.get()->GetTitleForDisplay("").is_empty());
// Setting URL affects virtual_url and GetTitleForDisplay
entry1_.get()->set_url(GURL("http://www.google.com"));
EXPECT_EQ(GURL("http://www.google.com"), entry1_.get()->url());
EXPECT_EQ(GURL("http://www.google.com"), entry1_.get()->virtual_url());
EXPECT_EQ(ASCIIToUTF16("www.google.com"),
- entry1_.get()->GetTitleForDisplay(""));
+ entry1_.get()->GetTitleForDisplay("").string());
// file:/// URLs should only show the filename.
entry1_.get()->set_url(GURL("file:///foo/bar baz.txt"));
EXPECT_EQ(ASCIIToUTF16("bar baz.txt"),
- entry1_.get()->GetTitleForDisplay(""));
+ entry1_.get()->GetTitleForDisplay("").string());
// Title affects GetTitleForDisplay
- entry1_.get()->set_title(ASCIIToUTF16("Google"));
- EXPECT_EQ(ASCIIToUTF16("Google"), entry1_.get()->GetTitleForDisplay(""));
+ entry1_.get()->set_title(
+ base::i18n::String16WithDirection(ASCIIToUTF16("Google"),
+ base::i18n::LEFT_TO_RIGHT));
+ EXPECT_EQ(ASCIIToUTF16("Google"),
+ entry1_.get()->GetTitleForDisplay("").string());
// Setting virtual_url doesn't affect URL
entry2_.get()->set_virtual_url(GURL("display:url"));
@@ -78,7 +83,8 @@ TEST_F(NavigationEntryTest, NavigationEntryURLs) {
EXPECT_EQ(GURL("display:url"), entry2_.get()->virtual_url());
// Having a title set in constructor overrides virtual URL
- EXPECT_EQ(ASCIIToUTF16("title"), entry2_.get()->GetTitleForDisplay(""));
+ EXPECT_EQ(ASCIIToUTF16("title"),
+ entry2_.get()->GetTitleForDisplay("").string());
// User typed URL is independent of the others
EXPECT_EQ(GURL(), entry1_.get()->user_typed_url());
@@ -151,10 +157,12 @@ TEST_F(NavigationEntryTest, NavigationEntryAccessors) {
EXPECT_EQ(GURL("from2"), entry2_.get()->referrer());
// Title
- EXPECT_EQ(string16(), entry1_.get()->title());
- EXPECT_EQ(ASCIIToUTF16("title"), entry2_.get()->title());
- entry2_.get()->set_title(ASCIIToUTF16("title2"));
- EXPECT_EQ(ASCIIToUTF16("title2"), entry2_.get()->title());
+ EXPECT_EQ(string16(), entry1_.get()->title().string());
+ EXPECT_EQ(ASCIIToUTF16("title"), entry2_.get()->title().string());
+ entry2_.get()->set_title(
+ base::i18n::String16WithDirection(ASCIIToUTF16("title2"),
+ base::i18n::LEFT_TO_RIGHT));
+ EXPECT_EQ(ASCIIToUTF16("title2"), entry2_.get()->title().string());
// State
EXPECT_EQ(std::string(), entry1_.get()->content_state());
diff --git a/content/browser/tab_contents/render_view_host_manager_unittest.cc b/content/browser/tab_contents/render_view_host_manager_unittest.cc
index 3ff2092..7462e03 100644
--- a/content/browser/tab_contents/render_view_host_manager_unittest.cc
+++ b/content/browser/tab_contents/render_view_host_manager_unittest.cc
@@ -176,7 +176,8 @@ TEST_F(RenderViewHostManagerTest, Navigate) {
// 1) The first navigation. --------------------------
GURL url1("http://www.google.com/");
NavigationEntry entry1(NULL /* instance */, -1 /* page_id */, url1,
- GURL() /* referrer */, string16() /* title */,
+ GURL() /* referrer */,
+ base::i18n::String16WithDirection() /* title */,
PageTransition::TYPED);
host = manager.Navigate(entry1);
@@ -195,7 +196,8 @@ TEST_F(RenderViewHostManagerTest, Navigate) {
// 2) Navigate to next site. -------------------------
GURL url2("http://www.google.com/foo");
NavigationEntry entry2(NULL /* instance */, -1 /* page_id */, url2,
- url1 /* referrer */, string16() /* title */,
+ url1 /* referrer */,
+ base::i18n::String16WithDirection() /* title */,
PageTransition::LINK);
host = manager.Navigate(entry2);
@@ -212,7 +214,8 @@ TEST_F(RenderViewHostManagerTest, Navigate) {
// 3) Cross-site navigate to next site. --------------
GURL url3("http://webkit.org/");
NavigationEntry entry3(NULL /* instance */, -1 /* page_id */, url3,
- url2 /* referrer */, string16() /* title */,
+ url2 /* referrer */,
+ base::i18n::String16WithDirection() /* title */,
PageTransition::LINK);
host = manager.Navigate(entry3);
@@ -247,7 +250,8 @@ TEST_F(RenderViewHostManagerTest, WebUI) {
GURL url(chrome::kChromeUINewTabURL);
NavigationEntry entry(NULL /* instance */, -1 /* page_id */, url,
- GURL() /* referrer */, string16() /* title */,
+ GURL() /* referrer */,
+ base::i18n::String16WithDirection() /* title */,
PageTransition::TYPED);
RenderViewHost* host = manager.Navigate(entry);
@@ -285,7 +289,8 @@ TEST_F(RenderViewHostManagerTest, NonWebUIChromeURLs) {
// NTP is a Web UI page.
GURL ntp_url(chrome::kChromeUINewTabURL);
NavigationEntry ntp_entry(NULL /* instance */, -1 /* page_id */, ntp_url,
- GURL() /* referrer */, string16() /* title */,
+ GURL() /* referrer */,
+ base::i18n::String16WithDirection() /* title */,
PageTransition::TYPED);
// about: URLs are not Web UI pages.
@@ -295,7 +300,8 @@ TEST_F(RenderViewHostManagerTest, NonWebUIChromeURLs) {
BrowserURLHandler::RewriteURLIfNecessary(
&about_url, profile_.get(), &reverse_on_redirect);
NavigationEntry about_entry(NULL /* instance */, -1 /* page_id */, about_url,
- GURL() /* referrer */, string16() /* title */,
+ GURL() /* referrer */,
+ base::i18n::String16WithDirection() /* title */,
PageTransition::TYPED);
EXPECT_TRUE(ShouldSwapProcesses(&manager, &ntp_entry, &about_entry));
diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc
index e5142a5..1b50925 100644
--- a/content/browser/tab_contents/tab_contents.cc
+++ b/content/browser/tab_contents/tab_contents.cc
@@ -446,8 +446,10 @@ const string16& TabContents::GetTitle() const {
// that are shown on top of existing pages.
NavigationEntry* entry = controller_.GetTransientEntry();
if (entry) {
+ // TODO(evan): use directionality of title.
+ // http://code.google.com/p/chromium/issues/detail?id=27094
return entry->GetTitleForDisplay(profile()->GetPrefs()->
- GetString(prefs::kAcceptLanguages));
+ GetString(prefs::kAcceptLanguages)).string();
}
WebUI* our_web_ui = render_manager_.pending_web_ui() ?
render_manager_.pending_web_ui() : render_manager_.web_ui();
@@ -456,6 +458,8 @@ const string16& TabContents::GetTitle() const {
entry = controller_.GetActiveEntry();
if (!(entry && entry->IsViewSourceMode())) {
// Give the Web UI the chance to override our title.
+ // TODO(evan): use directionality of title.
+ // http://code.google.com/p/chromium/issues/detail?id=27094
const string16& title = our_web_ui->overridden_title();
if (!title.empty())
return title;
@@ -468,8 +472,10 @@ const string16& TabContents::GetTitle() const {
// title.
entry = controller_.GetLastCommittedEntry();
if (entry) {
+ // TODO(evan): use directionality of title.
+ // http://code.google.com/p/chromium/issues/detail?id=27094
return entry->GetTitleForDisplay(profile()->GetPrefs()->
- GetString(prefs::kAcceptLanguages));
+ GetString(prefs::kAcceptLanguages)).string();
}
return EmptyString16();
}
@@ -1093,8 +1099,11 @@ void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
return;
HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
- if (hs)
- hs->SetPageTitle(entry.virtual_url(), entry.title());
+ if (hs) {
+ // TODO(evan): use directionality of title.
+ // http://code.google.com/p/chromium/issues/detail?id=27094
+ hs->SetPageTitle(entry.virtual_url(), entry.title().string());
+ }
}
double TabContents::GetZoomLevel() const {
@@ -1562,18 +1571,23 @@ TabContents::CreateHistoryAddPageArgs(
return add_page_args;
}
-bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
- const std::wstring& title) {
+bool TabContents::UpdateTitleForEntry(
+ NavigationEntry* entry,
+ const base::i18n::String16WithDirection& title) {
// For file URLs without a title, use the pathname instead. In the case of a
// synthesized title, we don't want the update to count toward the "one set
// per page of the title to history."
- string16 final_title;
+ base::i18n::String16WithDirection final_title;
bool explicit_set;
- if (entry->url().SchemeIsFile() && title.empty()) {
- final_title = UTF8ToUTF16(entry->url().ExtractFileName());
+ if (entry->url().SchemeIsFile() && title.is_empty()) {
+ final_title = base::i18n::String16WithDirection(
+ UTF8ToUTF16(entry->url().ExtractFileName()),
+ base::i18n::LEFT_TO_RIGHT);
explicit_set = false; // Don't count synthetic titles toward the set limit.
} else {
- TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
+ string16 trimmed;
+ TrimWhitespace(title.string(), TRIM_ALL, &trimmed);
+ final_title = base::i18n::String16WithDirection(trimmed, title.direction());
explicit_set = true;
}
@@ -1588,7 +1602,9 @@ bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
}
// Lastly, set the title for the view.
- view_->SetPageTitle(UTF16ToWideHack(final_title));
+ // TODO(evan): use directionality of title.
+ // http://code.google.com/p/chromium/issues/detail?id=27094
+ view_->SetPageTitle(UTF16ToWide(final_title.string()));
NotificationService::current()->Notify(
NotificationType::TAB_CONTENTS_TITLE_UPDATED,
@@ -1894,9 +1910,7 @@ void TabContents::UpdateTitle(RenderViewHost* rvh,
DCHECK(rvh == render_view_host());
NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
page_id);
- // TODO(evan): use directionality of title.
- // http://code.google.com/p/chromium/issues/detail?id=27094
- if (!entry || !UpdateTitleForEntry(entry, UTF16ToWide(title.string())))
+ if (!entry || !UpdateTitleForEntry(entry, title))
return;
// Broadcast notifications when the UI should be updated.
diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h
index 59277fc..42c6139 100644
--- a/content/browser/tab_contents/tab_contents.h
+++ b/content/browser/tab_contents/tab_contents.h
@@ -745,7 +745,8 @@ class TabContents : public PageNavigator,
// This is used as the backend for state updates, which include a new title,
// or the dedicated set title message. It returns true if the new title is
// different and was therefore updated.
- bool UpdateTitleForEntry(NavigationEntry* entry, const std::wstring& title);
+ bool UpdateTitleForEntry(NavigationEntry* entry,
+ const base::i18n::String16WithDirection& title);
// Causes the TabContents to navigate in the right renderer to |entry|, which
// must be already part of the entries in the navigation controller.