OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/tab_contents/tab_contents.h" | 5 #include "content/browser/tab_contents/tab_contents.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 // We may not have a navigation entry yet | 447 // We may not have a navigation entry yet |
448 NavigationEntry* entry = controller_.GetActiveEntry(); | 448 NavigationEntry* entry = controller_.GetActiveEntry(); |
449 return entry ? entry->virtual_url() : GURL::EmptyGURL(); | 449 return entry ? entry->virtual_url() : GURL::EmptyGURL(); |
450 } | 450 } |
451 | 451 |
452 const string16& TabContents::GetTitle() const { | 452 const string16& TabContents::GetTitle() const { |
453 // Transient entries take precedence. They are used for interstitial pages | 453 // Transient entries take precedence. They are used for interstitial pages |
454 // that are shown on top of existing pages. | 454 // that are shown on top of existing pages. |
455 NavigationEntry* entry = controller_.GetTransientEntry(); | 455 NavigationEntry* entry = controller_.GetTransientEntry(); |
456 if (entry) { | 456 if (entry) { |
| 457 // TODO(evan): use directionality of title. |
| 458 // http://code.google.com/p/chromium/issues/detail?id=27094 |
457 return entry->GetTitleForDisplay(profile()->GetPrefs()-> | 459 return entry->GetTitleForDisplay(profile()->GetPrefs()-> |
458 GetString(prefs::kAcceptLanguages)); | 460 GetString(prefs::kAcceptLanguages)).string(); |
459 } | 461 } |
460 WebUI* our_web_ui = render_manager_.pending_web_ui() ? | 462 WebUI* our_web_ui = render_manager_.pending_web_ui() ? |
461 render_manager_.pending_web_ui() : render_manager_.web_ui(); | 463 render_manager_.pending_web_ui() : render_manager_.web_ui(); |
462 if (our_web_ui) { | 464 if (our_web_ui) { |
463 // Don't override the title in view source mode. | 465 // Don't override the title in view source mode. |
464 entry = controller_.GetActiveEntry(); | 466 entry = controller_.GetActiveEntry(); |
465 if (!(entry && entry->IsViewSourceMode())) { | 467 if (!(entry && entry->IsViewSourceMode())) { |
466 // Give the Web UI the chance to override our title. | 468 // Give the Web UI the chance to override our title. |
| 469 // TODO(evan): use directionality of title. |
| 470 // http://code.google.com/p/chromium/issues/detail?id=27094 |
467 const string16& title = our_web_ui->overridden_title(); | 471 const string16& title = our_web_ui->overridden_title(); |
468 if (!title.empty()) | 472 if (!title.empty()) |
469 return title; | 473 return title; |
470 } | 474 } |
471 } | 475 } |
472 | 476 |
473 // We use the title for the last committed entry rather than a pending | 477 // We use the title for the last committed entry rather than a pending |
474 // navigation entry. For example, when the user types in a URL, we want to | 478 // navigation entry. For example, when the user types in a URL, we want to |
475 // keep the old page's title until the new load has committed and we get a new | 479 // keep the old page's title until the new load has committed and we get a new |
476 // title. | 480 // title. |
477 entry = controller_.GetLastCommittedEntry(); | 481 entry = controller_.GetLastCommittedEntry(); |
478 if (entry) { | 482 if (entry) { |
| 483 // TODO(evan): use directionality of title. |
| 484 // http://code.google.com/p/chromium/issues/detail?id=27094 |
479 return entry->GetTitleForDisplay(profile()->GetPrefs()-> | 485 return entry->GetTitleForDisplay(profile()->GetPrefs()-> |
480 GetString(prefs::kAcceptLanguages)); | 486 GetString(prefs::kAcceptLanguages)).string(); |
481 } | 487 } |
482 return EmptyString16(); | 488 return EmptyString16(); |
483 } | 489 } |
484 | 490 |
485 int32 TabContents::GetMaxPageID() { | 491 int32 TabContents::GetMaxPageID() { |
486 if (GetSiteInstance()) | 492 if (GetSiteInstance()) |
487 return GetSiteInstance()->max_page_id(); | 493 return GetSiteInstance()->max_page_id(); |
488 else | 494 else |
489 return max_page_id_; | 495 return max_page_id_; |
490 } | 496 } |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); | 1146 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); |
1141 if (hs) | 1147 if (hs) |
1142 hs->AddPage(*add_page_args); | 1148 hs->AddPage(*add_page_args); |
1143 } | 1149 } |
1144 | 1150 |
1145 void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) { | 1151 void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) { |
1146 if (profile()->IsOffTheRecord()) | 1152 if (profile()->IsOffTheRecord()) |
1147 return; | 1153 return; |
1148 | 1154 |
1149 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); | 1155 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); |
1150 if (hs) | 1156 if (hs) { |
1151 hs->SetPageTitle(entry.virtual_url(), entry.title()); | 1157 // TODO(evan): use directionality of title. |
| 1158 // http://code.google.com/p/chromium/issues/detail?id=27094 |
| 1159 hs->SetPageTitle(entry.virtual_url(), entry.title().string()); |
| 1160 } |
1152 } | 1161 } |
1153 | 1162 |
1154 double TabContents::GetZoomLevel() const { | 1163 double TabContents::GetZoomLevel() const { |
1155 HostZoomMap* zoom_map = profile()->GetHostZoomMap(); | 1164 HostZoomMap* zoom_map = profile()->GetHostZoomMap(); |
1156 if (!zoom_map) | 1165 if (!zoom_map) |
1157 return 0; | 1166 return 0; |
1158 | 1167 |
1159 double zoom_level; | 1168 double zoom_level; |
1160 if (temporary_zoom_settings_) { | 1169 if (temporary_zoom_settings_) { |
1161 zoom_level = zoom_map->GetTemporaryZoomLevel( | 1170 zoom_level = zoom_map->GetTemporaryZoomLevel( |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1661 // they saw in the URL bar, so we add the virtual URL as a redirect. This | 1670 // they saw in the URL bar, so we add the virtual URL as a redirect. This |
1662 // only applies to the main frame, as the virtual URL doesn't apply to | 1671 // only applies to the main frame, as the virtual URL doesn't apply to |
1663 // sub-frames. | 1672 // sub-frames. |
1664 add_page_args->url = virtual_url; | 1673 add_page_args->url = virtual_url; |
1665 if (!add_page_args->redirects.empty()) | 1674 if (!add_page_args->redirects.empty()) |
1666 add_page_args->redirects.back() = virtual_url; | 1675 add_page_args->redirects.back() = virtual_url; |
1667 } | 1676 } |
1668 return add_page_args; | 1677 return add_page_args; |
1669 } | 1678 } |
1670 | 1679 |
1671 bool TabContents::UpdateTitleForEntry(NavigationEntry* entry, | 1680 bool TabContents::UpdateTitleForEntry( |
1672 const std::wstring& title) { | 1681 NavigationEntry* entry, |
| 1682 const base::i18n::String16WithDirection& title) { |
1673 // For file URLs without a title, use the pathname instead. In the case of a | 1683 // For file URLs without a title, use the pathname instead. In the case of a |
1674 // synthesized title, we don't want the update to count toward the "one set | 1684 // synthesized title, we don't want the update to count toward the "one set |
1675 // per page of the title to history." | 1685 // per page of the title to history." |
1676 string16 final_title; | 1686 base::i18n::String16WithDirection final_title; |
1677 bool explicit_set; | 1687 bool explicit_set; |
1678 if (entry->url().SchemeIsFile() && title.empty()) { | 1688 if (entry->url().SchemeIsFile() && title.is_empty()) { |
1679 final_title = UTF8ToUTF16(entry->url().ExtractFileName()); | 1689 final_title = base::i18n::String16WithDirection( |
| 1690 UTF8ToUTF16(entry->url().ExtractFileName()), |
| 1691 base::i18n::LEFT_TO_RIGHT); |
1680 explicit_set = false; // Don't count synthetic titles toward the set limit. | 1692 explicit_set = false; // Don't count synthetic titles toward the set limit. |
1681 } else { | 1693 } else { |
1682 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title); | 1694 string16 trimmed; |
| 1695 TrimWhitespace(title.string(), TRIM_ALL, &trimmed); |
| 1696 final_title = base::i18n::String16WithDirection(trimmed, title.direction()); |
1683 explicit_set = true; | 1697 explicit_set = true; |
1684 } | 1698 } |
1685 | 1699 |
1686 if (final_title == entry->title()) | 1700 if (final_title == entry->title()) |
1687 return false; // Nothing changed, don't bother. | 1701 return false; // Nothing changed, don't bother. |
1688 | 1702 |
1689 entry->set_title(final_title); | 1703 entry->set_title(final_title); |
1690 | 1704 |
1691 if (!received_page_title_) { | 1705 if (!received_page_title_) { |
1692 UpdateHistoryPageTitle(*entry); | 1706 UpdateHistoryPageTitle(*entry); |
1693 received_page_title_ = explicit_set; | 1707 received_page_title_ = explicit_set; |
1694 } | 1708 } |
1695 | 1709 |
1696 // Lastly, set the title for the view. | 1710 // Lastly, set the title for the view. |
1697 view_->SetPageTitle(UTF16ToWideHack(final_title)); | 1711 // TODO(evan): use directionality of title. |
| 1712 // http://code.google.com/p/chromium/issues/detail?id=27094 |
| 1713 view_->SetPageTitle(UTF16ToWide(final_title.string())); |
1698 | 1714 |
1699 NotificationService::current()->Notify( | 1715 NotificationService::current()->Notify( |
1700 NotificationType::TAB_CONTENTS_TITLE_UPDATED, | 1716 NotificationType::TAB_CONTENTS_TITLE_UPDATED, |
1701 Source<TabContents>(this), | 1717 Source<TabContents>(this), |
1702 NotificationService::NoDetails()); | 1718 NotificationService::NoDetails()); |
1703 | 1719 |
1704 return true; | 1720 return true; |
1705 } | 1721 } |
1706 | 1722 |
1707 void TabContents::NotifySwapped() { | 1723 void TabContents::NotifySwapped() { |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1993 void TabContents::UpdateTitle(RenderViewHost* rvh, | 2009 void TabContents::UpdateTitle(RenderViewHost* rvh, |
1994 int32 page_id, | 2010 int32 page_id, |
1995 const base::i18n::String16WithDirection& title) { | 2011 const base::i18n::String16WithDirection& title) { |
1996 // If we have a title, that's a pretty good indication that we've started | 2012 // If we have a title, that's a pretty good indication that we've started |
1997 // getting useful data. | 2013 // getting useful data. |
1998 SetNotWaitingForResponse(); | 2014 SetNotWaitingForResponse(); |
1999 | 2015 |
2000 DCHECK(rvh == render_view_host()); | 2016 DCHECK(rvh == render_view_host()); |
2001 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(), | 2017 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(), |
2002 page_id); | 2018 page_id); |
2003 // TODO(evan): use directionality of title. | 2019 if (!entry || !UpdateTitleForEntry(entry, title)) |
2004 // http://code.google.com/p/chromium/issues/detail?id=27094 | |
2005 if (!entry || !UpdateTitleForEntry(entry, UTF16ToWide(title.string()))) | |
2006 return; | 2020 return; |
2007 | 2021 |
2008 // Broadcast notifications when the UI should be updated. | 2022 // Broadcast notifications when the UI should be updated. |
2009 if (entry == controller_.GetEntryAtOffset(0)) | 2023 if (entry == controller_.GetEntryAtOffset(0)) |
2010 NotifyNavigationStateChanged(INVALIDATE_TITLE); | 2024 NotifyNavigationStateChanged(INVALIDATE_TITLE); |
2011 } | 2025 } |
2012 | 2026 |
2013 void TabContents::UpdateEncoding(RenderViewHost* render_view_host, | 2027 void TabContents::UpdateEncoding(RenderViewHost* render_view_host, |
2014 const std::string& encoding) { | 2028 const std::string& encoding) { |
2015 set_encoding(encoding); | 2029 set_encoding(encoding); |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2543 | 2557 |
2544 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 2558 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
2545 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 2559 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
2546 rwh_view->SetSize(view()->GetContainerSize()); | 2560 rwh_view->SetSize(view()->GetContainerSize()); |
2547 } | 2561 } |
2548 | 2562 |
2549 void TabContents::OnOnlineStateChanged(bool online) { | 2563 void TabContents::OnOnlineStateChanged(bool online) { |
2550 render_view_host()->Send(new ViewMsg_NetworkStateChanged( | 2564 render_view_host()->Send(new ViewMsg_NetworkStateChanged( |
2551 render_view_host()->routing_id(), online)); | 2565 render_view_host()->routing_id(), online)); |
2552 } | 2566 } |
OLD | NEW |