OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/web_contents/web_contents_impl.h" | 5 #include "content/browser/web_contents/web_contents_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
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 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 const NavigationControllerImpl& WebContentsImpl::GetController() const { | 741 const NavigationControllerImpl& WebContentsImpl::GetController() const { |
742 return controller_; | 742 return controller_; |
743 } | 743 } |
744 | 744 |
745 BrowserContext* WebContentsImpl::GetBrowserContext() const { | 745 BrowserContext* WebContentsImpl::GetBrowserContext() const { |
746 return controller_.GetBrowserContext(); | 746 return controller_.GetBrowserContext(); |
747 } | 747 } |
748 | 748 |
749 const GURL& WebContentsImpl::GetURL() const { | 749 const GURL& WebContentsImpl::GetURL() const { |
750 // We may not have a navigation entry yet | 750 // We may not have a navigation entry yet |
751 NavigationEntry* entry = controller_.GetActiveEntry(); | 751 NavigationEntry* entry = controller_.GetVisibleEntry(); |
752 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); | 752 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
753 } | 753 } |
754 | 754 |
755 WebContentsDelegate* WebContentsImpl::GetDelegate() { | 755 WebContentsDelegate* WebContentsImpl::GetDelegate() { |
756 return delegate_; | 756 return delegate_; |
757 } | 757 } |
758 | 758 |
759 void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) { | 759 void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) { |
760 // TODO(cbentzel): remove this debugging code? | 760 // TODO(cbentzel): remove this debugging code? |
761 if (delegate == delegate_) | 761 if (delegate == delegate_) |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 std::string accept_languages = | 887 std::string accept_languages = |
888 GetContentClient()->browser()->GetAcceptLangs( | 888 GetContentClient()->browser()->GetAcceptLangs( |
889 GetBrowserContext()); | 889 GetBrowserContext()); |
890 if (entry) { | 890 if (entry) { |
891 return entry->GetTitleForDisplay(accept_languages); | 891 return entry->GetTitleForDisplay(accept_languages); |
892 } | 892 } |
893 WebUI* our_web_ui = render_manager_.pending_web_ui() ? | 893 WebUI* our_web_ui = render_manager_.pending_web_ui() ? |
894 render_manager_.pending_web_ui() : render_manager_.web_ui(); | 894 render_manager_.pending_web_ui() : render_manager_.web_ui(); |
895 if (our_web_ui) { | 895 if (our_web_ui) { |
896 // Don't override the title in view source mode. | 896 // Don't override the title in view source mode. |
897 entry = controller_.GetActiveEntry(); | 897 entry = controller_.GetVisibleEntry(); |
898 if (!(entry && entry->IsViewSourceMode())) { | 898 if (!(entry && entry->IsViewSourceMode())) { |
899 // Give the Web UI the chance to override our title. | 899 // Give the Web UI the chance to override our title. |
900 const string16& title = our_web_ui->GetOverriddenTitle(); | 900 const string16& title = our_web_ui->GetOverriddenTitle(); |
901 if (!title.empty()) | 901 if (!title.empty()) |
902 return title; | 902 return title; |
903 } | 903 } |
904 } | 904 } |
905 | 905 |
906 // We use the title for the last committed entry rather than a pending | 906 // We use the title for the last committed entry rather than a pending |
907 // navigation entry. For example, when the user types in a URL, we want to | 907 // navigation entry. For example, when the user types in a URL, we want to |
908 // keep the old page's title until the new load has committed and we get a new | 908 // keep the old page's title until the new load has committed and we get a new |
909 // title. | 909 // title. |
910 entry = controller_.GetLastCommittedEntry(); | 910 entry = controller_.GetLastCommittedEntry(); |
| 911 |
| 912 // We make an exception for initial navigations, because we can have a |
| 913 // committed entry for an initial navigation when doing a history navigation |
| 914 // in a new tab, such as Ctrl+Back. |
| 915 if (entry && controller_.IsInitialNavigation()) |
| 916 entry = controller_.GetVisibleEntry(); |
| 917 |
911 if (entry) { | 918 if (entry) { |
912 return entry->GetTitleForDisplay(accept_languages); | 919 return entry->GetTitleForDisplay(accept_languages); |
913 } | 920 } |
914 | 921 |
915 // |page_title_when_no_navigation_entry_| is finally used | 922 // |page_title_when_no_navigation_entry_| is finally used |
916 // if no title cannot be retrieved. | 923 // if no title cannot be retrieved. |
917 return page_title_when_no_navigation_entry_; | 924 return page_title_when_no_navigation_entry_; |
918 } | 925 } |
919 | 926 |
920 int32 WebContentsImpl::GetMaxPageID() { | 927 int32 WebContentsImpl::GetMaxPageID() { |
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2066 bool is_error_page = (url.spec() == kUnreachableWebDataURL); | 2073 bool is_error_page = (url.spec() == kUnreachableWebDataURL); |
2067 bool is_iframe_srcdoc = (url.spec() == chrome::kAboutSrcDocURL); | 2074 bool is_iframe_srcdoc = (url.spec() == chrome::kAboutSrcDocURL); |
2068 GURL validated_url(url); | 2075 GURL validated_url(url); |
2069 RenderProcessHost* render_process_host = | 2076 RenderProcessHost* render_process_host = |
2070 render_view_host->GetProcess(); | 2077 render_view_host->GetProcess(); |
2071 RenderViewHost::FilterURL(render_process_host, false, &validated_url); | 2078 RenderViewHost::FilterURL(render_process_host, false, &validated_url); |
2072 | 2079 |
2073 if (is_main_frame) | 2080 if (is_main_frame) |
2074 DidChangeLoadProgress(0); | 2081 DidChangeLoadProgress(0); |
2075 | 2082 |
| 2083 // Create a pending entry for this provisional load (if none exists) using the |
| 2084 // current SiteInstance, and ensure the address bar updates accordingly. |
| 2085 // We don't know the referrer or extra headers at this point, but the referrer |
| 2086 // will be set properly upon commit. |
| 2087 if (is_main_frame && !controller_.GetPendingEntry()) { |
| 2088 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( |
| 2089 controller_.CreateNavigationEntry(validated_url, |
| 2090 content::Referrer(), |
| 2091 content::PAGE_TRANSITION_LINK, |
| 2092 true /* is_renderer_initiated */, |
| 2093 std::string(), GetBrowserContext())); |
| 2094 entry->set_site_instance( |
| 2095 static_cast<SiteInstanceImpl*>(GetSiteInstance())); |
| 2096 controller_.SetPendingEntry(entry); |
| 2097 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL); |
| 2098 } |
| 2099 |
2076 // Notify observers about the start of the provisional load. | 2100 // Notify observers about the start of the provisional load. |
2077 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 2101 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
2078 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id, | 2102 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id, |
2079 is_main_frame, validated_url, is_error_page, | 2103 is_main_frame, validated_url, is_error_page, |
2080 is_iframe_srcdoc, render_view_host)); | 2104 is_iframe_srcdoc, render_view_host)); |
2081 | 2105 |
2082 if (is_main_frame) { | 2106 if (is_main_frame) { |
2083 // Notify observers about the provisional change in the main frame URL. | 2107 // Notify observers about the provisional change in the main frame URL. |
2084 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 2108 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
2085 ProvisionalChangeToMainFrameUrl(validated_url, | 2109 ProvisionalChangeToMainFrameUrl(validated_url, |
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3000 // Notify all swapped out RenderViewHosts for this tab. This is important | 3024 // Notify all swapped out RenderViewHosts for this tab. This is important |
3001 // in case we go back to them, or if another window in those processes tries | 3025 // in case we go back to them, or if another window in those processes tries |
3002 // to access window.opener. | 3026 // to access window.opener. |
3003 render_manager_.DidDisownOpener(rvh); | 3027 render_manager_.DidDisownOpener(rvh); |
3004 } | 3028 } |
3005 | 3029 |
3006 void WebContentsImpl::DidUpdateFrameTree(RenderViewHost* rvh) { | 3030 void WebContentsImpl::DidUpdateFrameTree(RenderViewHost* rvh) { |
3007 render_manager_.DidUpdateFrameTree(rvh); | 3031 render_manager_.DidUpdateFrameTree(rvh); |
3008 } | 3032 } |
3009 | 3033 |
| 3034 void WebContentsImpl::DidAccessInitialDocument() { |
| 3035 // Update the URL display. |
| 3036 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL); |
| 3037 } |
| 3038 |
3010 void WebContentsImpl::DocumentAvailableInMainFrame( | 3039 void WebContentsImpl::DocumentAvailableInMainFrame( |
3011 RenderViewHost* render_view_host) { | 3040 RenderViewHost* render_view_host) { |
3012 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3041 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
3013 DocumentAvailableInMainFrame()); | 3042 DocumentAvailableInMainFrame()); |
3014 } | 3043 } |
3015 | 3044 |
3016 void WebContentsImpl::DocumentOnLoadCompletedInMainFrame( | 3045 void WebContentsImpl::DocumentOnLoadCompletedInMainFrame( |
3017 RenderViewHost* render_view_host, | 3046 RenderViewHost* render_view_host, |
3018 int32 page_id) { | 3047 int32 page_id) { |
3019 NotificationService::current()->Notify( | 3048 NotificationService::current()->Notify( |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3510 } | 3539 } |
3511 | 3540 |
3512 BrowserPluginGuestManager* | 3541 BrowserPluginGuestManager* |
3513 WebContentsImpl::GetBrowserPluginGuestManager() const { | 3542 WebContentsImpl::GetBrowserPluginGuestManager() const { |
3514 return static_cast<BrowserPluginGuestManager*>( | 3543 return static_cast<BrowserPluginGuestManager*>( |
3515 GetBrowserContext()->GetUserData( | 3544 GetBrowserContext()->GetUserData( |
3516 browser_plugin::kBrowserPluginGuestManagerKeyName)); | 3545 browser_plugin::kBrowserPluginGuestManagerKeyName)); |
3517 } | 3546 } |
3518 | 3547 |
3519 } // namespace content | 3548 } // namespace content |
OLD | NEW |