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" |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "content/browser/tab_contents/provisional_load_details.h" | 34 #include "content/browser/tab_contents/provisional_load_details.h" |
35 #include "content/browser/tab_contents/tab_contents_delegate.h" | 35 #include "content/browser/tab_contents/tab_contents_delegate.h" |
36 #include "content/browser/tab_contents/tab_contents_observer.h" | 36 #include "content/browser/tab_contents/tab_contents_observer.h" |
37 #include "content/browser/tab_contents/tab_contents_view.h" | 37 #include "content/browser/tab_contents/tab_contents_view.h" |
38 #include "content/browser/tab_contents/title_updated_details.h" | 38 #include "content/browser/tab_contents/title_updated_details.h" |
39 #include "content/browser/user_metrics.h" | 39 #include "content/browser/user_metrics.h" |
40 #include "content/browser/webui/web_ui_factory.h" | 40 #include "content/browser/webui/web_ui_factory.h" |
41 #include "content/common/content_constants.h" | 41 #include "content/common/content_constants.h" |
42 #include "content/common/content_restriction.h" | 42 #include "content/common/content_restriction.h" |
43 #include "content/common/intents_messages.h" | 43 #include "content/common/intents_messages.h" |
44 #include "content/common/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
45 #include "content/common/view_messages.h" | 45 #include "content/common/view_messages.h" |
46 #include "content/public/browser/content_browser_client.h" | 46 #include "content/public/browser/content_browser_client.h" |
47 #include "content/public/browser/navigation_types.h" | 47 #include "content/public/browser/navigation_types.h" |
48 #include "content/public/common/bindings_policy.h" | 48 #include "content/public/common/bindings_policy.h" |
49 #include "content/public/common/url_constants.h" | 49 #include "content/public/common/url_constants.h" |
50 #include "content/public/common/view_types.h" | 50 #include "content/public/common/view_types.h" |
51 #include "net/base/net_util.h" | 51 #include "net/base/net_util.h" |
52 #include "net/url_request/url_request_context_getter.h" | 52 #include "net/url_request/url_request_context_getter.h" |
53 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 53 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
54 #include "ui/gfx/codec/png_codec.h" | 54 #include "ui/gfx/codec/png_codec.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 TabContents::~TabContents() { | 215 TabContents::~TabContents() { |
216 is_being_destroyed_ = true; | 216 is_being_destroyed_ = true; |
217 | 217 |
218 // Clear out any JavaScript state. | 218 // Clear out any JavaScript state. |
219 if (dialog_creator_) | 219 if (dialog_creator_) |
220 dialog_creator_->ResetJavaScriptState(this); | 220 dialog_creator_->ResetJavaScriptState(this); |
221 | 221 |
222 NotifyDisconnected(); | 222 NotifyDisconnected(); |
223 | 223 |
224 // Notify any observer that have a reference on this tab contents. | 224 // Notify any observer that have a reference on this tab contents. |
225 NotificationService::current()->Notify( | 225 content::NotificationService::current()->Notify( |
226 content::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 226 content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
227 content::Source<TabContents>(this), | 227 content::Source<TabContents>(this), |
228 NotificationService::NoDetails()); | 228 content::NotificationService::NoDetails()); |
229 | 229 |
230 // TODO(brettw) this should be moved to the view. | 230 // TODO(brettw) this should be moved to the view. |
231 #if defined(OS_WIN) | 231 #if defined(OS_WIN) |
232 // If we still have a window handle, destroy it. GetNativeView can return | 232 // If we still have a window handle, destroy it. GetNativeView can return |
233 // NULL if this contents was part of a window that closed. | 233 // NULL if this contents was part of a window that closed. |
234 if (GetNativeView()) { | 234 if (GetNativeView()) { |
235 RenderViewHost* host = render_view_host(); | 235 RenderViewHost* host = render_view_host(); |
236 if (host && host->view()) | 236 if (host && host->view()) |
237 host->view()->WillWmDestroy(); | 237 host->view()->WillWmDestroy(); |
238 } | 238 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 // |render_view_host()| can be NULL if the user middle clicks a link to open | 444 // |render_view_host()| can be NULL if the user middle clicks a link to open |
445 // a tab in then background, then closes the tab before selecting it. This | 445 // a tab in then background, then closes the tab before selecting it. This |
446 // is because closing the tab calls TabContents::Destroy(), which removes | 446 // is because closing the tab calls TabContents::Destroy(), which removes |
447 // the |render_view_host()|; then when we actually destroy the window, | 447 // the |render_view_host()|; then when we actually destroy the window, |
448 // OnWindowPosChanged() notices and calls HideContents() (which calls us). | 448 // OnWindowPosChanged() notices and calls HideContents() (which calls us). |
449 RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); | 449 RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); |
450 if (rwhv) | 450 if (rwhv) |
451 rwhv->WasHidden(); | 451 rwhv->WasHidden(); |
452 } | 452 } |
453 | 453 |
454 NotificationService::current()->Notify( | 454 content::NotificationService::current()->Notify( |
455 content::NOTIFICATION_TAB_CONTENTS_HIDDEN, | 455 content::NOTIFICATION_TAB_CONTENTS_HIDDEN, |
456 content::Source<TabContents>(this), | 456 content::Source<TabContents>(this), |
457 NotificationService::NoDetails()); | 457 content::NotificationService::NoDetails()); |
458 } | 458 } |
459 | 459 |
460 void TabContents::Activate() { | 460 void TabContents::Activate() { |
461 if (delegate_) | 461 if (delegate_) |
462 delegate_->ActivateContents(this); | 462 delegate_->ActivateContents(this); |
463 } | 463 } |
464 | 464 |
465 void TabContents::Deactivate() { | 465 void TabContents::Deactivate() { |
466 if (delegate_) | 466 if (delegate_) |
467 delegate_->DeactivateContents(this); | 467 delegate_->DeactivateContents(this); |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 // Send out a notification that we failed a provisional load with an error. | 976 // Send out a notification that we failed a provisional load with an error. |
977 ProvisionalLoadDetails details( | 977 ProvisionalLoadDetails details( |
978 params.is_main_frame, | 978 params.is_main_frame, |
979 controller_.IsURLInPageNavigation(validated_url), | 979 controller_.IsURLInPageNavigation(validated_url), |
980 validated_url, | 980 validated_url, |
981 std::string(), | 981 std::string(), |
982 false, | 982 false, |
983 params.frame_id); | 983 params.frame_id); |
984 details.set_error_code(params.error_code); | 984 details.set_error_code(params.error_code); |
985 | 985 |
986 NotificationService::current()->Notify( | 986 content::NotificationService::current()->Notify( |
987 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR, | 987 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR, |
988 content::Source<NavigationController>(&controller_), | 988 content::Source<NavigationController>(&controller_), |
989 content::Details<ProvisionalLoadDetails>(&details)); | 989 content::Details<ProvisionalLoadDetails>(&details)); |
990 | 990 |
991 FOR_EACH_OBSERVER(TabContentsObserver, | 991 FOR_EACH_OBSERVER(TabContentsObserver, |
992 observers_, | 992 observers_, |
993 DidFailProvisionalLoad(params.frame_id, | 993 DidFailProvisionalLoad(params.frame_id, |
994 params.is_main_frame, | 994 params.is_main_frame, |
995 validated_url, | 995 validated_url, |
996 params.error_code, | 996 params.error_code, |
(...skipping 13 matching lines...) Expand all Loading... |
1010 net::CertStatus cert_status = 0; | 1010 net::CertStatus cert_status = 0; |
1011 int security_bits = -1; | 1011 int security_bits = -1; |
1012 int connection_status = 0; | 1012 int connection_status = 0; |
1013 SSLManager::DeserializeSecurityInfo(security_info, | 1013 SSLManager::DeserializeSecurityInfo(security_info, |
1014 &cert_id, &cert_status, | 1014 &cert_id, &cert_status, |
1015 &security_bits, | 1015 &security_bits, |
1016 &connection_status); | 1016 &connection_status); |
1017 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->id(), | 1017 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->id(), |
1018 cert_id, cert_status); | 1018 cert_id, cert_status); |
1019 | 1019 |
1020 NotificationService::current()->Notify( | 1020 content::NotificationService::current()->Notify( |
1021 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE, | 1021 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE, |
1022 content::Source<NavigationController>(&controller_), | 1022 content::Source<NavigationController>(&controller_), |
1023 content::Details<LoadFromMemoryCacheDetails>(&details)); | 1023 content::Details<LoadFromMemoryCacheDetails>(&details)); |
1024 } | 1024 } |
1025 | 1025 |
1026 void TabContents::OnDidDisplayInsecureContent() { | 1026 void TabContents::OnDidDisplayInsecureContent() { |
1027 UserMetrics::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent")); | 1027 UserMetrics::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent")); |
1028 displayed_insecure_content_ = true; | 1028 displayed_insecure_content_ = true; |
1029 SSLManager::NotifySSLInternalStateChanged(&controller()); | 1029 SSLManager::NotifySSLInternalStateChanged(&controller()); |
1030 } | 1030 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 | 1083 |
1084 void TabContents::OnUpdateZoomLimits(int minimum_percent, | 1084 void TabContents::OnUpdateZoomLimits(int minimum_percent, |
1085 int maximum_percent, | 1085 int maximum_percent, |
1086 bool remember) { | 1086 bool remember) { |
1087 minimum_zoom_percent_ = minimum_percent; | 1087 minimum_zoom_percent_ = minimum_percent; |
1088 maximum_zoom_percent_ = maximum_percent; | 1088 maximum_zoom_percent_ = maximum_percent; |
1089 temporary_zoom_settings_ = !remember; | 1089 temporary_zoom_settings_ = !remember; |
1090 } | 1090 } |
1091 | 1091 |
1092 void TabContents::OnFocusedNodeChanged(bool is_editable_node) { | 1092 void TabContents::OnFocusedNodeChanged(bool is_editable_node) { |
1093 NotificationService::current()->Notify( | 1093 content::NotificationService::current()->Notify( |
1094 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, | 1094 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
1095 content::Source<TabContents>(this), | 1095 content::Source<TabContents>(this), |
1096 content::Details<const bool>(&is_editable_node)); | 1096 content::Details<const bool>(&is_editable_node)); |
1097 } | 1097 } |
1098 | 1098 |
1099 void TabContents::OnEnumerateDirectory(int request_id, | 1099 void TabContents::OnEnumerateDirectory(int request_id, |
1100 const FilePath& path) { | 1100 const FilePath& path) { |
1101 delegate()->EnumerateDirectory(this, request_id, path); | 1101 delegate()->EnumerateDirectory(this, request_id, path); |
1102 } | 1102 } |
1103 | 1103 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1170 | 1170 |
1171 is_loading_ = is_loading; | 1171 is_loading_ = is_loading; |
1172 waiting_for_response_ = is_loading; | 1172 waiting_for_response_ = is_loading; |
1173 | 1173 |
1174 if (delegate_) | 1174 if (delegate_) |
1175 delegate_->LoadingStateChanged(this); | 1175 delegate_->LoadingStateChanged(this); |
1176 NotifyNavigationStateChanged(INVALIDATE_LOAD); | 1176 NotifyNavigationStateChanged(INVALIDATE_LOAD); |
1177 | 1177 |
1178 int type = is_loading ? content::NOTIFICATION_LOAD_START : | 1178 int type = is_loading ? content::NOTIFICATION_LOAD_START : |
1179 content::NOTIFICATION_LOAD_STOP; | 1179 content::NOTIFICATION_LOAD_STOP; |
1180 content::NotificationDetails det = NotificationService::NoDetails(); | 1180 content::NotificationDetails det = content::NotificationService::NoDetails(); |
1181 if (details) | 1181 if (details) |
1182 det = content::Details<LoadNotificationDetails>(details); | 1182 det = content::Details<LoadNotificationDetails>(details); |
1183 NotificationService::current()->Notify(type, | 1183 content::NotificationService::current()->Notify(type, |
1184 content::Source<NavigationController>(&controller_), | 1184 content::Source<NavigationController>(&controller_), |
1185 det); | 1185 det); |
1186 } | 1186 } |
1187 | 1187 |
1188 WebUI* TabContents::GetWebUIForCurrentState() { | 1188 WebUI* TabContents::GetWebUIForCurrentState() { |
1189 // When there is a pending navigation entry, we want to use the pending WebUI | 1189 // When there is a pending navigation entry, we want to use the pending WebUI |
1190 // that goes along with it to control the basic flags. For example, we want to | 1190 // that goes along with it to control the basic flags. For example, we want to |
1191 // show the pending URL in the URL bar, so we want the display_url flag to | 1191 // show the pending URL in the URL bar, so we want the display_url flag to |
1192 // be from the pending entry. | 1192 // be from the pending entry. |
1193 // | 1193 // |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 return false; // Nothing changed, don't bother. | 1341 return false; // Nothing changed, don't bother. |
1342 | 1342 |
1343 page_title_when_no_navigation_entry_ = final_title; | 1343 page_title_when_no_navigation_entry_ = final_title; |
1344 } | 1344 } |
1345 | 1345 |
1346 // Lastly, set the title for the view. | 1346 // Lastly, set the title for the view. |
1347 view_->SetPageTitle(final_title); | 1347 view_->SetPageTitle(final_title); |
1348 | 1348 |
1349 TitleUpdatedDetails details(entry, explicit_set); | 1349 TitleUpdatedDetails details(entry, explicit_set); |
1350 | 1350 |
1351 NotificationService::current()->Notify( | 1351 content::NotificationService::current()->Notify( |
1352 content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED, | 1352 content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED, |
1353 content::Source<TabContents>(this), | 1353 content::Source<TabContents>(this), |
1354 content::Details<TitleUpdatedDetails>(&details)); | 1354 content::Details<TitleUpdatedDetails>(&details)); |
1355 | 1355 |
1356 return true; | 1356 return true; |
1357 } | 1357 } |
1358 | 1358 |
1359 void TabContents::NotifySwapped() { | 1359 void TabContents::NotifySwapped() { |
1360 // After sending out a swap notification, we need to send a disconnect | 1360 // After sending out a swap notification, we need to send a disconnect |
1361 // notification so that clients that pick up a pointer to |this| can NULL the | 1361 // notification so that clients that pick up a pointer to |this| can NULL the |
1362 // pointer. See Bug 1230284. | 1362 // pointer. See Bug 1230284. |
1363 notify_disconnection_ = true; | 1363 notify_disconnection_ = true; |
1364 NotificationService::current()->Notify( | 1364 content::NotificationService::current()->Notify( |
1365 content::NOTIFICATION_TAB_CONTENTS_SWAPPED, | 1365 content::NOTIFICATION_TAB_CONTENTS_SWAPPED, |
1366 content::Source<TabContents>(this), | 1366 content::Source<TabContents>(this), |
1367 NotificationService::NoDetails()); | 1367 content::NotificationService::NoDetails()); |
1368 } | 1368 } |
1369 | 1369 |
1370 void TabContents::NotifyConnected() { | 1370 void TabContents::NotifyConnected() { |
1371 notify_disconnection_ = true; | 1371 notify_disconnection_ = true; |
1372 NotificationService::current()->Notify( | 1372 content::NotificationService::current()->Notify( |
1373 content::NOTIFICATION_TAB_CONTENTS_CONNECTED, | 1373 content::NOTIFICATION_TAB_CONTENTS_CONNECTED, |
1374 content::Source<TabContents>(this), | 1374 content::Source<TabContents>(this), |
1375 NotificationService::NoDetails()); | 1375 content::NotificationService::NoDetails()); |
1376 } | 1376 } |
1377 | 1377 |
1378 void TabContents::NotifyDisconnected() { | 1378 void TabContents::NotifyDisconnected() { |
1379 if (!notify_disconnection_) | 1379 if (!notify_disconnection_) |
1380 return; | 1380 return; |
1381 | 1381 |
1382 notify_disconnection_ = false; | 1382 notify_disconnection_ = false; |
1383 NotificationService::current()->Notify( | 1383 content::NotificationService::current()->Notify( |
1384 content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, | 1384 content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, |
1385 content::Source<TabContents>(this), | 1385 content::Source<TabContents>(this), |
1386 NotificationService::NoDetails()); | 1386 content::NotificationService::NoDetails()); |
1387 } | 1387 } |
1388 | 1388 |
1389 RenderViewHostDelegate::View* TabContents::GetViewDelegate() { | 1389 RenderViewHostDelegate::View* TabContents::GetViewDelegate() { |
1390 return view_.get(); | 1390 return view_.get(); |
1391 } | 1391 } |
1392 | 1392 |
1393 RenderViewHostDelegate::RendererManagement* | 1393 RenderViewHostDelegate::RendererManagement* |
1394 TabContents::GetRendererManagementDelegate() { | 1394 TabContents::GetRendererManagementDelegate() { |
1395 return &render_manager_; | 1395 return &render_manager_; |
1396 } | 1396 } |
1397 | 1397 |
1398 RendererPreferences TabContents::GetRendererPrefs( | 1398 RendererPreferences TabContents::GetRendererPrefs( |
1399 content::BrowserContext* browser_context) const { | 1399 content::BrowserContext* browser_context) const { |
1400 return renderer_preferences_; | 1400 return renderer_preferences_; |
1401 } | 1401 } |
1402 | 1402 |
1403 TabContents* TabContents::GetAsTabContents() { | 1403 TabContents* TabContents::GetAsTabContents() { |
1404 return this; | 1404 return this; |
1405 } | 1405 } |
1406 | 1406 |
1407 content::ViewType TabContents::GetRenderViewType() const { | 1407 content::ViewType TabContents::GetRenderViewType() const { |
1408 return content::VIEW_TYPE_TAB_CONTENTS; | 1408 return content::VIEW_TYPE_TAB_CONTENTS; |
1409 } | 1409 } |
1410 | 1410 |
1411 void TabContents::RenderViewCreated(RenderViewHost* render_view_host) { | 1411 void TabContents::RenderViewCreated(RenderViewHost* render_view_host) { |
1412 NotificationService::current()->Notify( | 1412 content::NotificationService::current()->Notify( |
1413 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, | 1413 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, |
1414 content::Source<TabContents>(this), | 1414 content::Source<TabContents>(this), |
1415 content::Details<RenderViewHost>(render_view_host)); | 1415 content::Details<RenderViewHost>(render_view_host)); |
1416 NavigationEntry* entry = controller_.GetActiveEntry(); | 1416 NavigationEntry* entry = controller_.GetActiveEntry(); |
1417 if (!entry) | 1417 if (!entry) |
1418 return; | 1418 return; |
1419 | 1419 |
1420 // When we're creating views, we're still doing initial setup, so we always | 1420 // When we're creating views, we're still doing initial setup, so we always |
1421 // use the pending Web UI rather than any possibly existing committed one. | 1421 // use the pending Web UI rather than any possibly existing committed one. |
1422 if (render_manager_.pending_web_ui()) | 1422 if (render_manager_.pending_web_ui()) |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1671 } | 1671 } |
1672 | 1672 |
1673 void TabContents::DidChangeLoadProgress(double progress) { | 1673 void TabContents::DidChangeLoadProgress(double progress) { |
1674 if (delegate()) | 1674 if (delegate()) |
1675 delegate()->LoadProgressChanged(progress); | 1675 delegate()->LoadProgressChanged(progress); |
1676 } | 1676 } |
1677 | 1677 |
1678 void TabContents::DocumentOnLoadCompletedInMainFrame( | 1678 void TabContents::DocumentOnLoadCompletedInMainFrame( |
1679 RenderViewHost* render_view_host, | 1679 RenderViewHost* render_view_host, |
1680 int32 page_id) { | 1680 int32 page_id) { |
1681 NotificationService::current()->Notify( | 1681 content::NotificationService::current()->Notify( |
1682 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 1682 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
1683 content::Source<TabContents>(this), | 1683 content::Source<TabContents>(this), |
1684 content::Details<int>(&page_id)); | 1684 content::Details<int>(&page_id)); |
1685 } | 1685 } |
1686 | 1686 |
1687 void TabContents::RequestOpenURL(const GURL& url, | 1687 void TabContents::RequestOpenURL(const GURL& url, |
1688 const GURL& referrer, | 1688 const GURL& referrer, |
1689 WindowOpenDisposition disposition, | 1689 WindowOpenDisposition disposition, |
1690 int64 source_frame_id) { | 1690 int64 source_frame_id) { |
1691 TabContents* new_contents = NULL; | 1691 TabContents* new_contents = NULL; |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1994 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 1994 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
1995 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 1995 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
1996 rwh_view->SetSize(view()->GetContainerSize()); | 1996 rwh_view->SetSize(view()->GetContainerSize()); |
1997 } | 1997 } |
1998 | 1998 |
1999 bool TabContents::GotResponseToLockMouseRequest(bool allowed) { | 1999 bool TabContents::GotResponseToLockMouseRequest(bool allowed) { |
2000 return render_view_host() ? | 2000 return render_view_host() ? |
2001 render_view_host()->GotResponseToLockMouseRequest(allowed) : false; | 2001 render_view_host()->GotResponseToLockMouseRequest(allowed) : false; |
2002 } | 2002 } |
2003 | 2003 |
OLD | NEW |