Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: content/browser/web_contents/web_contents_impl.cc

Issue 1693353002: Reland #2 Remove the is_loading_ field from WebContentsImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Checking whether the frame is loading on history navigations Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 render_view_host_delegate_view_(NULL), 331 render_view_host_delegate_view_(NULL),
332 created_with_opener_(false), 332 created_with_opener_(false),
333 #if defined(OS_WIN) 333 #if defined(OS_WIN)
334 accessible_parent_(NULL), 334 accessible_parent_(NULL),
335 #endif 335 #endif
336 frame_tree_(new NavigatorImpl(&controller_, this), 336 frame_tree_(new NavigatorImpl(&controller_, this),
337 this, 337 this,
338 this, 338 this,
339 this, 339 this,
340 this), 340 this),
341 is_loading_(false),
342 is_load_to_different_document_(false), 341 is_load_to_different_document_(false),
343 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING), 342 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
344 crashed_error_code_(0), 343 crashed_error_code_(0),
345 waiting_for_response_(false), 344 waiting_for_response_(false),
346 load_state_(net::LOAD_STATE_IDLE, base::string16()), 345 load_state_(net::LOAD_STATE_IDLE, base::string16()),
347 upload_size_(0), 346 upload_size_(0),
348 upload_position_(0), 347 upload_position_(0),
349 is_resume_pending_(false), 348 is_resume_pending_(false),
349 paused_throbber_for_interstitial_(false),
350 displayed_insecure_content_(false), 350 displayed_insecure_content_(false),
351 has_accessed_initial_document_(false), 351 has_accessed_initial_document_(false),
352 theme_color_(SK_ColorTRANSPARENT), 352 theme_color_(SK_ColorTRANSPARENT),
353 last_sent_theme_color_(SK_ColorTRANSPARENT), 353 last_sent_theme_color_(SK_ColorTRANSPARENT),
354 did_first_visually_non_empty_paint_(false), 354 did_first_visually_non_empty_paint_(false),
355 capturer_count_(0), 355 capturer_count_(0),
356 should_normally_be_visible_(true), 356 should_normally_be_visible_(true),
357 is_being_destroyed_(false), 357 is_being_destroyed_(false),
358 notify_disconnection_(false), 358 notify_disconnection_(false),
359 dialog_manager_(NULL), 359 dialog_manager_(NULL),
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 renderer_preferences_.user_agent_override = override; 889 renderer_preferences_.user_agent_override = override;
890 890
891 // Send the new override string to the renderer. 891 // Send the new override string to the renderer.
892 RenderViewHost* host = GetRenderViewHost(); 892 RenderViewHost* host = GetRenderViewHost();
893 if (host) 893 if (host)
894 host->SyncRendererPrefs(); 894 host->SyncRendererPrefs();
895 895
896 // Reload the page if a load is currently in progress to avoid having 896 // Reload the page if a load is currently in progress to avoid having
897 // different parts of the page loaded using different user agents. 897 // different parts of the page loaded using different user agents.
898 NavigationEntry* entry = controller_.GetVisibleEntry(); 898 NavigationEntry* entry = controller_.GetVisibleEntry();
899 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent()) 899 if (IsLoading() && entry != NULL && entry->GetIsOverridingUserAgent())
900 controller_.ReloadIgnoringCache(true); 900 controller_.ReloadIgnoringCache(true);
901 901
902 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 902 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
903 UserAgentOverrideSet(override)); 903 UserAgentOverrideSet(override));
904 } 904 }
905 905
906 const std::string& WebContentsImpl::GetUserAgentOverride() const { 906 const std::string& WebContentsImpl::GetUserAgentOverride() const {
907 return renderer_preferences_.user_agent_override; 907 return renderer_preferences_.user_agent_override;
908 } 908 }
909 909
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 1029
1030 SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const { 1030 SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
1031 RenderViewHostImpl* dest_rvh = 1031 RenderViewHostImpl* dest_rvh =
1032 GetRenderManager()->pending_render_view_host() ? 1032 GetRenderManager()->pending_render_view_host() ?
1033 GetRenderManager()->pending_render_view_host() : 1033 GetRenderManager()->pending_render_view_host() :
1034 GetRenderManager()->current_host(); 1034 GetRenderManager()->current_host();
1035 return dest_rvh->GetSiteInstance(); 1035 return dest_rvh->GetSiteInstance();
1036 } 1036 }
1037 1037
1038 bool WebContentsImpl::IsLoading() const { 1038 bool WebContentsImpl::IsLoading() const {
1039 return is_loading_; 1039 return frame_tree_.IsLoading() && !paused_throbber_for_interstitial_;
1040 } 1040 }
1041 1041
1042 bool WebContentsImpl::IsLoadingToDifferentDocument() const { 1042 bool WebContentsImpl::IsLoadingToDifferentDocument() const {
1043 return is_loading_ && is_load_to_different_document_; 1043 return IsLoading() && is_load_to_different_document_;
1044 } 1044 }
1045 1045
1046 bool WebContentsImpl::IsWaitingForResponse() const { 1046 bool WebContentsImpl::IsWaitingForResponse() const {
1047 return waiting_for_response_ && is_load_to_different_document_; 1047 return waiting_for_response_ && is_load_to_different_document_;
1048 } 1048 }
1049 1049
1050 const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const { 1050 const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
1051 return load_state_; 1051 return load_state_;
1052 } 1052 }
1053 1053
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after
2308 InterstitialPageImpl* interstitial_page) { 2308 InterstitialPageImpl* interstitial_page) {
2309 DCHECK(interstitial_page); 2309 DCHECK(interstitial_page);
2310 GetRenderManager()->set_interstitial_page(interstitial_page); 2310 GetRenderManager()->set_interstitial_page(interstitial_page);
2311 2311
2312 // Cancel any visible dialogs so that they don't interfere with the 2312 // Cancel any visible dialogs so that they don't interfere with the
2313 // interstitial. 2313 // interstitial.
2314 CancelActiveAndPendingDialogs(); 2314 CancelActiveAndPendingDialogs();
2315 2315
2316 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 2316 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2317 DidAttachInterstitialPage()); 2317 DidAttachInterstitialPage());
2318
2319 // Stop the throbber if needed while the interstitial page is shown.
2320 if (IsLoading())
2321 LoadingStateChanged(false, true, true, nullptr);
2322 }
2323
2324 void WebContentsImpl::DidProceedOnInterstitial() {
2325 // Restart the throbber now that the interstitial page is going away.
2326 if (paused_throbber_for_interstitial_) {
2327 if (frame_tree_.IsLoading())
2328 LoadingStateChanged(true, true, false, nullptr);
2329 }
2318 } 2330 }
2319 2331
2320 void WebContentsImpl::DetachInterstitialPage() { 2332 void WebContentsImpl::DetachInterstitialPage() {
2321 if (ShowingInterstitialPage()) 2333 if (ShowingInterstitialPage())
2322 GetRenderManager()->remove_interstitial_page(); 2334 GetRenderManager()->remove_interstitial_page();
2323 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 2335 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2324 DidDetachInterstitialPage()); 2336 DidDetachInterstitialPage());
2337 // Restart the throbber now that the interstitial page is going away.
2338 if (paused_throbber_for_interstitial_) {
2339 if (frame_tree_.IsLoading())
2340 LoadingStateChanged(true, true, false, nullptr);
2341 }
2325 } 2342 }
2326 2343
2327 void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset, 2344 void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2328 int history_length) { 2345 int history_length) {
2329 SetHistoryOffsetAndLengthForView( 2346 SetHistoryOffsetAndLengthForView(
2330 GetRenderViewHost(), history_offset, history_length); 2347 GetRenderViewHost(), history_offset, history_length);
2331 } 2348 }
2332 2349
2333 void WebContentsImpl::SetHistoryOffsetAndLengthForView( 2350 void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2334 RenderViewHost* render_view_host, 2351 RenderViewHost* render_view_host,
(...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after
3587 if (delegate_) 3604 if (delegate_)
3588 delegate_->ShowRepostFormWarningDialog(this); 3605 delegate_->ShowRepostFormWarningDialog(this);
3589 } 3606 }
3590 3607
3591 bool WebContentsImpl::HasAccessedInitialDocument() { 3608 bool WebContentsImpl::HasAccessedInitialDocument() {
3592 return has_accessed_initial_document_; 3609 return has_accessed_initial_document_;
3593 } 3610 }
3594 3611
3595 // Notifies the RenderWidgetHost instance about the fact that the page is 3612 // Notifies the RenderWidgetHost instance about the fact that the page is
3596 // loading, or done loading. 3613 // loading, or done loading.
3597 void WebContentsImpl::SetIsLoading(bool is_loading, 3614 void WebContentsImpl::LoadingStateChanged(bool is_loading,
3598 bool to_different_document, 3615 bool to_different_document,
3599 LoadNotificationDetails* details) { 3616 bool pause_throbber_for_interstitial,
3600 if (is_loading == is_loading_) 3617 LoadNotificationDetails* details) {
3618 // Do not send notifications about loading while the interstitial is showing.
3619 if (paused_throbber_for_interstitial_ && pause_throbber_for_interstitial)
3601 return; 3620 return;
3602 3621
3622 // Update whether the interstitial state.
3623 paused_throbber_for_interstitial_ = pause_throbber_for_interstitial;
3624
3603 if (!is_loading) { 3625 if (!is_loading) {
3604 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, 3626 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3605 base::string16()); 3627 base::string16());
3606 load_state_host_.clear(); 3628 load_state_host_.clear();
3607 upload_size_ = 0; 3629 upload_size_ = 0;
3608 upload_position_ = 0; 3630 upload_position_ = 0;
3609 } 3631 }
3610 3632
3611 GetRenderManager()->SetIsLoading(is_loading); 3633 GetRenderManager()->SetIsLoading(is_loading);
3612 3634
3613 is_loading_ = is_loading;
3614 waiting_for_response_ = is_loading; 3635 waiting_for_response_ = is_loading;
3615 is_load_to_different_document_ = to_different_document; 3636 is_load_to_different_document_ = to_different_document;
3616 3637
3617 if (delegate_) 3638 if (delegate_)
3618 delegate_->LoadingStateChanged(this, to_different_document); 3639 delegate_->LoadingStateChanged(this, to_different_document);
3619 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD); 3640 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
3620 3641
3621 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL"); 3642 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
3622 if (is_loading) { 3643 if (is_loading) {
3623 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading", 3644 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
3956 // renderer may not have made a clean exit. 3977 // renderer may not have made a clean exit.
3957 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget())) 3978 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
3958 ExitFullscreenMode(false); 3979 ExitFullscreenMode(false);
3959 3980
3960 // Cancel any visible dialogs so they are not left dangling over the sad tab. 3981 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3961 CancelActiveAndPendingDialogs(); 3982 CancelActiveAndPendingDialogs();
3962 3983
3963 if (delegate_) 3984 if (delegate_)
3964 delegate_->HideValidationMessage(this); 3985 delegate_->HideValidationMessage(this);
3965 3986
3966 SetIsLoading(false, true, nullptr);
3967 NotifyDisconnected();
3968 SetIsCrashed(status, error_code);
3969
3970 // Reset the loading progress. TODO(avi): What does it mean to have a 3987 // Reset the loading progress. TODO(avi): What does it mean to have a
3971 // "renderer crash" when there is more than one renderer process serving a 3988 // "renderer crash" when there is more than one renderer process serving a
3972 // webpage? Once this function is called at a more granular frame level, we 3989 // webpage? Once this function is called at a more granular frame level, we
3973 // probably will need to more granularly reset the state here. 3990 // probably will need to more granularly reset the state here.
3974 ResetLoadProgressState(); 3991 ResetLoadProgressState();
3992 NotifyDisconnected();
3993 SetIsCrashed(status, error_code);
3975 3994
3976 FOR_EACH_OBSERVER(WebContentsObserver, 3995 FOR_EACH_OBSERVER(WebContentsObserver,
3977 observers_, 3996 observers_,
3978 RenderProcessGone(GetCrashedStatus())); 3997 RenderProcessGone(GetCrashedStatus()));
3979 } 3998 }
3980 3999
3981 void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) { 4000 void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
3982 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh)); 4001 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
3983 } 4002 }
3984 4003
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
4058 delegate_->SwappedOut(this); 4077 delegate_->SwappedOut(this);
4059 } 4078 }
4060 4079
4061 void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) { 4080 void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
4062 if (delegate_ && delegate_->IsPopupOrPanel(this)) 4081 if (delegate_ && delegate_->IsPopupOrPanel(this))
4063 delegate_->MoveContents(this, new_bounds); 4082 delegate_->MoveContents(this, new_bounds);
4064 } 4083 }
4065 4084
4066 void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node, 4085 void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
4067 bool to_different_document) { 4086 bool to_different_document) {
4068 SetIsLoading(true, to_different_document, nullptr); 4087 LoadingStateChanged(true, to_different_document,
4088 paused_throbber_for_interstitial_, nullptr);
4069 4089
4070 // Notify accessibility that the user is navigating away from the 4090 // Notify accessibility that the user is navigating away from the
4071 // current document. 4091 // current document.
4072 // 4092 //
4073 // TODO(dmazzoni): do this using a WebContentsObserver. 4093 // TODO(dmazzoni): do this using a WebContentsObserver.
4074 BrowserAccessibilityManager* manager = 4094 BrowserAccessibilityManager* manager =
4075 frame_tree_node->current_frame_host()->browser_accessibility_manager(); 4095 frame_tree_node->current_frame_host()->browser_accessibility_manager();
4076 if (manager) 4096 if (manager)
4077 manager->UserIsNavigatingAway(); 4097 manager->UserIsNavigatingAway();
4078 } 4098 }
(...skipping 13 matching lines...) Expand all
4092 base::TimeTicks::Now() - navigator->GetCurrentLoadStart(); 4112 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
4093 4113
4094 details.reset(new LoadNotificationDetails( 4114 details.reset(new LoadNotificationDetails(
4095 entry->GetVirtualURL(), 4115 entry->GetVirtualURL(),
4096 entry->GetTransitionType(), 4116 entry->GetTransitionType(),
4097 elapsed, 4117 elapsed,
4098 &controller_, 4118 &controller_,
4099 controller_.GetCurrentEntryIndex())); 4119 controller_.GetCurrentEntryIndex()));
4100 } 4120 }
4101 4121
4102 SetIsLoading(false, true, details.get()); 4122 LoadingStateChanged(false, true, paused_throbber_for_interstitial_,
4123 details.get());
4103 } 4124 }
4104 4125
4105 void WebContentsImpl::DidChangeLoadProgress() { 4126 void WebContentsImpl::DidChangeLoadProgress() {
4106 double load_progress = frame_tree_.load_progress(); 4127 double load_progress = frame_tree_.load_progress();
4107 4128
4108 // The delegate is notified immediately for the first and last updates. Also, 4129 // The delegate is notified immediately for the first and last updates. Also,
4109 // since the message loop may be pretty busy when a page is loaded, it might 4130 // since the message loop may be pretty busy when a page is loaded, it might
4110 // not execute a posted task in a timely manner so the progress report is sent 4131 // not execute a posted task in a timely manner so the progress report is sent
4111 // immediately if enough time has passed. 4132 // immediately if enough time has passed.
4112 base::TimeDelta min_delay = 4133 base::TimeDelta min_delay =
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
4629 int render_frame_id, 4650 int render_frame_id,
4630 IPC::Message* reply_msg, 4651 IPC::Message* reply_msg,
4631 bool dialog_was_suppressed, 4652 bool dialog_was_suppressed,
4632 bool success, 4653 bool success,
4633 const base::string16& user_input) { 4654 const base::string16& user_input) {
4634 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id, 4655 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4635 render_frame_id); 4656 render_frame_id);
4636 last_dialog_suppressed_ = dialog_was_suppressed; 4657 last_dialog_suppressed_ = dialog_was_suppressed;
4637 4658
4638 if (is_showing_before_unload_dialog_ && !success) { 4659 if (is_showing_before_unload_dialog_ && !success) {
4639 // If a beforeunload dialog is canceled, we need to stop the throbber from
4640 // spinning, since we forced it to start spinning in Navigate.
4641 if (rfh) 4660 if (rfh)
4642 DidStopLoading(); 4661 rfh->frame_tree_node()->BeforeUnloadCanceled();
4643 controller_.DiscardNonCommittedEntries(); 4662 controller_.DiscardNonCommittedEntries();
4644 4663
4645 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 4664 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4646 BeforeUnloadDialogCancelled()); 4665 BeforeUnloadDialogCancelled());
4647 } 4666 }
4648 4667
4649 is_showing_before_unload_dialog_ = false; 4668 is_showing_before_unload_dialog_ = false;
4650 if (rfh) { 4669 if (rfh) {
4651 rfh->JavaScriptDialogClosed(reply_msg, success, user_input, 4670 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4652 dialog_was_suppressed); 4671 dialog_was_suppressed);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
4758 const WebContentsObserver::MediaPlayerId& id) { 4777 const WebContentsObserver::MediaPlayerId& id) {
4759 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id)); 4778 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id));
4760 } 4779 }
4761 4780
4762 void WebContentsImpl::MediaStoppedPlaying( 4781 void WebContentsImpl::MediaStoppedPlaying(
4763 const WebContentsObserver::MediaPlayerId& id) { 4782 const WebContentsObserver::MediaPlayerId& id) {
4764 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id)); 4783 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id));
4765 } 4784 }
4766 4785
4767 } // namespace content 4786 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698