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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <cmath> | 9 #include <cmath> |
10 #include <utility> | 10 #include <utility> |
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1079 | 1079 |
1080 if (entry) { | 1080 if (entry) { |
1081 return entry->GetTitleForDisplay(); | 1081 return entry->GetTitleForDisplay(); |
1082 } | 1082 } |
1083 | 1083 |
1084 // |page_title_when_no_navigation_entry_| is finally used | 1084 // |page_title_when_no_navigation_entry_| is finally used |
1085 // if no title cannot be retrieved. | 1085 // if no title cannot be retrieved. |
1086 return page_title_when_no_navigation_entry_; | 1086 return page_title_when_no_navigation_entry_; |
1087 } | 1087 } |
1088 | 1088 |
1089 void WebContentsImpl::UpdateTitleForEntry(NavigationEntry* entry, | |
Charlie Reis
2016/07/13 21:02:23
nit: I think it's probably better to leave this in
afakhry
2016/07/13 22:10:27
Done.
| |
1090 const base::string16& title) { | |
1091 // For file URLs without a title, use the pathname instead. In the case of a | |
1092 // synthesized title, we don't want the update to count toward the "one set | |
1093 // per page of the title to history." | |
1094 base::string16 final_title; | |
1095 bool explicit_set; | |
1096 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) { | |
1097 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName()); | |
1098 explicit_set = false; // Don't count synthetic titles toward the set limit. | |
1099 } else { | |
1100 base::TrimWhitespace(title, base::TRIM_ALL, &final_title); | |
1101 explicit_set = true; | |
1102 } | |
1103 | |
1104 // If a page is created via window.open and never navigated, | |
1105 // there will be no navigation entry. In this situation, | |
1106 // |page_title_when_no_navigation_entry_| will be used for page title. | |
1107 if (entry) { | |
1108 if (final_title == entry->GetTitle()) | |
1109 return; // Nothing changed, don't bother. | |
1110 | |
1111 entry->SetTitle(final_title); | |
1112 } else { | |
1113 if (page_title_when_no_navigation_entry_ == final_title) | |
1114 return; // Nothing changed, don't bother. | |
1115 | |
1116 page_title_when_no_navigation_entry_ = final_title; | |
1117 } | |
1118 | |
1119 // Lastly, set the title for the view. | |
1120 view_->SetPageTitle(final_title); | |
1121 | |
1122 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | |
1123 TitleWasSet(entry, explicit_set)); | |
1124 | |
1125 // Broadcast notifications when the UI should be updated. | |
1126 if (entry == controller_.GetEntryAtOffset(0)) | |
1127 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE); | |
1128 } | |
1129 | |
1089 int32_t WebContentsImpl::GetMaxPageID() { | 1130 int32_t WebContentsImpl::GetMaxPageID() { |
1090 return GetMaxPageIDForSiteInstance(GetSiteInstance()); | 1131 return GetMaxPageIDForSiteInstance(GetSiteInstance()); |
1091 } | 1132 } |
1092 | 1133 |
1093 int32_t WebContentsImpl::GetMaxPageIDForSiteInstance( | 1134 int32_t WebContentsImpl::GetMaxPageIDForSiteInstance( |
1094 SiteInstance* site_instance) { | 1135 SiteInstance* site_instance) { |
1095 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end()) | 1136 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end()) |
1096 max_page_ids_[site_instance->GetId()] = -1; | 1137 max_page_ids_[site_instance->GetId()] = -1; |
1097 | 1138 |
1098 return max_page_ids_[site_instance->GetId()]; | 1139 return max_page_ids_[site_instance->GetId()]; |
(...skipping 2774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3873 // navigating (to avoid a race between the browser updating max_page_id and | 3914 // navigating (to avoid a race between the browser updating max_page_id and |
3874 // the renderer updating next_page_id_). Because of this, we only call this | 3915 // the renderer updating next_page_id_). Because of this, we only call this |
3875 // from CreateRenderView and allow that to notify the RenderView for us. | 3916 // from CreateRenderView and allow that to notify the RenderView for us. |
3876 int max_restored_page_id = controller_.GetMaxRestoredPageID(); | 3917 int max_restored_page_id = controller_.GetMaxRestoredPageID(); |
3877 if (max_restored_page_id > | 3918 if (max_restored_page_id > |
3878 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance())) | 3919 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance())) |
3879 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(), | 3920 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(), |
3880 max_restored_page_id); | 3921 max_restored_page_id); |
3881 } | 3922 } |
3882 | 3923 |
3883 bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry, | |
3884 const base::string16& title) { | |
3885 // For file URLs without a title, use the pathname instead. In the case of a | |
3886 // synthesized title, we don't want the update to count toward the "one set | |
3887 // per page of the title to history." | |
3888 base::string16 final_title; | |
3889 bool explicit_set; | |
3890 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) { | |
3891 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName()); | |
3892 explicit_set = false; // Don't count synthetic titles toward the set limit. | |
3893 } else { | |
3894 base::TrimWhitespace(title, base::TRIM_ALL, &final_title); | |
3895 explicit_set = true; | |
3896 } | |
3897 | |
3898 // If a page is created via window.open and never navigated, | |
3899 // there will be no navigation entry. In this situation, | |
3900 // |page_title_when_no_navigation_entry_| will be used for page title. | |
3901 if (entry) { | |
3902 if (final_title == entry->GetTitle()) | |
3903 return false; // Nothing changed, don't bother. | |
3904 | |
3905 entry->SetTitle(final_title); | |
3906 } else { | |
3907 if (page_title_when_no_navigation_entry_ == final_title) | |
3908 return false; // Nothing changed, don't bother. | |
3909 | |
3910 page_title_when_no_navigation_entry_ = final_title; | |
3911 } | |
3912 | |
3913 // Lastly, set the title for the view. | |
3914 view_->SetPageTitle(final_title); | |
3915 | |
3916 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | |
3917 TitleWasSet(entry, explicit_set)); | |
3918 | |
3919 return true; | |
3920 } | |
3921 | |
3922 void WebContentsImpl::SendChangeLoadProgress() { | 3924 void WebContentsImpl::SendChangeLoadProgress() { |
3923 loading_last_progress_update_ = base::TimeTicks::Now(); | 3925 loading_last_progress_update_ = base::TimeTicks::Now(); |
3924 if (delegate_) | 3926 if (delegate_) |
3925 delegate_->LoadProgressChanged(this, frame_tree_.load_progress()); | 3927 delegate_->LoadProgressChanged(this, frame_tree_.load_progress()); |
3926 } | 3928 } |
3927 | 3929 |
3928 void WebContentsImpl::ResetLoadProgressState() { | 3930 void WebContentsImpl::ResetLoadProgressState() { |
3929 frame_tree_.ResetLoadProgress(); | 3931 frame_tree_.ResetLoadProgress(); |
3930 loading_weak_factory_.InvalidateWeakPtrs(); | 3932 loading_weak_factory_.InvalidateWeakPtrs(); |
3931 loading_last_progress_update_ = base::TimeTicks(); | 3933 loading_last_progress_update_ = base::TimeTicks(); |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4515 } | 4517 } |
4516 | 4518 |
4517 // We can handle title updates when we don't have an entry in | 4519 // We can handle title updates when we don't have an entry in |
4518 // UpdateTitleForEntry, but only if the update is from the current RVH. | 4520 // UpdateTitleForEntry, but only if the update is from the current RVH. |
4519 // TODO(avi): Change to make decisions based on the RenderFrameHost. | 4521 // TODO(avi): Change to make decisions based on the RenderFrameHost. |
4520 if (!entry && render_frame_host != GetMainFrame()) | 4522 if (!entry && render_frame_host != GetMainFrame()) |
4521 return; | 4523 return; |
4522 | 4524 |
4523 // TODO(evan): make use of title_direction. | 4525 // TODO(evan): make use of title_direction. |
4524 // http://code.google.com/p/chromium/issues/detail?id=27094 | 4526 // http://code.google.com/p/chromium/issues/detail?id=27094 |
4525 if (!UpdateTitleForEntry(entry, title)) | 4527 UpdateTitleForEntry(entry, title); |
4526 return; | |
4527 | |
4528 // Broadcast notifications when the UI should be updated. | |
4529 if (entry == controller_.GetEntryAtOffset(0)) | |
4530 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE); | |
4531 } | 4528 } |
4532 | 4529 |
4533 void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host, | 4530 void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host, |
4534 const std::string& encoding) { | 4531 const std::string& encoding) { |
4535 SetEncoding(encoding); | 4532 SetEncoding(encoding); |
4536 } | 4533 } |
4537 | 4534 |
4538 void WebContentsImpl::DocumentAvailableInMainFrame( | 4535 void WebContentsImpl::DocumentAvailableInMainFrame( |
4539 RenderViewHost* render_view_host) { | 4536 RenderViewHost* render_view_host) { |
4540 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 4537 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5161 for (RenderViewHost* render_view_host : render_view_host_set) | 5158 for (RenderViewHost* render_view_host : render_view_host_set) |
5162 render_view_host->OnWebkitPreferencesChanged(); | 5159 render_view_host->OnWebkitPreferencesChanged(); |
5163 } | 5160 } |
5164 | 5161 |
5165 void WebContentsImpl::SetJavaScriptDialogManagerForTesting( | 5162 void WebContentsImpl::SetJavaScriptDialogManagerForTesting( |
5166 JavaScriptDialogManager* dialog_manager) { | 5163 JavaScriptDialogManager* dialog_manager) { |
5167 dialog_manager_ = dialog_manager; | 5164 dialog_manager_ = dialog_manager; |
5168 } | 5165 } |
5169 | 5166 |
5170 } // namespace content | 5167 } // namespace content |
OLD | NEW |