| 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" | 18 #include "chrome/browser/defaults.h" |
| 19 #include "chrome/browser/external_protocol_handler.h" | 19 #include "chrome/browser/external_protocol_handler.h" |
| 20 #include "chrome/browser/history/history.h" | |
| 21 #include "chrome/browser/load_from_memory_cache_details.h" | 20 #include "chrome/browser/load_from_memory_cache_details.h" |
| 22 #include "chrome/browser/load_notification_details.h" | 21 #include "chrome/browser/load_notification_details.h" |
| 23 #include "chrome/browser/notifications/desktop_notification_service.h" | 22 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 24 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 23 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 25 #include "chrome/browser/platform_util.h" | 24 #include "chrome/browser/platform_util.h" |
| 26 #include "chrome/browser/prefs/pref_service.h" | 25 #include "chrome/browser/prefs/pref_service.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/renderer_host/web_cache_manager.h" | 27 #include "chrome/browser/renderer_host/web_cache_manager.h" |
| 29 #include "chrome/browser/renderer_preferences_util.h" | 28 #include "chrome/browser/renderer_preferences_util.h" |
| 30 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" | 29 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" |
| 31 #include "chrome/browser/ui/browser_dialogs.h" | 30 #include "chrome/browser/ui/browser_dialogs.h" |
| 32 #include "chrome/common/chrome_constants.h" | 31 #include "chrome/common/chrome_constants.h" |
| 33 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 34 #include "chrome/common/render_messages.h" | 33 #include "chrome/common/render_messages.h" |
| 35 #include "content/browser/child_process_security_policy.h" | 34 #include "content/browser/child_process_security_policy.h" |
| 36 #include "content/browser/content_browser_client.h" | 35 #include "content/browser/content_browser_client.h" |
| 37 #include "content/browser/host_zoom_map.h" | 36 #include "content/browser/host_zoom_map.h" |
| 38 #include "content/browser/in_process_webkit/session_storage_namespace.h" | 37 #include "content/browser/in_process_webkit/session_storage_namespace.h" |
| 39 #include "content/browser/renderer_host/render_process_host.h" | 38 #include "content/browser/renderer_host/render_process_host.h" |
| 40 #include "content/browser/renderer_host/render_view_host.h" | 39 #include "content/browser/renderer_host/render_view_host.h" |
| 41 #include "content/browser/renderer_host/render_widget_host_view.h" | 40 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 42 #include "content/browser/renderer_host/resource_request_details.h" | 41 #include "content/browser/renderer_host/resource_request_details.h" |
| 43 #include "content/browser/site_instance.h" | 42 #include "content/browser/site_instance.h" |
| 44 #include "content/browser/tab_contents/interstitial_page.h" | 43 #include "content/browser/tab_contents/interstitial_page.h" |
| 45 #include "content/browser/tab_contents/navigation_entry.h" | 44 #include "content/browser/tab_contents/navigation_entry.h" |
| 46 #include "content/browser/tab_contents/provisional_load_details.h" | 45 #include "content/browser/tab_contents/provisional_load_details.h" |
| 47 #include "content/browser/tab_contents/tab_contents_delegate.h" | 46 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 48 #include "content/browser/tab_contents/tab_contents_observer.h" | 47 #include "content/browser/tab_contents/tab_contents_observer.h" |
| 49 #include "content/browser/tab_contents/tab_contents_view.h" | 48 #include "content/browser/tab_contents/tab_contents_view.h" |
| 49 #include "content/browser/tab_contents/title_updated_details.h" |
| 50 #include "content/browser/user_metrics.h" | 50 #include "content/browser/user_metrics.h" |
| 51 #include "content/browser/webui/web_ui_factory.h" | 51 #include "content/browser/webui/web_ui_factory.h" |
| 52 #include "content/common/bindings_policy.h" | 52 #include "content/common/bindings_policy.h" |
| 53 #include "content/common/content_client.h" | 53 #include "content/common/content_client.h" |
| 54 #include "content/common/content_restriction.h" | 54 #include "content/common/content_restriction.h" |
| 55 #include "content/common/navigation_types.h" | 55 #include "content/common/navigation_types.h" |
| 56 #include "content/common/notification_service.h" | 56 #include "content/common/notification_service.h" |
| 57 #include "content/common/url_constants.h" | 57 #include "content/common/url_constants.h" |
| 58 #include "content/common/view_messages.h" | 58 #include "content/common/view_messages.h" |
| 59 #include "net/base/net_util.h" | 59 #include "net/base/net_util.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)), | 209 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)), |
| 210 bookmark_drag_(NULL), | 210 bookmark_drag_(NULL), |
| 211 is_loading_(false), | 211 is_loading_(false), |
| 212 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING), | 212 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING), |
| 213 crashed_error_code_(0), | 213 crashed_error_code_(0), |
| 214 waiting_for_response_(false), | 214 waiting_for_response_(false), |
| 215 max_page_id_(-1), | 215 max_page_id_(-1), |
| 216 load_state_(net::LOAD_STATE_IDLE), | 216 load_state_(net::LOAD_STATE_IDLE), |
| 217 upload_size_(0), | 217 upload_size_(0), |
| 218 upload_position_(0), | 218 upload_position_(0), |
| 219 received_page_title_(false), | |
| 220 displayed_insecure_content_(false), | 219 displayed_insecure_content_(false), |
| 221 capturing_contents_(false), | 220 capturing_contents_(false), |
| 222 is_being_destroyed_(false), | 221 is_being_destroyed_(false), |
| 223 notify_disconnection_(false), | 222 notify_disconnection_(false), |
| 224 #if defined(OS_WIN) | 223 #if defined(OS_WIN) |
| 225 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), | 224 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), |
| 226 #endif | 225 #endif |
| 227 suppress_javascript_messages_(false), | 226 suppress_javascript_messages_(false), |
| 228 is_showing_before_unload_dialog_(false), | 227 is_showing_before_unload_dialog_(false), |
| 229 opener_web_ui_type_(WebUI::kNoWebUI), | 228 opener_web_ui_type_(WebUI::kNoWebUI), |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 #endif | 808 #endif |
| 810 } | 809 } |
| 811 | 810 |
| 812 void TabContents::SystemDragEnded() { | 811 void TabContents::SystemDragEnded() { |
| 813 if (render_view_host()) | 812 if (render_view_host()) |
| 814 render_view_host()->DragSourceSystemDragEnded(); | 813 render_view_host()->DragSourceSystemDragEnded(); |
| 815 if (delegate()) | 814 if (delegate()) |
| 816 delegate()->DragEnded(); | 815 delegate()->DragEnded(); |
| 817 } | 816 } |
| 818 | 817 |
| 819 void TabContents::UpdateHistoryForNavigation( | |
| 820 scoped_refptr<history::HistoryAddPageArgs> add_page_args) { | |
| 821 if (profile()->IsOffTheRecord()) | |
| 822 return; | |
| 823 | |
| 824 // Add to history service. | |
| 825 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); | |
| 826 if (hs) | |
| 827 hs->AddPage(*add_page_args); | |
| 828 } | |
| 829 | |
| 830 void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) { | |
| 831 if (profile()->IsOffTheRecord()) | |
| 832 return; | |
| 833 | |
| 834 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); | |
| 835 if (hs) | |
| 836 hs->SetPageTitle(entry.virtual_url(), entry.title()); | |
| 837 } | |
| 838 | |
| 839 double TabContents::GetZoomLevel() const { | 818 double TabContents::GetZoomLevel() const { |
| 840 HostZoomMap* zoom_map = profile()->GetHostZoomMap(); | 819 HostZoomMap* zoom_map = profile()->GetHostZoomMap(); |
| 841 if (!zoom_map) | 820 if (!zoom_map) |
| 842 return 0; | 821 return 0; |
| 843 | 822 |
| 844 double zoom_level; | 823 double zoom_level; |
| 845 if (temporary_zoom_settings_) { | 824 if (temporary_zoom_settings_) { |
| 846 zoom_level = zoom_map->GetTemporaryZoomLevel( | 825 zoom_level = zoom_map->GetTemporaryZoomLevel( |
| 847 GetRenderProcessHost()->id(), render_view_host()->routing_id()); | 826 GetRenderProcessHost()->id(), render_view_host()->routing_id()); |
| 848 } else { | 827 } else { |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 if (details.is_user_initiated_main_frame_load()) { | 1122 if (details.is_user_initiated_main_frame_load()) { |
| 1144 // Clear the status bubble. This is a workaround for a bug where WebKit | 1123 // Clear the status bubble. This is a workaround for a bug where WebKit |
| 1145 // doesn't let us know that the cursor left an element during a | 1124 // doesn't let us know that the cursor left an element during a |
| 1146 // transition (this is also why the mouse cursor remains as a hand after | 1125 // transition (this is also why the mouse cursor remains as a hand after |
| 1147 // clicking on a link); see bugs 1184641 and 980803. We don't want to | 1126 // clicking on a link); see bugs 1184641 and 980803. We don't want to |
| 1148 // clear the bubble when a user navigates to a named anchor in the same | 1127 // clear the bubble when a user navigates to a named anchor in the same |
| 1149 // page. | 1128 // page. |
| 1150 UpdateTargetURL(details.entry->page_id(), GURL()); | 1129 UpdateTargetURL(details.entry->page_id(), GURL()); |
| 1151 } | 1130 } |
| 1152 | 1131 |
| 1153 // Allow the new page to set the title again. | |
| 1154 received_page_title_ = false; | |
| 1155 | |
| 1156 if (!details.is_in_page) { | 1132 if (!details.is_in_page) { |
| 1157 // Once the main frame is navigated, we're no longer considered to have | 1133 // Once the main frame is navigated, we're no longer considered to have |
| 1158 // displayed insecure content. | 1134 // displayed insecure content. |
| 1159 displayed_insecure_content_ = false; | 1135 displayed_insecure_content_ = false; |
| 1160 } | 1136 } |
| 1161 | 1137 |
| 1162 // Close constrained windows if necessary. | 1138 // Close constrained windows if necessary. |
| 1163 if (!net::RegistryControlledDomainService::SameDomainOrHost( | 1139 if (!net::RegistryControlledDomainService::SameDomainOrHost( |
| 1164 details.previous_url, details.entry->url())) | 1140 details.previous_url, details.entry->url())) |
| 1165 CloseConstrainedWindows(); | 1141 CloseConstrainedWindows(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 // Also tell the renderer to update its internal representation. We | 1207 // Also tell the renderer to update its internal representation. We |
| 1232 // need to reserve enough IDs to make all restored page IDs less than | 1208 // need to reserve enough IDs to make all restored page IDs less than |
| 1233 // the max. | 1209 // the max. |
| 1234 if (curr_max_page_id < 0) | 1210 if (curr_max_page_id < 0) |
| 1235 curr_max_page_id = 0; | 1211 curr_max_page_id = 0; |
| 1236 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id); | 1212 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id); |
| 1237 } | 1213 } |
| 1238 } | 1214 } |
| 1239 } | 1215 } |
| 1240 | 1216 |
| 1241 scoped_refptr<history::HistoryAddPageArgs> | |
| 1242 TabContents::CreateHistoryAddPageArgs( | |
| 1243 const GURL& virtual_url, | |
| 1244 const NavigationController::LoadCommittedDetails& details, | |
| 1245 const ViewHostMsg_FrameNavigate_Params& params) { | |
| 1246 scoped_refptr<history::HistoryAddPageArgs> add_page_args( | |
| 1247 new history::HistoryAddPageArgs( | |
| 1248 params.url, base::Time::Now(), this, params.page_id, params.referrer, | |
| 1249 params.redirects, params.transition, history::SOURCE_BROWSED, | |
| 1250 details.did_replace_entry)); | |
| 1251 if (PageTransition::IsMainFrame(params.transition) && | |
| 1252 virtual_url != params.url) { | |
| 1253 // Hack on the "virtual" URL so that it will appear in history. For some | |
| 1254 // types of URLs, we will display a magic URL that is different from where | |
| 1255 // the page is actually navigated. We want the user to see in history what | |
| 1256 // they saw in the URL bar, so we add the virtual URL as a redirect. This | |
| 1257 // only applies to the main frame, as the virtual URL doesn't apply to | |
| 1258 // sub-frames. | |
| 1259 add_page_args->url = virtual_url; | |
| 1260 if (!add_page_args->redirects.empty()) | |
| 1261 add_page_args->redirects.back() = virtual_url; | |
| 1262 } | |
| 1263 return add_page_args; | |
| 1264 } | |
| 1265 | |
| 1266 bool TabContents::UpdateTitleForEntry(NavigationEntry* entry, | 1217 bool TabContents::UpdateTitleForEntry(NavigationEntry* entry, |
| 1267 const std::wstring& title) { | 1218 const std::wstring& title) { |
| 1268 // For file URLs without a title, use the pathname instead. In the case of a | 1219 // For file URLs without a title, use the pathname instead. In the case of a |
| 1269 // synthesized title, we don't want the update to count toward the "one set | 1220 // synthesized title, we don't want the update to count toward the "one set |
| 1270 // per page of the title to history." | 1221 // per page of the title to history." |
| 1271 string16 final_title; | 1222 string16 final_title; |
| 1272 bool explicit_set; | 1223 bool explicit_set; |
| 1273 if (entry->url().SchemeIsFile() && title.empty()) { | 1224 if (entry->url().SchemeIsFile() && title.empty()) { |
| 1274 final_title = UTF8ToUTF16(entry->url().ExtractFileName()); | 1225 final_title = UTF8ToUTF16(entry->url().ExtractFileName()); |
| 1275 explicit_set = false; // Don't count synthetic titles toward the set limit. | 1226 explicit_set = false; // Don't count synthetic titles toward the set limit. |
| 1276 } else { | 1227 } else { |
| 1277 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title); | 1228 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title); |
| 1278 explicit_set = true; | 1229 explicit_set = true; |
| 1279 } | 1230 } |
| 1280 | 1231 |
| 1281 if (final_title == entry->title()) | 1232 if (final_title == entry->title()) |
| 1282 return false; // Nothing changed, don't bother. | 1233 return false; // Nothing changed, don't bother. |
| 1283 | 1234 |
| 1284 entry->set_title(final_title); | 1235 entry->set_title(final_title); |
| 1285 | 1236 |
| 1286 if (!received_page_title_) { | |
| 1287 UpdateHistoryPageTitle(*entry); | |
| 1288 received_page_title_ = explicit_set; | |
| 1289 } | |
| 1290 | |
| 1291 // Lastly, set the title for the view. | 1237 // Lastly, set the title for the view. |
| 1292 view_->SetPageTitle(UTF16ToWideHack(final_title)); | 1238 view_->SetPageTitle(UTF16ToWideHack(final_title)); |
| 1293 | 1239 |
| 1240 TitleUpdatedDetails details(entry, explicit_set); |
| 1241 |
| 1294 NotificationService::current()->Notify( | 1242 NotificationService::current()->Notify( |
| 1295 NotificationType::TAB_CONTENTS_TITLE_UPDATED, | 1243 NotificationType::TAB_CONTENTS_TITLE_UPDATED, |
| 1296 Source<TabContents>(this), | 1244 Source<TabContents>(this), |
| 1297 NotificationService::NoDetails()); | 1245 Details<TitleUpdatedDetails>(&details)); |
| 1298 | 1246 |
| 1299 return true; | 1247 return true; |
| 1300 } | 1248 } |
| 1301 | 1249 |
| 1302 void TabContents::NotifySwapped() { | 1250 void TabContents::NotifySwapped() { |
| 1303 // After sending out a swap notification, we need to send a disconnect | 1251 // After sending out a swap notification, we need to send a disconnect |
| 1304 // notification so that clients that pick up a pointer to |this| can NULL the | 1252 // notification so that clients that pick up a pointer to |this| can NULL the |
| 1305 // pointer. See Bug 1230284. | 1253 // pointer. See Bug 1230284. |
| 1306 notify_disconnection_ = true; | 1254 notify_disconnection_ = true; |
| 1307 NotificationService::current()->Notify( | 1255 NotificationService::current()->Notify( |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1498 (controller_.GetActiveEntry()->transition_type() & | 1446 (controller_.GetActiveEntry()->transition_type() & |
| 1499 PageTransition::FORWARD_BACK)) { | 1447 PageTransition::FORWARD_BACK)) { |
| 1500 transition_type = params.transition | PageTransition::FORWARD_BACK; | 1448 transition_type = params.transition | PageTransition::FORWARD_BACK; |
| 1501 } | 1449 } |
| 1502 // Notify observers about the commit of the provisional load. | 1450 // Notify observers about the commit of the provisional load. |
| 1503 FOR_EACH_OBSERVER(TabContentsObserver, observers_, | 1451 FOR_EACH_OBSERVER(TabContentsObserver, observers_, |
| 1504 DidCommitProvisionalLoadForFrame(params.frame_id, | 1452 DidCommitProvisionalLoadForFrame(params.frame_id, |
| 1505 is_main_frame, params.url, transition_type)); | 1453 is_main_frame, params.url, transition_type)); |
| 1506 } | 1454 } |
| 1507 | 1455 |
| 1508 // Update history. Note that this needs to happen after the entry is complete, | |
| 1509 // which WillNavigate[Main,Sub]Frame will do before this function is called. | |
| 1510 if (params.should_update_history) { | |
| 1511 // Most of the time, the displayURL matches the loaded URL, but for about: | |
| 1512 // URLs, we use a data: URL as the real value. We actually want to save the | |
| 1513 // about: URL to the history db and keep the data: URL hidden. This is what | |
| 1514 // the TabContents' URL getter does. | |
| 1515 scoped_refptr<history::HistoryAddPageArgs> add_page_args( | |
| 1516 CreateHistoryAddPageArgs(GetURL(), details, params)); | |
| 1517 if (!delegate() || | |
| 1518 delegate()->ShouldAddNavigationToHistory(*add_page_args, | |
| 1519 details.type)) { | |
| 1520 UpdateHistoryForNavigation(add_page_args); | |
| 1521 } | |
| 1522 } | |
| 1523 | |
| 1524 if (!did_navigate) | 1456 if (!did_navigate) |
| 1525 return; // No navigation happened. | 1457 return; // No navigation happened. |
| 1526 | 1458 |
| 1527 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen | 1459 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen |
| 1528 // for the appropriate notification (best) or you can add it to | 1460 // for the appropriate notification (best) or you can add it to |
| 1529 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if | 1461 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if |
| 1530 // necessary, please). | 1462 // necessary, please). |
| 1531 | 1463 |
| 1532 // Run post-commit tasks. | 1464 // Run post-commit tasks. |
| 1533 if (details.is_main_frame) | 1465 if (details.is_main_frame) |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2053 | 1985 |
| 2054 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 1986 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 2055 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 1987 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
| 2056 rwh_view->SetSize(view()->GetContainerSize()); | 1988 rwh_view->SetSize(view()->GetContainerSize()); |
| 2057 } | 1989 } |
| 2058 | 1990 |
| 2059 void TabContents::OnOnlineStateChanged(bool online) { | 1991 void TabContents::OnOnlineStateChanged(bool online) { |
| 2060 render_view_host()->Send(new ViewMsg_NetworkStateChanged( | 1992 render_view_host()->Send(new ViewMsg_NetworkStateChanged( |
| 2061 render_view_host()->routing_id(), online)); | 1993 render_view_host()->routing_id(), online)); |
| 2062 } | 1994 } |
| OLD | NEW |