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 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 const NavigationControllerImpl& WebContentsImpl::GetController() const { | 737 const NavigationControllerImpl& WebContentsImpl::GetController() const { |
738 return controller_; | 738 return controller_; |
739 } | 739 } |
740 | 740 |
741 BrowserContext* WebContentsImpl::GetBrowserContext() const { | 741 BrowserContext* WebContentsImpl::GetBrowserContext() const { |
742 return controller_.GetBrowserContext(); | 742 return controller_.GetBrowserContext(); |
743 } | 743 } |
744 | 744 |
745 const GURL& WebContentsImpl::GetURL() const { | 745 const GURL& WebContentsImpl::GetURL() const { |
746 // We may not have a navigation entry yet. | 746 // We may not have a navigation entry yet. |
747 NavigationEntry* entry = controller_.GetActiveEntry(); | 747 NavigationEntry* entry = controller_.GetVisibleEntry(); |
748 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); | 748 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
749 } | 749 } |
750 | 750 |
751 const GURL& WebContentsImpl::GetActiveURL() const { | 751 const GURL& WebContentsImpl::GetActiveURL() const { |
752 // We may not have a navigation entry yet. | 752 // We may not have a navigation entry yet. |
753 NavigationEntry* entry = controller_.GetActiveEntry(); | 753 NavigationEntry* entry = controller_.GetVisibleEntry(); |
754 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); | 754 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
755 } | 755 } |
756 | 756 |
757 const GURL& WebContentsImpl::GetLastCommittedURL() const { | 757 const GURL& WebContentsImpl::GetLastCommittedURL() const { |
758 // We may not have a navigation entry yet. | 758 // We may not have a navigation entry yet. |
759 NavigationEntry* entry = controller_.GetLastCommittedEntry(); | 759 NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
760 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); | 760 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
761 } | 761 } |
762 | 762 |
763 WebContentsDelegate* WebContentsImpl::GetDelegate() { | 763 WebContentsDelegate* WebContentsImpl::GetDelegate() { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 std::string accept_languages = | 904 std::string accept_languages = |
905 GetContentClient()->browser()->GetAcceptLangs( | 905 GetContentClient()->browser()->GetAcceptLangs( |
906 GetBrowserContext()); | 906 GetBrowserContext()); |
907 if (entry) { | 907 if (entry) { |
908 return entry->GetTitleForDisplay(accept_languages); | 908 return entry->GetTitleForDisplay(accept_languages); |
909 } | 909 } |
910 WebUI* our_web_ui = render_manager_.pending_web_ui() ? | 910 WebUI* our_web_ui = render_manager_.pending_web_ui() ? |
911 render_manager_.pending_web_ui() : render_manager_.web_ui(); | 911 render_manager_.pending_web_ui() : render_manager_.web_ui(); |
912 if (our_web_ui) { | 912 if (our_web_ui) { |
913 // Don't override the title in view source mode. | 913 // Don't override the title in view source mode. |
914 entry = controller_.GetActiveEntry(); | 914 entry = controller_.GetVisibleEntry(); |
915 if (!(entry && entry->IsViewSourceMode())) { | 915 if (!(entry && entry->IsViewSourceMode())) { |
916 // Give the Web UI the chance to override our title. | 916 // Give the Web UI the chance to override our title. |
917 const string16& title = our_web_ui->GetOverriddenTitle(); | 917 const string16& title = our_web_ui->GetOverriddenTitle(); |
918 if (!title.empty()) | 918 if (!title.empty()) |
919 return title; | 919 return title; |
920 } | 920 } |
921 } | 921 } |
922 | 922 |
923 // We use the title for the last committed entry rather than a pending | 923 // We use the title for the last committed entry rather than a pending |
924 // navigation entry. For example, when the user types in a URL, we want to | 924 // navigation entry. For example, when the user types in a URL, we want to |
925 // keep the old page's title until the new load has committed and we get a new | 925 // keep the old page's title until the new load has committed and we get a new |
926 // title. | 926 // title. |
927 entry = controller_.GetLastCommittedEntry(); | 927 entry = controller_.GetLastCommittedEntry(); |
| 928 |
| 929 // We make an exception for initial navigations, because we can have a |
| 930 // committed entry for an initial navigation when doing a history navigation |
| 931 // in a new tab, such as Ctrl+Back. |
| 932 if (entry && controller_.IsInitialNavigation()) |
| 933 entry = controller_.GetVisibleEntry(); |
| 934 |
928 if (entry) { | 935 if (entry) { |
929 return entry->GetTitleForDisplay(accept_languages); | 936 return entry->GetTitleForDisplay(accept_languages); |
930 } | 937 } |
931 | 938 |
932 // |page_title_when_no_navigation_entry_| is finally used | 939 // |page_title_when_no_navigation_entry_| is finally used |
933 // if no title cannot be retrieved. | 940 // if no title cannot be retrieved. |
934 return page_title_when_no_navigation_entry_; | 941 return page_title_when_no_navigation_entry_; |
935 } | 942 } |
936 | 943 |
937 int32 WebContentsImpl::GetMaxPageID() { | 944 int32 WebContentsImpl::GetMaxPageID() { |
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2065 bool is_error_page = (url.spec() == kUnreachableWebDataURL); | 2072 bool is_error_page = (url.spec() == kUnreachableWebDataURL); |
2066 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL); | 2073 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL); |
2067 GURL validated_url(url); | 2074 GURL validated_url(url); |
2068 RenderProcessHost* render_process_host = | 2075 RenderProcessHost* render_process_host = |
2069 render_view_host->GetProcess(); | 2076 render_view_host->GetProcess(); |
2070 RenderViewHost::FilterURL(render_process_host, false, &validated_url); | 2077 RenderViewHost::FilterURL(render_process_host, false, &validated_url); |
2071 | 2078 |
2072 if (is_main_frame) | 2079 if (is_main_frame) |
2073 DidChangeLoadProgress(0); | 2080 DidChangeLoadProgress(0); |
2074 | 2081 |
| 2082 // Create a pending entry for this provisional load (if none exists) using the |
| 2083 // current SiteInstance, and ensure the address bar updates accordingly. |
| 2084 // We don't know the referrer or extra headers at this point, but the referrer |
| 2085 // will be set properly upon commit. |
| 2086 if (is_main_frame && !controller_.GetPendingEntry()) { |
| 2087 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( |
| 2088 controller_.CreateNavigationEntry(validated_url, |
| 2089 content::Referrer(), |
| 2090 content::PAGE_TRANSITION_LINK, |
| 2091 true /* is_renderer_initiated */, |
| 2092 std::string(), GetBrowserContext())); |
| 2093 entry->set_site_instance( |
| 2094 static_cast<SiteInstanceImpl*>(GetSiteInstance())); |
| 2095 controller_.SetPendingEntry(entry); |
| 2096 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL); |
| 2097 } |
| 2098 |
2075 // Notify observers about the start of the provisional load. | 2099 // Notify observers about the start of the provisional load. |
2076 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 2100 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
2077 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id, | 2101 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id, |
2078 is_main_frame, validated_url, is_error_page, | 2102 is_main_frame, validated_url, is_error_page, |
2079 is_iframe_srcdoc, render_view_host)); | 2103 is_iframe_srcdoc, render_view_host)); |
2080 | 2104 |
2081 if (is_main_frame) { | 2105 if (is_main_frame) { |
2082 // Notify observers about the provisional change in the main frame URL. | 2106 // Notify observers about the provisional change in the main frame URL. |
2083 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 2107 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
2084 ProvisionalChangeToMainFrameUrl(validated_url, | 2108 ProvisionalChangeToMainFrameUrl(validated_url, |
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3057 RemoveDestructionObserver(opener_); | 3081 RemoveDestructionObserver(opener_); |
3058 opener_ = NULL; | 3082 opener_ = NULL; |
3059 } | 3083 } |
3060 | 3084 |
3061 // Notify all swapped out RenderViewHosts for this tab. This is important | 3085 // Notify all swapped out RenderViewHosts for this tab. This is important |
3062 // in case we go back to them, or if another window in those processes tries | 3086 // in case we go back to them, or if another window in those processes tries |
3063 // to access window.opener. | 3087 // to access window.opener. |
3064 render_manager_.DidDisownOpener(rvh); | 3088 render_manager_.DidDisownOpener(rvh); |
3065 } | 3089 } |
3066 | 3090 |
| 3091 void WebContentsImpl::DidAccessInitialDocument() { |
| 3092 // Update the URL display. |
| 3093 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL); |
| 3094 } |
| 3095 |
3067 void WebContentsImpl::DocumentAvailableInMainFrame( | 3096 void WebContentsImpl::DocumentAvailableInMainFrame( |
3068 RenderViewHost* render_view_host) { | 3097 RenderViewHost* render_view_host) { |
3069 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3098 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
3070 DocumentAvailableInMainFrame()); | 3099 DocumentAvailableInMainFrame()); |
3071 } | 3100 } |
3072 | 3101 |
3073 void WebContentsImpl::DocumentOnLoadCompletedInMainFrame( | 3102 void WebContentsImpl::DocumentOnLoadCompletedInMainFrame( |
3074 RenderViewHost* render_view_host, | 3103 RenderViewHost* render_view_host, |
3075 int32 page_id) { | 3104 int32 page_id) { |
3076 NotificationService::current()->Notify( | 3105 NotificationService::current()->Notify( |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3580 } | 3609 } |
3581 | 3610 |
3582 BrowserPluginGuestManager* | 3611 BrowserPluginGuestManager* |
3583 WebContentsImpl::GetBrowserPluginGuestManager() const { | 3612 WebContentsImpl::GetBrowserPluginGuestManager() const { |
3584 return static_cast<BrowserPluginGuestManager*>( | 3613 return static_cast<BrowserPluginGuestManager*>( |
3585 GetBrowserContext()->GetUserData( | 3614 GetBrowserContext()->GetUserData( |
3586 browser_plugin::kBrowserPluginGuestManagerKeyName)); | 3615 browser_plugin::kBrowserPluginGuestManagerKeyName)); |
3587 } | 3616 } |
3588 | 3617 |
3589 } // namespace content | 3618 } // namespace content |
OLD | NEW |