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" |
11 #include "base/metrics/stats_counters.h" | 11 #include "base/metrics/stats_counters.h" |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "chrome/browser/browser_shutdown.h" | 16 #include "chrome/browser/browser_shutdown.h" |
17 #include "chrome/browser/debugger/devtools_manager.h" | 17 #include "chrome/browser/debugger/devtools_manager.h" |
18 #include "chrome/browser/defaults.h" | |
19 #include "chrome/browser/load_from_memory_cache_details.h" | 18 #include "chrome/browser/load_from_memory_cache_details.h" |
20 #include "chrome/browser/notifications/desktop_notification_service.h" | 19 #include "chrome/browser/notifications/desktop_notification_service.h" |
21 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 20 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
22 #include "chrome/browser/prefs/pref_service.h" | |
23 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/renderer_host/web_cache_manager.h" | 22 #include "chrome/browser/renderer_host/web_cache_manager.h" |
25 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" | 23 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" |
26 #include "chrome/browser/ui/browser_dialogs.h" | 24 #include "chrome/browser/ui/browser_dialogs.h" |
27 #include "chrome/common/chrome_constants.h" | 25 #include "chrome/common/chrome_constants.h" |
28 #include "chrome/common/pref_names.h" | |
29 #include "chrome/common/render_messages.h" | 26 #include "chrome/common/render_messages.h" |
30 #include "content/browser/child_process_security_policy.h" | 27 #include "content/browser/child_process_security_policy.h" |
31 #include "content/browser/content_browser_client.h" | 28 #include "content/browser/content_browser_client.h" |
32 #include "content/browser/host_zoom_map.h" | 29 #include "content/browser/host_zoom_map.h" |
33 #include "content/browser/in_process_webkit/session_storage_namespace.h" | 30 #include "content/browser/in_process_webkit/session_storage_namespace.h" |
34 #include "content/browser/load_notification_details.h" | 31 #include "content/browser/load_notification_details.h" |
35 #include "content/browser/renderer_host/render_process_host.h" | 32 #include "content/browser/renderer_host/render_process_host.h" |
36 #include "content/browser/renderer_host/render_view_host.h" | 33 #include "content/browser/renderer_host/render_view_host.h" |
37 #include "content/browser/renderer_host/render_widget_host_view.h" | 34 #include "content/browser/renderer_host/render_widget_host_view.h" |
38 #include "content/browser/renderer_host/resource_request_details.h" | 35 #include "content/browser/renderer_host/resource_request_details.h" |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 const GURL& TabContents::GetURL() const { | 321 const GURL& TabContents::GetURL() const { |
325 // We may not have a navigation entry yet | 322 // We may not have a navigation entry yet |
326 NavigationEntry* entry = controller_.GetActiveEntry(); | 323 NavigationEntry* entry = controller_.GetActiveEntry(); |
327 return entry ? entry->virtual_url() : GURL::EmptyGURL(); | 324 return entry ? entry->virtual_url() : GURL::EmptyGURL(); |
328 } | 325 } |
329 | 326 |
330 const string16& TabContents::GetTitle() const { | 327 const string16& TabContents::GetTitle() const { |
331 // Transient entries take precedence. They are used for interstitial pages | 328 // Transient entries take precedence. They are used for interstitial pages |
332 // that are shown on top of existing pages. | 329 // that are shown on top of existing pages. |
333 NavigationEntry* entry = controller_.GetTransientEntry(); | 330 NavigationEntry* entry = controller_.GetTransientEntry(); |
| 331 std::string accept_languages = |
| 332 content::GetContentClient()->browser()->GetAcceptLangs(this); |
334 if (entry) { | 333 if (entry) { |
335 return entry->GetTitleForDisplay(profile()->GetPrefs()-> | 334 return entry->GetTitleForDisplay(accept_languages); |
336 GetString(prefs::kAcceptLanguages)); | |
337 } | 335 } |
338 WebUI* our_web_ui = render_manager_.pending_web_ui() ? | 336 WebUI* our_web_ui = render_manager_.pending_web_ui() ? |
339 render_manager_.pending_web_ui() : render_manager_.web_ui(); | 337 render_manager_.pending_web_ui() : render_manager_.web_ui(); |
340 if (our_web_ui) { | 338 if (our_web_ui) { |
341 // Don't override the title in view source mode. | 339 // Don't override the title in view source mode. |
342 entry = controller_.GetActiveEntry(); | 340 entry = controller_.GetActiveEntry(); |
343 if (!(entry && entry->IsViewSourceMode())) { | 341 if (!(entry && entry->IsViewSourceMode())) { |
344 // Give the Web UI the chance to override our title. | 342 // Give the Web UI the chance to override our title. |
345 const string16& title = our_web_ui->overridden_title(); | 343 const string16& title = our_web_ui->overridden_title(); |
346 if (!title.empty()) | 344 if (!title.empty()) |
347 return title; | 345 return title; |
348 } | 346 } |
349 } | 347 } |
350 | 348 |
351 // We use the title for the last committed entry rather than a pending | 349 // We use the title for the last committed entry rather than a pending |
352 // navigation entry. For example, when the user types in a URL, we want to | 350 // navigation entry. For example, when the user types in a URL, we want to |
353 // keep the old page's title until the new load has committed and we get a new | 351 // keep the old page's title until the new load has committed and we get a new |
354 // title. | 352 // title. |
355 entry = controller_.GetLastCommittedEntry(); | 353 entry = controller_.GetLastCommittedEntry(); |
356 if (entry) { | 354 if (entry) { |
357 return entry->GetTitleForDisplay(profile()->GetPrefs()-> | 355 return entry->GetTitleForDisplay(accept_languages); |
358 GetString(prefs::kAcceptLanguages)); | |
359 } | 356 } |
360 return EmptyString16(); | 357 return EmptyString16(); |
361 } | 358 } |
362 | 359 |
363 int32 TabContents::GetMaxPageID() { | 360 int32 TabContents::GetMaxPageID() { |
364 if (GetSiteInstance()) | 361 if (GetSiteInstance()) |
365 return GetSiteInstance()->max_page_id(); | 362 return GetSiteInstance()->max_page_id(); |
366 else | 363 else |
367 return max_page_id_; | 364 return max_page_id_; |
368 } | 365 } |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 | 660 |
664 void TabContents::SetFocusToLocationBar(bool select_all) { | 661 void TabContents::SetFocusToLocationBar(bool select_all) { |
665 if (delegate()) | 662 if (delegate()) |
666 delegate()->SetFocusToLocationBar(select_all); | 663 delegate()->SetFocusToLocationBar(select_all); |
667 } | 664 } |
668 | 665 |
669 bool TabContents::ShouldShowBookmarkBar() { | 666 bool TabContents::ShouldShowBookmarkBar() { |
670 if (showing_interstitial_page()) | 667 if (showing_interstitial_page()) |
671 return false; | 668 return false; |
672 | 669 |
673 // Do not show bookmarks bar if bookmarks aren't enabled. | |
674 if (!browser_defaults::bookmarks_enabled) | |
675 return false; | |
676 | |
677 if (!profile()->GetPrefs()->GetBoolean(prefs::kEnableBookmarkBar)) | |
678 return false; | |
679 | |
680 // See GetWebUIForCurrentState() comment for more info. This case is very | 670 // See GetWebUIForCurrentState() comment for more info. This case is very |
681 // similar, but for non-first loads, we want to use the committed entry. This | 671 // similar, but for non-first loads, we want to use the committed entry. This |
682 // is so the bookmarks bar disappears at the same time the page does. | 672 // is so the bookmarks bar disappears at the same time the page does. |
683 if (controller_.GetLastCommittedEntry()) { | 673 if (controller_.GetLastCommittedEntry()) { |
684 // Not the first load, always use the committed Web UI. | 674 // Not the first load, always use the committed Web UI. |
685 return (render_manager_.web_ui() == NULL) ? | 675 return (render_manager_.web_ui() == NULL) ? |
686 false : render_manager_.web_ui()->force_bookmark_bar_visible(); | 676 false : render_manager_.web_ui()->force_bookmark_bar_visible(); |
687 } | 677 } |
688 | 678 |
689 // When it's the first load, we know either the pending one or the committed | 679 // When it's the first load, we know either the pending one or the committed |
(...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1721 } | 1711 } |
1722 | 1712 |
1723 void TabContents::LoadStateChanged(const GURL& url, | 1713 void TabContents::LoadStateChanged(const GURL& url, |
1724 net::LoadState load_state, | 1714 net::LoadState load_state, |
1725 uint64 upload_position, | 1715 uint64 upload_position, |
1726 uint64 upload_size) { | 1716 uint64 upload_size) { |
1727 load_state_ = load_state; | 1717 load_state_ = load_state; |
1728 upload_position_ = upload_position; | 1718 upload_position_ = upload_position; |
1729 upload_size_ = upload_size; | 1719 upload_size_ = upload_size; |
1730 load_state_host_ = net::IDNToUnicode(url.host(), | 1720 load_state_host_ = net::IDNToUnicode(url.host(), |
1731 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 1721 content::GetContentClient()->browser()->GetAcceptLangs(this)); |
1732 if (load_state_ == net::LOAD_STATE_READING_RESPONSE) | 1722 if (load_state_ == net::LOAD_STATE_READING_RESPONSE) |
1733 SetNotWaitingForResponse(); | 1723 SetNotWaitingForResponse(); |
1734 if (is_loading()) | 1724 if (is_loading()) |
1735 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB); | 1725 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB); |
1736 } | 1726 } |
1737 | 1727 |
1738 bool TabContents::IsExternalTabContainer() const { | 1728 bool TabContents::IsExternalTabContainer() const { |
1739 if (!delegate()) | 1729 if (!delegate()) |
1740 return false; | 1730 return false; |
1741 | 1731 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1871 | 1861 |
1872 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 1862 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
1873 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 1863 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
1874 rwh_view->SetSize(view()->GetContainerSize()); | 1864 rwh_view->SetSize(view()->GetContainerSize()); |
1875 } | 1865 } |
1876 | 1866 |
1877 void TabContents::OnOnlineStateChanged(bool online) { | 1867 void TabContents::OnOnlineStateChanged(bool online) { |
1878 render_view_host()->Send(new ViewMsg_NetworkStateChanged( | 1868 render_view_host()->Send(new ViewMsg_NetworkStateChanged( |
1879 render_view_host()->routing_id(), online)); | 1869 render_view_host()->routing_id(), online)); |
1880 } | 1870 } |
OLD | NEW |