Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/web_contents.h" | 5 #include "chrome/browser/web_contents.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/file_version_info.h" | 9 #include "base/file_version_info.h" |
| 10 #include "chrome/app/locales/locale_settings.h" | 10 #include "chrome/app/locales/locale_settings.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "chrome/browser/navigation_entry.h" | 27 #include "chrome/browser/navigation_entry.h" |
| 28 #include "chrome/browser/password_manager.h" | 28 #include "chrome/browser/password_manager.h" |
| 29 #include "chrome/browser/plugin_installer.h" | 29 #include "chrome/browser/plugin_installer.h" |
| 30 #include "chrome/browser/plugin_service.h" | 30 #include "chrome/browser/plugin_service.h" |
| 31 #include "chrome/browser/printing/print_job.h" | 31 #include "chrome/browser/printing/print_job.h" |
| 32 #include "chrome/browser/render_view_host.h" | 32 #include "chrome/browser/render_view_host.h" |
| 33 #include "chrome/browser/render_widget_host_view_win.h" // TODO(brettw) delete me. | 33 #include "chrome/browser/render_widget_host_view_win.h" // TODO(brettw) delete me. |
| 34 #include "chrome/browser/template_url_fetcher.h" | 34 #include "chrome/browser/template_url_fetcher.h" |
| 35 #include "chrome/browser/template_url_model.h" | 35 #include "chrome/browser/template_url_model.h" |
| 36 #include "chrome/browser/views/hung_renderer_view.h" // TODO(brettw) delete me. | 36 #include "chrome/browser/views/hung_renderer_view.h" // TODO(brettw) delete me. |
| 37 #include "chrome/browser/views/sad_tab_view.h" // FIXME(brettw) delete me. | |
| 38 #include "chrome/browser/web_contents_view.h" | 37 #include "chrome/browser/web_contents_view.h" |
| 39 #include "chrome/browser/web_contents_view_win.h" | 38 #include "chrome/browser/web_contents_view_win.h" |
| 40 #include "chrome/common/chrome_switches.h" | 39 #include "chrome/common/chrome_switches.h" |
| 41 #include "chrome/common/l10n_util.h" | 40 #include "chrome/common/l10n_util.h" |
| 42 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
| 43 #include "chrome/common/pref_service.h" | 42 #include "chrome/common/pref_service.h" |
| 44 #include "chrome/common/resource_bundle.h" | 43 #include "chrome/common/resource_bundle.h" |
| 45 #include "net/base/mime_util.h" | 44 #include "net/base/mime_util.h" |
| 46 #include "net/base/registry_controlled_domain.h" | 45 #include "net/base/registry_controlled_domain.h" |
| 47 #include "webkit/glue/webkit_glue.h" | 46 #include "webkit/glue/webkit_glue.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 WebContents::WebContents(Profile* profile, | 169 WebContents::WebContents(Profile* profile, |
| 171 SiteInstance* site_instance, | 170 SiteInstance* site_instance, |
| 172 RenderViewHostFactory* render_view_factory, | 171 RenderViewHostFactory* render_view_factory, |
| 173 int routing_id, | 172 int routing_id, |
| 174 HANDLE modal_dialog_event) | 173 HANDLE modal_dialog_event) |
| 175 : TabContents(TAB_CONTENTS_WEB), | 174 : TabContents(TAB_CONTENTS_WEB), |
| 176 view_(new WebContentsViewWin(this)), | 175 view_(new WebContentsViewWin(this)), |
| 177 ALLOW_THIS_IN_INITIALIZER_LIST( | 176 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 178 render_manager_(render_view_factory, this, this)), | 177 render_manager_(render_view_factory, this, this)), |
| 179 render_view_factory_(render_view_factory), | 178 render_view_factory_(render_view_factory), |
| 180 has_page_title_(false), | 179 received_page_title_(false), |
| 181 is_starred_(false), | 180 is_starred_(false), |
| 182 printing_(*this), | 181 printing_(*this), |
| 183 notify_disconnection_(false), | 182 notify_disconnection_(false), |
| 184 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), | 183 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), |
| 185 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)), | 184 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)), |
| 186 suppress_javascript_messages_(false), | 185 suppress_javascript_messages_(false), |
| 187 load_state_(net::LOAD_STATE_IDLE) { | 186 load_state_(net::LOAD_STATE_IDLE) { |
| 188 InitWebContentsClass(); | 187 InitWebContentsClass(); |
| 189 | 188 |
| 190 pending_install_.page_id = 0; | 189 pending_install_.page_id = 0; |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 739 if (!printing_.OnRendererGone(rvh)) | 738 if (!printing_.OnRendererGone(rvh)) |
| 740 return; | 739 return; |
| 741 if (rvh != render_view_host()) { | 740 if (rvh != render_view_host()) { |
| 742 // The pending or interstitial page's RenderViewHost is gone. If we are | 741 // The pending or interstitial page's RenderViewHost is gone. If we are |
| 743 // showing an interstitial, this may mean that the original RenderViewHost | 742 // showing an interstitial, this may mean that the original RenderViewHost |
| 744 // is gone. If so, we will call RendererGone again if we try to swap that | 743 // is gone. If so, we will call RendererGone again if we try to swap that |
| 745 // RenderViewHost back in, in SwapToRenderView. | 744 // RenderViewHost back in, in SwapToRenderView. |
| 746 return; | 745 return; |
| 747 } | 746 } |
| 748 | 747 |
| 749 // TODO(brettw) move the platform-specific view stuff here to the view. | |
| 750 | |
| 751 // Force an invalidation here to render sad tab. however, it is possible for | |
| 752 // our window to have already gone away (since we may be in the process of | |
| 753 // closing this render view). | |
| 754 if (::IsWindow(view_->GetContainerHWND())) | |
| 755 InvalidateRect(view_->GetContainerHWND(), NULL, FALSE); | |
| 756 | |
| 757 SetIsLoading(false, NULL); | 748 SetIsLoading(false, NULL); |
| 758 | |
| 759 // Ensure that this browser window is enabled. This deals with the case where | |
| 760 // a renderer crashed while showing a modal dialog. We're assuming that the | |
| 761 // browser code will never show a modal dialog, so we could only be disabled | |
| 762 // by something the renderer (or some plug-in) did. | |
| 763 HWND root_window = ::GetAncestor(view_->GetContainerHWND(), GA_ROOT); | |
| 764 if (!::IsWindowEnabled(root_window)) | |
| 765 ::EnableWindow(root_window, TRUE); | |
| 766 | |
| 767 NotifyDisconnected(); | 749 NotifyDisconnected(); |
| 768 SetIsCrashed(true); | 750 SetIsCrashed(true); |
| 751 | |
| 752 // Force an invalidation to render sad tab. The view will notice we crashed | |
| 753 // when it paints. | |
| 754 view_->Invalidate(); | |
| 755 | |
| 769 // Hide any visible hung renderer warning for this web contents' process. | 756 // Hide any visible hung renderer warning for this web contents' process. |
| 770 HungRendererWarning::HideForWebContents(this); | 757 HungRendererWarning::HideForWebContents(this); |
| 771 } | 758 } |
| 772 | 759 |
| 773 void WebContents::DidNavigate(RenderViewHost* rvh, | 760 void WebContents::DidNavigate(RenderViewHost* rvh, |
| 774 const ViewHostMsg_FrameNavigate_Params& params) { | 761 const ViewHostMsg_FrameNavigate_Params& params) { |
| 775 if (PageTransition::IsMainFrame(params.transition)) | 762 if (PageTransition::IsMainFrame(params.transition)) |
| 776 render_manager_.DidNavigateMainFrame(rvh); | 763 render_manager_.DidNavigateMainFrame(rvh); |
| 777 | 764 |
| 778 // In the case of interstitial, we don't mess with the navigation entries. | 765 // In the case of interstitial, we don't mess with the navigation entries. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 850 unsigned changed_flags = 0; | 837 unsigned changed_flags = 0; |
| 851 | 838 |
| 852 // Update the URL. | 839 // Update the URL. |
| 853 if (url != entry->url()) { | 840 if (url != entry->url()) { |
| 854 changed_flags |= INVALIDATE_URL; | 841 changed_flags |= INVALIDATE_URL; |
| 855 if (entry == controller()->GetActiveEntry()) | 842 if (entry == controller()->GetActiveEntry()) |
| 856 fav_icon_helper_.FetchFavIcon(url); | 843 fav_icon_helper_.FetchFavIcon(url); |
| 857 entry->set_url(url); | 844 entry->set_url(url); |
| 858 } | 845 } |
| 859 | 846 |
| 860 // For file URLs without a title, use the pathname instead. | 847 // Save the new title if it changed. |
| 861 std::wstring final_title; | 848 if (UpdateTitleForEntry(entry, title)) |
| 862 if (url.SchemeIsFile() && title.empty()) { | |
| 863 final_title = UTF8ToWide(url.ExtractFileName()); | |
| 864 } else { | |
| 865 TrimWhitespace(title, TRIM_ALL, &final_title); | |
| 866 } | |
| 867 if (final_title != entry->title()) { | |
| 868 changed_flags |= INVALIDATE_TITLE; | 849 changed_flags |= INVALIDATE_TITLE; |
| 869 entry->set_title(final_title); | |
| 870 | |
| 871 // Update the history system for this page. | |
| 872 if (!profile()->IsOffTheRecord()) { | |
| 873 HistoryService* hs = | |
| 874 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); | |
| 875 if (hs) | |
| 876 hs->SetPageTitle(entry->display_url(), final_title); | |
| 877 } | |
| 878 } | |
| 879 // TODO(brettw) move this to the view. | |
| 880 if (view_->GetContainerHWND()) { | |
| 881 // It's possible to get this after the hwnd has been destroyed. | |
| 882 ::SetWindowText(view_->GetContainerHWND(), title.c_str()); | |
| 883 ::SetWindowText(render_widget_host_view()->GetPluginHWND(), title.c_str()); | |
| 884 } | |
| 885 | 850 |
| 886 // Update the state (forms, etc.). | 851 // Update the state (forms, etc.). |
| 887 if (state != entry->content_state()) | 852 if (state != entry->content_state()) |
| 888 entry->set_content_state(state); | 853 entry->set_content_state(state); |
| 889 | 854 |
| 890 // Notify everybody of the changes (only when the current page changed). | 855 // Notify everybody of the changes (only when the current page changed). |
| 891 if (changed_flags && entry == controller()->GetActiveEntry()) | 856 if (changed_flags && entry == controller()->GetActiveEntry()) |
| 892 NotifyNavigationStateChanged(changed_flags); | 857 NotifyNavigationStateChanged(changed_flags); |
| 893 controller()->NotifyEntryChanged(entry, entry_index); | 858 controller()->NotifyEntryChanged(entry, entry_index); |
| 894 } | 859 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 908 // We are showing an interstitial page in a different RenderViewHost, so | 873 // We are showing an interstitial page in a different RenderViewHost, so |
| 909 // the page_id is not sufficient to find the entry from the controller. | 874 // the page_id is not sufficient to find the entry from the controller. |
| 910 // (both RenderViewHost page_ids overlap). We know it is the active entry, | 875 // (both RenderViewHost page_ids overlap). We know it is the active entry, |
| 911 // so just use that. | 876 // so just use that. |
| 912 entry = controller()->GetActiveEntry(); | 877 entry = controller()->GetActiveEntry(); |
| 913 } else { | 878 } else { |
| 914 entry = controller()->GetEntryWithPageID(type(), GetSiteInstance(), | 879 entry = controller()->GetEntryWithPageID(type(), GetSiteInstance(), |
| 915 page_id); | 880 page_id); |
| 916 } | 881 } |
| 917 | 882 |
| 918 if (!entry) | 883 if (!entry || !UpdateTitleForEntry(entry, title)) |
| 919 return; | 884 return; |
| 920 | 885 |
| 921 std::wstring trimmed_title; | |
| 922 TrimWhitespace(title, TRIM_ALL, &trimmed_title); | |
| 923 if (title == entry->title()) | |
| 924 return; // Title did not change, do nothing. | |
| 925 | |
| 926 entry->set_title(trimmed_title); | |
| 927 | |
| 928 // Broadcast notifications when the UI should be updated. | 886 // Broadcast notifications when the UI should be updated. |
| 929 if (entry == controller()->GetEntryAtOffset(0)) | 887 if (entry == controller()->GetEntryAtOffset(0)) |
| 930 NotifyNavigationStateChanged(INVALIDATE_TITLE); | 888 NotifyNavigationStateChanged(INVALIDATE_TITLE); |
| 931 | |
| 932 // Update the history system for this page. | |
| 933 if (profile()->IsOffTheRecord()) | |
| 934 return; | |
| 935 | |
| 936 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); | |
| 937 if (hs && !has_page_title_ && !trimmed_title.empty()) { | |
| 938 hs->SetPageTitle(entry->display_url(), trimmed_title); | |
| 939 has_page_title_ = true; | |
| 940 } | |
| 941 } | 889 } |
| 942 | 890 |
| 943 | 891 |
| 944 void WebContents::UpdateEncoding(RenderViewHost* render_view_host, | 892 void WebContents::UpdateEncoding(RenderViewHost* render_view_host, |
| 945 const std::wstring& encoding_name) { | 893 const std::wstring& encoding_name) { |
| 946 set_encoding(encoding_name); | 894 set_encoding(encoding_name); |
| 947 } | 895 } |
| 948 | 896 |
| 949 void WebContents::UpdateTargetURL(int32 page_id, const GURL& url) { | 897 void WebContents::UpdateTargetURL(int32 page_id, const GURL& url) { |
| 950 if (delegate()) | 898 if (delegate()) |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1114 // request. If we end up with another place invoking DownloadImage, probably | 1062 // request. If we end up with another place invoking DownloadImage, probably |
| 1115 // best to refactor out into notification service, or something similar. | 1063 // best to refactor out into notification service, or something similar. |
| 1116 if (errored) | 1064 if (errored) |
| 1117 fav_icon_helper_.FavIconDownloadFailed(id); | 1065 fav_icon_helper_.FavIconDownloadFailed(id); |
| 1118 else | 1066 else |
| 1119 fav_icon_helper_.SetFavIcon(id, image_url, image); | 1067 fav_icon_helper_.SetFavIcon(id, image_url, image); |
| 1120 if (web_app_.get() && !errored) | 1068 if (web_app_.get() && !errored) |
| 1121 web_app_->SetImage(image_url, image); | 1069 web_app_->SetImage(image_url, image); |
| 1122 } | 1070 } |
| 1123 | 1071 |
| 1124 void WebContents::ShowContextMenu( | |
| 1125 const ViewHostMsg_ContextMenu_Params& params) { | |
| 1126 view_->ShowContextMenu(params); | |
| 1127 } | |
| 1128 | |
| 1129 void WebContents::StartDragging(const WebDropData& drop_data) { | |
| 1130 view_->StartDragging(drop_data); | |
| 1131 } | |
| 1132 | |
| 1133 void WebContents::UpdateDragCursor(bool is_drop_target) { | |
| 1134 view_->UpdateDragCursor(is_drop_target); | |
| 1135 } | |
| 1136 | |
| 1137 void WebContents::RequestOpenURL(const GURL& url, | 1072 void WebContents::RequestOpenURL(const GURL& url, |
| 1138 WindowOpenDisposition disposition) { | 1073 WindowOpenDisposition disposition) { |
| 1139 OpenURL(url, disposition, PageTransition::LINK); | 1074 OpenURL(url, disposition, PageTransition::LINK); |
| 1140 } | 1075 } |
| 1141 | 1076 |
| 1142 void WebContents::DomOperationResponse(const std::string& json_string, | 1077 void WebContents::DomOperationResponse(const std::string& json_string, |
| 1143 int automation_id) { | 1078 int automation_id) { |
| 1144 DomOperationNotificationDetails details(json_string, automation_id); | 1079 DomOperationNotificationDetails details(json_string, automation_id); |
| 1145 NotificationService::current()->Notify( | 1080 NotificationService::current()->Notify( |
| 1146 NOTIFY_DOM_OPERATION_RESPONSE, Source<WebContents>(this), | 1081 NOTIFY_DOM_OPERATION_RESPONSE, Source<WebContents>(this), |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1229 reply_msg, this); | 1164 reply_msg, this); |
| 1230 delegate()->ShowHtmlDialog(dialog_delegate, NULL); | 1165 delegate()->ShowHtmlDialog(dialog_delegate, NULL); |
| 1231 } | 1166 } |
| 1232 } | 1167 } |
| 1233 | 1168 |
| 1234 void WebContents::PasswordFormsSeen( | 1169 void WebContents::PasswordFormsSeen( |
| 1235 const std::vector<PasswordForm>& forms) { | 1170 const std::vector<PasswordForm>& forms) { |
| 1236 GetPasswordManager()->PasswordFormsSeen(forms); | 1171 GetPasswordManager()->PasswordFormsSeen(forms); |
| 1237 } | 1172 } |
| 1238 | 1173 |
| 1239 void WebContents::TakeFocus(bool reverse) { | |
| 1240 // TODO(brettw) move this to the view. | |
| 1241 views::FocusManager* focus_manager = | |
| 1242 views::FocusManager::GetFocusManager(view_->GetContainerHWND()); | |
| 1243 | |
| 1244 // We may not have a focus manager if the tab has been switched before this | |
| 1245 // message arrived. | |
| 1246 if (focus_manager) { | |
| 1247 focus_manager->AdvanceFocus(reverse); | |
| 1248 } | |
| 1249 } | |
| 1250 | |
| 1251 // Checks to see if we should generate a keyword based on the OSDD, and if | 1174 // Checks to see if we should generate a keyword based on the OSDD, and if |
| 1252 // necessary uses TemplateURLFetcher to download the OSDD and create a keyword. | 1175 // necessary uses TemplateURLFetcher to download the OSDD and create a keyword. |
| 1253 void WebContents::PageHasOSDD(RenderViewHost* render_view_host, | 1176 void WebContents::PageHasOSDD(RenderViewHost* render_view_host, |
| 1254 int32 page_id, const GURL& url, | 1177 int32 page_id, const GURL& url, |
| 1255 bool autodetected) { | 1178 bool autodetected) { |
| 1256 // Make sure page_id is the current page, and the TemplateURLModel is loaded. | 1179 // Make sure page_id is the current page, and the TemplateURLModel is loaded. |
| 1257 DCHECK(url.is_valid()); | 1180 DCHECK(url.is_valid()); |
| 1258 if (!controller() || !IsActiveEntry(page_id)) | 1181 if (!controller() || !IsActiveEntry(page_id)) |
| 1259 return; | 1182 return; |
| 1260 TemplateURLModel* url_model = profile()->GetTemplateURLModel(); | 1183 TemplateURLModel* url_model = profile()->GetTemplateURLModel(); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1485 &GearsCreateShortcutCallbackFunctor::Run)); | 1408 &GearsCreateShortcutCallbackFunctor::Run)); |
| 1486 } | 1409 } |
| 1487 | 1410 |
| 1488 void WebContents::OnEnterOrSpace() { | 1411 void WebContents::OnEnterOrSpace() { |
| 1489 // See comment in RenderViewHostDelegate::OnEnterOrSpace as to why we do this. | 1412 // See comment in RenderViewHostDelegate::OnEnterOrSpace as to why we do this. |
| 1490 DownloadRequestManager* drm = g_browser_process->download_request_manager(); | 1413 DownloadRequestManager* drm = g_browser_process->download_request_manager(); |
| 1491 if (drm) | 1414 if (drm) |
| 1492 drm->OnUserGesture(this); | 1415 drm->OnUserGesture(this); |
| 1493 } | 1416 } |
| 1494 | 1417 |
| 1495 // Stupid pass-through for RenderViewHostDelegate. | |
| 1496 void WebContents::HandleKeyboardEvent(const WebKeyboardEvent& event) { | |
| 1497 view_->HandleKeyboardEvent(event); | |
| 1498 } | |
| 1499 | |
| 1500 void WebContents::FileSelected(const std::wstring& path, void* params) { | 1418 void WebContents::FileSelected(const std::wstring& path, void* params) { |
| 1501 render_view_host()->FileSelected(path); | 1419 render_view_host()->FileSelected(path); |
| 1502 } | 1420 } |
| 1503 | 1421 |
| 1504 void WebContents::FileSelectionCanceled(void* params) { | 1422 void WebContents::FileSelectionCanceled(void* params) { |
| 1505 // If the user cancels choosing a file to upload we need to pass back the | 1423 // If the user cancels choosing a file to upload we need to pass back the |
| 1506 // empty string. | 1424 // empty string. |
| 1507 render_view_host()->FileSelected(std::wstring()); | 1425 render_view_host()->FileSelected(std::wstring()); |
| 1508 } | 1426 } |
| 1509 | 1427 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1609 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be | 1527 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be |
| 1610 // cleaned up and covered by tests. | 1528 // cleaned up and covered by tests. |
| 1611 if (!params.password_form.origin.is_valid()) | 1529 if (!params.password_form.origin.is_valid()) |
| 1612 GetPasswordManager()->DidNavigate(); | 1530 GetPasswordManager()->DidNavigate(); |
| 1613 } | 1531 } |
| 1614 | 1532 |
| 1615 // The keyword generator uses the navigation entries, so must be called after | 1533 // The keyword generator uses the navigation entries, so must be called after |
| 1616 // the commit. | 1534 // the commit. |
| 1617 GenerateKeywordIfNecessary(params); | 1535 GenerateKeywordIfNecessary(params); |
| 1618 | 1536 |
| 1619 // We no longer know the title after this navigation. | 1537 // Allow the new page to set the title again. |
| 1620 has_page_title_ = false; | 1538 received_page_title_ = false; |
| 1621 | 1539 |
| 1622 // Update contents MIME type of the main webframe. | 1540 // Update contents MIME type of the main webframe. |
| 1623 contents_mime_type_ = params.contents_mime_type; | 1541 contents_mime_type_ = params.contents_mime_type; |
| 1624 | 1542 |
| 1625 // Get the favicon, either from history or request it from the net. | 1543 // Get the favicon, either from history or request it from the net. |
| 1626 fav_icon_helper_.FetchFavIcon(details.entry->url()); | 1544 fav_icon_helper_.FetchFavIcon(details.entry->url()); |
| 1627 | 1545 |
| 1628 // Close constrained popups if necessary. | 1546 // Close constrained popups if necessary. |
| 1629 MaybeCloseChildWindows(params); | 1547 MaybeCloseChildWindows(params); |
| 1630 | 1548 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1784 redirects.back() = display_url; | 1702 redirects.back() = display_url; |
| 1785 hs->AddPage(display_url, this, params.page_id, params.referrer, | 1703 hs->AddPage(display_url, this, params.page_id, params.referrer, |
| 1786 params.transition, redirects); | 1704 params.transition, redirects); |
| 1787 } else { | 1705 } else { |
| 1788 hs->AddPage(params.url, this, params.page_id, params.referrer, | 1706 hs->AddPage(params.url, this, params.page_id, params.referrer, |
| 1789 params.transition, params.redirects); | 1707 params.transition, params.redirects); |
| 1790 } | 1708 } |
| 1791 } | 1709 } |
| 1792 } | 1710 } |
| 1793 | 1711 |
| 1712 bool WebContents::UpdateTitleForEntry(NavigationEntry* entry, | |
| 1713 const std::wstring& title) { | |
| 1714 // For file URLs without a title, use the pathname instead. In the case of a | |
| 1715 // synthesized title, we don't want the update to count toward the "one set | |
| 1716 // per page of the title to history." | |
| 1717 std::wstring final_title; | |
| 1718 bool explicit_set; | |
| 1719 if (entry->url().SchemeIsFile() && title.empty()) { | |
| 1720 final_title = UTF8ToWide(entry->url().ExtractFileName()); | |
| 1721 explicit_set = false; // Don't count synthetic titles toward the set limit. | |
| 1722 } else { | |
| 1723 TrimWhitespace(title, TRIM_ALL, &final_title); | |
| 1724 explicit_set = true; | |
| 1725 } | |
| 1726 | |
| 1727 if (final_title != entry->title()) | |
|
Ben Goodger (Google)
2008/10/18 05:08:13
do you mean ==?
| |
| 1728 return false; // Nothing changed, don't bother. | |
| 1729 | |
| 1730 entry->set_title(final_title); | |
| 1731 | |
| 1732 // Update the history system for this page. | |
| 1733 if (!profile()->IsOffTheRecord() && !received_page_title_) { | |
| 1734 HistoryService* hs = | |
| 1735 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); | |
| 1736 if (hs) | |
| 1737 hs->SetPageTitle(entry->display_url(), final_title); | |
| 1738 | |
| 1739 // Don't allow the title to be saved again for explicitly set ones. | |
| 1740 received_page_title_ = explicit_set; | |
| 1741 } | |
| 1742 | |
| 1743 // Lastly, set the title for the view. | |
| 1744 view_->SetPageTitle(final_title); | |
| 1745 | |
| 1746 return true; | |
| 1747 } | |
| 1748 | |
| 1794 void WebContents::NotifySwapped() { | 1749 void WebContents::NotifySwapped() { |
| 1795 // After sending out a swap notification, we need to send a disconnect | 1750 // After sending out a swap notification, we need to send a disconnect |
| 1796 // notification so that clients that pick up a pointer to |this| can NULL the | 1751 // notification so that clients that pick up a pointer to |this| can NULL the |
| 1797 // pointer. See Bug 1230284. | 1752 // pointer. See Bug 1230284. |
| 1798 notify_disconnection_ = true; | 1753 notify_disconnection_ = true; |
| 1799 NotificationService::current()-> | 1754 NotificationService::current()-> |
| 1800 Notify(NOTIFY_WEB_CONTENTS_SWAPPED, | 1755 Notify(NOTIFY_WEB_CONTENTS_SWAPPED, |
| 1801 Source<WebContents>(this), | 1756 Source<WebContents>(this), |
| 1802 NotificationService::NoDetails()); | 1757 NotificationService::NoDetails()); |
| 1803 } | 1758 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1888 // The favicon url isn't valid. This means there really isn't a favicon, | 1843 // The favicon url isn't valid. This means there really isn't a favicon, |
| 1889 // or the favicon url wasn't obtained before the load started. This assumes | 1844 // or the favicon url wasn't obtained before the load started. This assumes |
| 1890 // the later. | 1845 // the later. |
| 1891 // TODO(sky): Need a way to set the favicon that doesn't involve generating | 1846 // TODO(sky): Need a way to set the favicon that doesn't involve generating |
| 1892 // its url. | 1847 // its url. |
| 1893 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer)); | 1848 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer)); |
| 1894 } | 1849 } |
| 1895 new_url->set_safe_for_autoreplace(true); | 1850 new_url->set_safe_for_autoreplace(true); |
| 1896 url_model->Add(new_url); | 1851 url_model->Add(new_url); |
| 1897 } | 1852 } |
| OLD | NEW |