| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 // We may not have a navigation entry yet | 437 // We may not have a navigation entry yet |
| 438 NavigationEntry* entry = controller_.GetActiveEntry(); | 438 NavigationEntry* entry = controller_.GetActiveEntry(); |
| 439 return entry ? entry->virtual_url() : GURL::EmptyGURL(); | 439 return entry ? entry->virtual_url() : GURL::EmptyGURL(); |
| 440 } | 440 } |
| 441 | 441 |
| 442 const string16& TabContents::GetTitle() const { | 442 const string16& TabContents::GetTitle() const { |
| 443 // Transient entries take precedence. They are used for interstitial pages | 443 // Transient entries take precedence. They are used for interstitial pages |
| 444 // that are shown on top of existing pages. | 444 // that are shown on top of existing pages. |
| 445 NavigationEntry* entry = controller_.GetTransientEntry(); | 445 NavigationEntry* entry = controller_.GetTransientEntry(); |
| 446 if (entry) { | 446 if (entry) { |
| 447 // TODO(evan): use directionality of title. | |
| 448 // http://code.google.com/p/chromium/issues/detail?id=27094 | |
| 449 return entry->GetTitleForDisplay(profile()->GetPrefs()-> | 447 return entry->GetTitleForDisplay(profile()->GetPrefs()-> |
| 450 GetString(prefs::kAcceptLanguages)).string(); | 448 GetString(prefs::kAcceptLanguages)); |
| 451 } | 449 } |
| 452 WebUI* our_web_ui = render_manager_.pending_web_ui() ? | 450 WebUI* our_web_ui = render_manager_.pending_web_ui() ? |
| 453 render_manager_.pending_web_ui() : render_manager_.web_ui(); | 451 render_manager_.pending_web_ui() : render_manager_.web_ui(); |
| 454 if (our_web_ui) { | 452 if (our_web_ui) { |
| 455 // Don't override the title in view source mode. | 453 // Don't override the title in view source mode. |
| 456 entry = controller_.GetActiveEntry(); | 454 entry = controller_.GetActiveEntry(); |
| 457 if (!(entry && entry->IsViewSourceMode())) { | 455 if (!(entry && entry->IsViewSourceMode())) { |
| 458 // Give the Web UI the chance to override our title. | 456 // Give the Web UI the chance to override our title. |
| 459 // TODO(evan): use directionality of title. | |
| 460 // http://code.google.com/p/chromium/issues/detail?id=27094 | |
| 461 const string16& title = our_web_ui->overridden_title(); | 457 const string16& title = our_web_ui->overridden_title(); |
| 462 if (!title.empty()) | 458 if (!title.empty()) |
| 463 return title; | 459 return title; |
| 464 } | 460 } |
| 465 } | 461 } |
| 466 | 462 |
| 467 // We use the title for the last committed entry rather than a pending | 463 // We use the title for the last committed entry rather than a pending |
| 468 // navigation entry. For example, when the user types in a URL, we want to | 464 // navigation entry. For example, when the user types in a URL, we want to |
| 469 // keep the old page's title until the new load has committed and we get a new | 465 // keep the old page's title until the new load has committed and we get a new |
| 470 // title. | 466 // title. |
| 471 entry = controller_.GetLastCommittedEntry(); | 467 entry = controller_.GetLastCommittedEntry(); |
| 472 if (entry) { | 468 if (entry) { |
| 473 // TODO(evan): use directionality of title. | |
| 474 // http://code.google.com/p/chromium/issues/detail?id=27094 | |
| 475 return entry->GetTitleForDisplay(profile()->GetPrefs()-> | 469 return entry->GetTitleForDisplay(profile()->GetPrefs()-> |
| 476 GetString(prefs::kAcceptLanguages)).string(); | 470 GetString(prefs::kAcceptLanguages)); |
| 477 } | 471 } |
| 478 return EmptyString16(); | 472 return EmptyString16(); |
| 479 } | 473 } |
| 480 | 474 |
| 481 int32 TabContents::GetMaxPageID() { | 475 int32 TabContents::GetMaxPageID() { |
| 482 if (GetSiteInstance()) | 476 if (GetSiteInstance()) |
| 483 return GetSiteInstance()->max_page_id(); | 477 return GetSiteInstance()->max_page_id(); |
| 484 else | 478 else |
| 485 return max_page_id_; | 479 return max_page_id_; |
| 486 } | 480 } |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); | 1084 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); |
| 1091 if (hs) | 1085 if (hs) |
| 1092 hs->AddPage(*add_page_args); | 1086 hs->AddPage(*add_page_args); |
| 1093 } | 1087 } |
| 1094 | 1088 |
| 1095 void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) { | 1089 void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) { |
| 1096 if (profile()->IsOffTheRecord()) | 1090 if (profile()->IsOffTheRecord()) |
| 1097 return; | 1091 return; |
| 1098 | 1092 |
| 1099 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); | 1093 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); |
| 1100 if (hs) { | 1094 if (hs) |
| 1101 // TODO(evan): use directionality of title. | 1095 hs->SetPageTitle(entry.virtual_url(), entry.title()); |
| 1102 // http://code.google.com/p/chromium/issues/detail?id=27094 | |
| 1103 hs->SetPageTitle(entry.virtual_url(), entry.title().string()); | |
| 1104 } | |
| 1105 } | 1096 } |
| 1106 | 1097 |
| 1107 double TabContents::GetZoomLevel() const { | 1098 double TabContents::GetZoomLevel() const { |
| 1108 HostZoomMap* zoom_map = profile()->GetHostZoomMap(); | 1099 HostZoomMap* zoom_map = profile()->GetHostZoomMap(); |
| 1109 if (!zoom_map) | 1100 if (!zoom_map) |
| 1110 return 0; | 1101 return 0; |
| 1111 | 1102 |
| 1112 double zoom_level; | 1103 double zoom_level; |
| 1113 if (temporary_zoom_settings_) { | 1104 if (temporary_zoom_settings_) { |
| 1114 zoom_level = zoom_map->GetTemporaryZoomLevel( | 1105 zoom_level = zoom_map->GetTemporaryZoomLevel( |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1562 // they saw in the URL bar, so we add the virtual URL as a redirect. This | 1553 // they saw in the URL bar, so we add the virtual URL as a redirect. This |
| 1563 // only applies to the main frame, as the virtual URL doesn't apply to | 1554 // only applies to the main frame, as the virtual URL doesn't apply to |
| 1564 // sub-frames. | 1555 // sub-frames. |
| 1565 add_page_args->url = virtual_url; | 1556 add_page_args->url = virtual_url; |
| 1566 if (!add_page_args->redirects.empty()) | 1557 if (!add_page_args->redirects.empty()) |
| 1567 add_page_args->redirects.back() = virtual_url; | 1558 add_page_args->redirects.back() = virtual_url; |
| 1568 } | 1559 } |
| 1569 return add_page_args; | 1560 return add_page_args; |
| 1570 } | 1561 } |
| 1571 | 1562 |
| 1572 bool TabContents::UpdateTitleForEntry( | 1563 bool TabContents::UpdateTitleForEntry(NavigationEntry* entry, |
| 1573 NavigationEntry* entry, | 1564 const std::wstring& title) { |
| 1574 const base::i18n::String16WithDirection& title) { | |
| 1575 // For file URLs without a title, use the pathname instead. In the case of a | 1565 // For file URLs without a title, use the pathname instead. In the case of a |
| 1576 // synthesized title, we don't want the update to count toward the "one set | 1566 // synthesized title, we don't want the update to count toward the "one set |
| 1577 // per page of the title to history." | 1567 // per page of the title to history." |
| 1578 base::i18n::String16WithDirection final_title; | 1568 string16 final_title; |
| 1579 bool explicit_set; | 1569 bool explicit_set; |
| 1580 if (entry->url().SchemeIsFile() && title.is_empty()) { | 1570 if (entry->url().SchemeIsFile() && title.empty()) { |
| 1581 final_title = base::i18n::String16WithDirection( | 1571 final_title = UTF8ToUTF16(entry->url().ExtractFileName()); |
| 1582 UTF8ToUTF16(entry->url().ExtractFileName()), | |
| 1583 base::i18n::LEFT_TO_RIGHT); | |
| 1584 explicit_set = false; // Don't count synthetic titles toward the set limit. | 1572 explicit_set = false; // Don't count synthetic titles toward the set limit. |
| 1585 } else { | 1573 } else { |
| 1586 string16 trimmed; | 1574 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title); |
| 1587 TrimWhitespace(title.string(), TRIM_ALL, &trimmed); | |
| 1588 final_title = base::i18n::String16WithDirection(trimmed, title.direction()); | |
| 1589 explicit_set = true; | 1575 explicit_set = true; |
| 1590 } | 1576 } |
| 1591 | 1577 |
| 1592 if (final_title == entry->title()) | 1578 if (final_title == entry->title()) |
| 1593 return false; // Nothing changed, don't bother. | 1579 return false; // Nothing changed, don't bother. |
| 1594 | 1580 |
| 1595 entry->set_title(final_title); | 1581 entry->set_title(final_title); |
| 1596 | 1582 |
| 1597 if (!received_page_title_) { | 1583 if (!received_page_title_) { |
| 1598 UpdateHistoryPageTitle(*entry); | 1584 UpdateHistoryPageTitle(*entry); |
| 1599 received_page_title_ = explicit_set; | 1585 received_page_title_ = explicit_set; |
| 1600 } | 1586 } |
| 1601 | 1587 |
| 1602 // Lastly, set the title for the view. | 1588 // Lastly, set the title for the view. |
| 1603 // TODO(evan): use directionality of title. | 1589 view_->SetPageTitle(UTF16ToWideHack(final_title)); |
| 1604 // http://code.google.com/p/chromium/issues/detail?id=27094 | |
| 1605 view_->SetPageTitle(UTF16ToWide(final_title.string())); | |
| 1606 | 1590 |
| 1607 NotificationService::current()->Notify( | 1591 NotificationService::current()->Notify( |
| 1608 NotificationType::TAB_CONTENTS_TITLE_UPDATED, | 1592 NotificationType::TAB_CONTENTS_TITLE_UPDATED, |
| 1609 Source<TabContents>(this), | 1593 Source<TabContents>(this), |
| 1610 NotificationService::NoDetails()); | 1594 NotificationService::NoDetails()); |
| 1611 | 1595 |
| 1612 return true; | 1596 return true; |
| 1613 } | 1597 } |
| 1614 | 1598 |
| 1615 void TabContents::NotifySwapped() { | 1599 void TabContents::NotifySwapped() { |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1892 return; | 1876 return; |
| 1893 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index); | 1877 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index); |
| 1894 | 1878 |
| 1895 if (state == entry->content_state()) | 1879 if (state == entry->content_state()) |
| 1896 return; // Nothing to update. | 1880 return; // Nothing to update. |
| 1897 entry->set_content_state(state); | 1881 entry->set_content_state(state); |
| 1898 controller_.NotifyEntryChanged(entry, entry_index); | 1882 controller_.NotifyEntryChanged(entry, entry_index); |
| 1899 } | 1883 } |
| 1900 | 1884 |
| 1901 void TabContents::UpdateTitle(RenderViewHost* rvh, | 1885 void TabContents::UpdateTitle(RenderViewHost* rvh, |
| 1902 int32 page_id, | 1886 int32 page_id, const std::wstring& title) { |
| 1903 const base::i18n::String16WithDirection& title) { | |
| 1904 // If we have a title, that's a pretty good indication that we've started | 1887 // If we have a title, that's a pretty good indication that we've started |
| 1905 // getting useful data. | 1888 // getting useful data. |
| 1906 SetNotWaitingForResponse(); | 1889 SetNotWaitingForResponse(); |
| 1907 | 1890 |
| 1908 DCHECK(rvh == render_view_host()); | 1891 DCHECK(rvh == render_view_host()); |
| 1909 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(), | 1892 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(), |
| 1910 page_id); | 1893 page_id); |
| 1911 if (!entry || !UpdateTitleForEntry(entry, title)) | 1894 if (!entry || !UpdateTitleForEntry(entry, title)) |
| 1912 return; | 1895 return; |
| 1913 | 1896 |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2449 | 2432 |
| 2450 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 2433 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 2451 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 2434 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
| 2452 rwh_view->SetSize(view()->GetContainerSize()); | 2435 rwh_view->SetSize(view()->GetContainerSize()); |
| 2453 } | 2436 } |
| 2454 | 2437 |
| 2455 void TabContents::OnOnlineStateChanged(bool online) { | 2438 void TabContents::OnOnlineStateChanged(bool online) { |
| 2456 render_view_host()->Send(new ViewMsg_NetworkStateChanged( | 2439 render_view_host()->Send(new ViewMsg_NetworkStateChanged( |
| 2457 render_view_host()->routing_id(), online)); | 2440 render_view_host()->routing_id(), online)); |
| 2458 } | 2441 } |
| OLD | NEW |