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

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: Addressed comments 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),
350 displayed_insecure_content_(false), 349 displayed_insecure_content_(false),
351 has_accessed_initial_document_(false), 350 has_accessed_initial_document_(false),
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 renderer_preferences_.user_agent_override = override; 888 renderer_preferences_.user_agent_override = override;
890 889
891 // Send the new override string to the renderer. 890 // Send the new override string to the renderer.
892 RenderViewHost* host = GetRenderViewHost(); 891 RenderViewHost* host = GetRenderViewHost();
893 if (host) 892 if (host)
894 host->SyncRendererPrefs(); 893 host->SyncRendererPrefs();
895 894
896 // Reload the page if a load is currently in progress to avoid having 895 // Reload the page if a load is currently in progress to avoid having
897 // different parts of the page loaded using different user agents. 896 // different parts of the page loaded using different user agents.
898 NavigationEntry* entry = controller_.GetVisibleEntry(); 897 NavigationEntry* entry = controller_.GetVisibleEntry();
899 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent()) 898 if (IsLoading() && entry != NULL && entry->GetIsOverridingUserAgent())
900 controller_.ReloadIgnoringCache(true); 899 controller_.ReloadIgnoringCache(true);
901 900
902 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 901 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
903 UserAgentOverrideSet(override)); 902 UserAgentOverrideSet(override));
904 } 903 }
905 904
906 const std::string& WebContentsImpl::GetUserAgentOverride() const { 905 const std::string& WebContentsImpl::GetUserAgentOverride() const {
907 return renderer_preferences_.user_agent_override; 906 return renderer_preferences_.user_agent_override;
908 } 907 }
909 908
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 1028
1030 SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const { 1029 SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
1031 RenderViewHostImpl* dest_rvh = 1030 RenderViewHostImpl* dest_rvh =
1032 GetRenderManager()->pending_render_view_host() ? 1031 GetRenderManager()->pending_render_view_host() ?
1033 GetRenderManager()->pending_render_view_host() : 1032 GetRenderManager()->pending_render_view_host() :
1034 GetRenderManager()->current_host(); 1033 GetRenderManager()->current_host();
1035 return dest_rvh->GetSiteInstance(); 1034 return dest_rvh->GetSiteInstance();
1036 } 1035 }
1037 1036
1038 bool WebContentsImpl::IsLoading() const { 1037 bool WebContentsImpl::IsLoading() const {
1039 return is_loading_; 1038 return frame_tree_.IsLoading() &&
1039 !(ShowingInterstitialPage() &&
1040 GetRenderManager()->interstitial_page()->pause_throbber());
1040 } 1041 }
1041 1042
1042 bool WebContentsImpl::IsLoadingToDifferentDocument() const { 1043 bool WebContentsImpl::IsLoadingToDifferentDocument() const {
1043 return is_loading_ && is_load_to_different_document_; 1044 return IsLoading() && is_load_to_different_document_;
1044 } 1045 }
1045 1046
1046 bool WebContentsImpl::IsWaitingForResponse() const { 1047 bool WebContentsImpl::IsWaitingForResponse() const {
1047 return waiting_for_response_ && is_load_to_different_document_; 1048 return waiting_for_response_ && is_load_to_different_document_;
1048 } 1049 }
1049 1050
1050 const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const { 1051 const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
1051 return load_state_; 1052 return load_state_;
1052 } 1053 }
1053 1054
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after
2308 InterstitialPageImpl* interstitial_page) { 2309 InterstitialPageImpl* interstitial_page) {
2309 DCHECK(interstitial_page); 2310 DCHECK(interstitial_page);
2310 GetRenderManager()->set_interstitial_page(interstitial_page); 2311 GetRenderManager()->set_interstitial_page(interstitial_page);
2311 2312
2312 // Cancel any visible dialogs so that they don't interfere with the 2313 // Cancel any visible dialogs so that they don't interfere with the
2313 // interstitial. 2314 // interstitial.
2314 CancelActiveAndPendingDialogs(); 2315 CancelActiveAndPendingDialogs();
2315 2316
2316 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 2317 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2317 DidAttachInterstitialPage()); 2318 DidAttachInterstitialPage());
2319
2320 // Stop the throbber if needed while the interstitial page is shown.
2321 if (frame_tree_.IsLoading())
2322 LoadingStateChanged(true, true, nullptr);
2323 }
2324
2325 void WebContentsImpl::DidProceedOnInterstitial() {
2326 // The interstitial page should no longer be pausing the throbber.
2327 DCHECK(!(ShowingInterstitialPage() &&
2328 GetRenderManager()->interstitial_page()->pause_throbber()));
2329
2330 // Restart the throbber now that the interstitial page no longer pauses it.
2331 if (ShowingInterstitialPage() && frame_tree_.IsLoading())
2332 LoadingStateChanged(true, true, nullptr);
2318 } 2333 }
2319 2334
2320 void WebContentsImpl::DetachInterstitialPage() { 2335 void WebContentsImpl::DetachInterstitialPage() {
2336 bool interstitial_pausing_throbber =
2337 ShowingInterstitialPage() &&
2338 GetRenderManager()->interstitial_page()->pause_throbber();
2321 if (ShowingInterstitialPage()) 2339 if (ShowingInterstitialPage())
2322 GetRenderManager()->remove_interstitial_page(); 2340 GetRenderManager()->remove_interstitial_page();
2323 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 2341 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2324 DidDetachInterstitialPage()); 2342 DidDetachInterstitialPage());
2343
2344 // Restart the throbber if needed now that the interstitial page is going
2345 // away.
2346 if (interstitial_pausing_throbber && frame_tree_.IsLoading())
2347 LoadingStateChanged(true, true, nullptr);
2325 } 2348 }
2326 2349
2327 void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset, 2350 void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2328 int history_length) { 2351 int history_length) {
2329 SetHistoryOffsetAndLengthForView( 2352 SetHistoryOffsetAndLengthForView(
2330 GetRenderViewHost(), history_offset, history_length); 2353 GetRenderViewHost(), history_offset, history_length);
2331 } 2354 }
2332 2355
2333 void WebContentsImpl::SetHistoryOffsetAndLengthForView( 2356 void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2334 RenderViewHost* render_view_host, 2357 RenderViewHost* render_view_host,
(...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after
3587 if (delegate_) 3610 if (delegate_)
3588 delegate_->ShowRepostFormWarningDialog(this); 3611 delegate_->ShowRepostFormWarningDialog(this);
3589 } 3612 }
3590 3613
3591 bool WebContentsImpl::HasAccessedInitialDocument() { 3614 bool WebContentsImpl::HasAccessedInitialDocument() {
3592 return has_accessed_initial_document_; 3615 return has_accessed_initial_document_;
3593 } 3616 }
3594 3617
3595 // Notifies the RenderWidgetHost instance about the fact that the page is 3618 // Notifies the RenderWidgetHost instance about the fact that the page is
3596 // loading, or done loading. 3619 // loading, or done loading.
3597 void WebContentsImpl::SetIsLoading(bool is_loading, 3620 void WebContentsImpl::LoadingStateChanged(bool to_different_document,
3598 bool to_different_document, 3621 bool due_to_interstitial,
3599 LoadNotificationDetails* details) { 3622 LoadNotificationDetails* details) {
3600 if (is_loading == is_loading_) 3623 // Do not send notifications about loading changes in the FrameTree while the
3624 // interstitial page is pausing the throbber.
3625 if (ShowingInterstitialPage() &&
3626 GetRenderManager()->interstitial_page()->pause_throbber() &&
3627 !due_to_interstitial) {
3601 return; 3628 return;
3629 }
3630
3631 bool is_loading = IsLoading();
3602 3632
3603 if (!is_loading) { 3633 if (!is_loading) {
3604 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, 3634 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3605 base::string16()); 3635 base::string16());
3606 load_state_host_.clear(); 3636 load_state_host_.clear();
3607 upload_size_ = 0; 3637 upload_size_ = 0;
3608 upload_position_ = 0; 3638 upload_position_ = 0;
3609 } 3639 }
3610 3640
3611 GetRenderManager()->SetIsLoading(is_loading); 3641 GetRenderManager()->SetIsLoading(is_loading);
3612 3642
3613 is_loading_ = is_loading;
3614 waiting_for_response_ = is_loading; 3643 waiting_for_response_ = is_loading;
3615 is_load_to_different_document_ = to_different_document; 3644 is_load_to_different_document_ = to_different_document;
3616 3645
3617 if (delegate_) 3646 if (delegate_)
3618 delegate_->LoadingStateChanged(this, to_different_document); 3647 delegate_->LoadingStateChanged(this, to_different_document);
3619 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD); 3648 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
3620 3649
3621 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL"); 3650 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
3622 if (is_loading) { 3651 if (is_loading) {
3623 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading", 3652 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. 3985 // renderer may not have made a clean exit.
3957 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget())) 3986 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
3958 ExitFullscreenMode(false); 3987 ExitFullscreenMode(false);
3959 3988
3960 // Cancel any visible dialogs so they are not left dangling over the sad tab. 3989 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3961 CancelActiveAndPendingDialogs(); 3990 CancelActiveAndPendingDialogs();
3962 3991
3963 if (delegate_) 3992 if (delegate_)
3964 delegate_->HideValidationMessage(this); 3993 delegate_->HideValidationMessage(this);
3965 3994
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 3995 // 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 3996 // "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 3997 // webpage? Once this function is called at a more granular frame level, we
3973 // probably will need to more granularly reset the state here. 3998 // probably will need to more granularly reset the state here.
3974 ResetLoadProgressState(); 3999 ResetLoadProgressState();
4000 NotifyDisconnected();
4001 SetIsCrashed(status, error_code);
3975 4002
3976 FOR_EACH_OBSERVER(WebContentsObserver, 4003 FOR_EACH_OBSERVER(WebContentsObserver,
3977 observers_, 4004 observers_,
3978 RenderProcessGone(GetCrashedStatus())); 4005 RenderProcessGone(GetCrashedStatus()));
3979 } 4006 }
3980 4007
3981 void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) { 4008 void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
3982 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh)); 4009 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
3983 } 4010 }
3984 4011
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
4058 delegate_->SwappedOut(this); 4085 delegate_->SwappedOut(this);
4059 } 4086 }
4060 4087
4061 void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) { 4088 void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
4062 if (delegate_ && delegate_->IsPopupOrPanel(this)) 4089 if (delegate_ && delegate_->IsPopupOrPanel(this))
4063 delegate_->MoveContents(this, new_bounds); 4090 delegate_->MoveContents(this, new_bounds);
4064 } 4091 }
4065 4092
4066 void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node, 4093 void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
4067 bool to_different_document) { 4094 bool to_different_document) {
4068 SetIsLoading(true, to_different_document, nullptr); 4095 LoadingStateChanged(to_different_document, false, nullptr);
4069 4096
4070 // Notify accessibility that the user is navigating away from the 4097 // Notify accessibility that the user is navigating away from the
4071 // current document. 4098 // current document.
4072 // 4099 //
4073 // TODO(dmazzoni): do this using a WebContentsObserver. 4100 // TODO(dmazzoni): do this using a WebContentsObserver.
4074 BrowserAccessibilityManager* manager = 4101 BrowserAccessibilityManager* manager =
4075 frame_tree_node->current_frame_host()->browser_accessibility_manager(); 4102 frame_tree_node->current_frame_host()->browser_accessibility_manager();
4076 if (manager) 4103 if (manager)
4077 manager->UserIsNavigatingAway(); 4104 manager->UserIsNavigatingAway();
4078 } 4105 }
(...skipping 13 matching lines...) Expand all
4092 base::TimeTicks::Now() - navigator->GetCurrentLoadStart(); 4119 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
4093 4120
4094 details.reset(new LoadNotificationDetails( 4121 details.reset(new LoadNotificationDetails(
4095 entry->GetVirtualURL(), 4122 entry->GetVirtualURL(),
4096 entry->GetTransitionType(), 4123 entry->GetTransitionType(),
4097 elapsed, 4124 elapsed,
4098 &controller_, 4125 &controller_,
4099 controller_.GetCurrentEntryIndex())); 4126 controller_.GetCurrentEntryIndex()));
4100 } 4127 }
4101 4128
4102 SetIsLoading(false, true, details.get()); 4129 LoadingStateChanged(true, false, details.get());
4103 } 4130 }
4104 4131
4105 void WebContentsImpl::DidChangeLoadProgress() { 4132 void WebContentsImpl::DidChangeLoadProgress() {
4106 double load_progress = frame_tree_.load_progress(); 4133 double load_progress = frame_tree_.load_progress();
4107 4134
4108 // The delegate is notified immediately for the first and last updates. Also, 4135 // 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 4136 // 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 4137 // not execute a posted task in a timely manner so the progress report is sent
4111 // immediately if enough time has passed. 4138 // immediately if enough time has passed.
4112 base::TimeDelta min_delay = 4139 base::TimeDelta min_delay =
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
4629 int render_frame_id, 4656 int render_frame_id,
4630 IPC::Message* reply_msg, 4657 IPC::Message* reply_msg,
4631 bool dialog_was_suppressed, 4658 bool dialog_was_suppressed,
4632 bool success, 4659 bool success,
4633 const base::string16& user_input) { 4660 const base::string16& user_input) {
4634 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id, 4661 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4635 render_frame_id); 4662 render_frame_id);
4636 last_dialog_suppressed_ = dialog_was_suppressed; 4663 last_dialog_suppressed_ = dialog_was_suppressed;
4637 4664
4638 if (is_showing_before_unload_dialog_ && !success) { 4665 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) 4666 if (rfh)
4642 DidStopLoading(); 4667 rfh->frame_tree_node()->BeforeUnloadCanceled();
4643 controller_.DiscardNonCommittedEntries(); 4668 controller_.DiscardNonCommittedEntries();
4644 4669
4645 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 4670 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4646 BeforeUnloadDialogCancelled()); 4671 BeforeUnloadDialogCancelled());
4647 } 4672 }
4648 4673
4649 is_showing_before_unload_dialog_ = false; 4674 is_showing_before_unload_dialog_ = false;
4650 if (rfh) { 4675 if (rfh) {
4651 rfh->JavaScriptDialogClosed(reply_msg, success, user_input, 4676 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4652 dialog_was_suppressed); 4677 dialog_was_suppressed);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
4758 const WebContentsObserver::MediaPlayerId& id) { 4783 const WebContentsObserver::MediaPlayerId& id) {
4759 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id)); 4784 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id));
4760 } 4785 }
4761 4786
4762 void WebContentsImpl::MediaStoppedPlaying( 4787 void WebContentsImpl::MediaStoppedPlaying(
4763 const WebContentsObserver::MediaPlayerId& id) { 4788 const WebContentsObserver::MediaPlayerId& id) {
4764 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id)); 4789 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id));
4765 } 4790 }
4766 4791
4767 } // namespace content 4792 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698