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

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

Issue 1690653003: Reland #1 Remove the is_loading_ field from WebContentsImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Nasko's comment 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 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after
2301 InterstitialPageImpl* interstitial_page) { 2301 InterstitialPageImpl* interstitial_page) {
2302 DCHECK(interstitial_page); 2302 DCHECK(interstitial_page);
2303 GetRenderManager()->set_interstitial_page(interstitial_page); 2303 GetRenderManager()->set_interstitial_page(interstitial_page);
2304 2304
2305 // Cancel any visible dialogs so that they don't interfere with the 2305 // Cancel any visible dialogs so that they don't interfere with the
2306 // interstitial. 2306 // interstitial.
2307 CancelActiveAndPendingDialogs(); 2307 CancelActiveAndPendingDialogs();
2308 2308
2309 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 2309 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2310 DidAttachInterstitialPage()); 2310 DidAttachInterstitialPage());
2311
2312 // Stop the throbber if needed while the interstitial page is shown.
2313 if (IsLoading())
2314 LoadingStateChanged(false, true, true, nullptr);
2315 }
2316
2317 void WebContentsImpl::DidProceedOnInterstitial() {
2318 // Restart the throbber now that the interstitial page is going away.
2319 if (paused_throbber_for_interstitial_) {
2320 if (frame_tree_.IsLoading())
2321 LoadingStateChanged(true, true, false, nullptr);
2322 }
2311 } 2323 }
2312 2324
2313 void WebContentsImpl::DetachInterstitialPage() { 2325 void WebContentsImpl::DetachInterstitialPage() {
2314 if (ShowingInterstitialPage()) 2326 if (ShowingInterstitialPage())
2315 GetRenderManager()->remove_interstitial_page(); 2327 GetRenderManager()->remove_interstitial_page();
2316 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 2328 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2317 DidDetachInterstitialPage()); 2329 DidDetachInterstitialPage());
2330 // Restart the throbber now that the interstitial page is going away.
2331 if (paused_throbber_for_interstitial_) {
2332 if (frame_tree_.IsLoading())
2333 LoadingStateChanged(true, true, false, nullptr);
2334 }
2318 } 2335 }
2319 2336
2320 void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset, 2337 void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2321 int history_length) { 2338 int history_length) {
2322 SetHistoryOffsetAndLengthForView( 2339 SetHistoryOffsetAndLengthForView(
2323 GetRenderViewHost(), history_offset, history_length); 2340 GetRenderViewHost(), history_offset, history_length);
2324 } 2341 }
2325 2342
2326 void WebContentsImpl::SetHistoryOffsetAndLengthForView( 2343 void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2327 RenderViewHost* render_view_host, 2344 RenderViewHost* render_view_host,
(...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after
3580 if (delegate_) 3597 if (delegate_)
3581 delegate_->ShowRepostFormWarningDialog(this); 3598 delegate_->ShowRepostFormWarningDialog(this);
3582 } 3599 }
3583 3600
3584 bool WebContentsImpl::HasAccessedInitialDocument() { 3601 bool WebContentsImpl::HasAccessedInitialDocument() {
3585 return has_accessed_initial_document_; 3602 return has_accessed_initial_document_;
3586 } 3603 }
3587 3604
3588 // Notifies the RenderWidgetHost instance about the fact that the page is 3605 // Notifies the RenderWidgetHost instance about the fact that the page is
3589 // loading, or done loading. 3606 // loading, or done loading.
3590 void WebContentsImpl::SetIsLoading(bool is_loading, 3607 void WebContentsImpl::LoadingStateChanged(bool is_loading,
3591 bool to_different_document, 3608 bool to_different_document,
3592 LoadNotificationDetails* details) { 3609 bool pause_throbber_for_interstitial,
3593 if (is_loading == is_loading_) 3610 LoadNotificationDetails* details) {
3611 // Do not send notifications about loading while the interstitial is showing.
3612 if (paused_throbber_for_interstitial_ && pause_throbber_for_interstitial)
3594 return; 3613 return;
3595 3614
3615 // Update whether the interstitial state.
3616 paused_throbber_for_interstitial_ = pause_throbber_for_interstitial;
3617
3596 if (!is_loading) { 3618 if (!is_loading) {
3597 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, 3619 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3598 base::string16()); 3620 base::string16());
3599 load_state_host_.clear(); 3621 load_state_host_.clear();
3600 upload_size_ = 0; 3622 upload_size_ = 0;
3601 upload_position_ = 0; 3623 upload_position_ = 0;
3602 } 3624 }
3603 3625
3604 GetRenderManager()->SetIsLoading(is_loading); 3626 GetRenderManager()->SetIsLoading(is_loading);
3605 3627
3606 is_loading_ = is_loading;
3607 waiting_for_response_ = is_loading; 3628 waiting_for_response_ = is_loading;
3608 is_load_to_different_document_ = to_different_document; 3629 is_load_to_different_document_ = to_different_document;
3609 3630
3610 if (delegate_) 3631 if (delegate_)
3611 delegate_->LoadingStateChanged(this, to_different_document); 3632 delegate_->LoadingStateChanged(this, to_different_document);
3612 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD); 3633 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
3613 3634
3614 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL"); 3635 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
3615 if (is_loading) { 3636 if (is_loading) {
3616 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading", 3637 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
3949 // renderer may not have made a clean exit. 3970 // renderer may not have made a clean exit.
3950 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget())) 3971 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
3951 ExitFullscreenMode(false); 3972 ExitFullscreenMode(false);
3952 3973
3953 // Cancel any visible dialogs so they are not left dangling over the sad tab. 3974 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3954 CancelActiveAndPendingDialogs(); 3975 CancelActiveAndPendingDialogs();
3955 3976
3956 if (delegate_) 3977 if (delegate_)
3957 delegate_->HideValidationMessage(this); 3978 delegate_->HideValidationMessage(this);
3958 3979
3959 SetIsLoading(false, true, nullptr);
3960 NotifyDisconnected();
3961 SetIsCrashed(status, error_code);
3962
3963 // Reset the loading progress. TODO(avi): What does it mean to have a 3980 // Reset the loading progress. TODO(avi): What does it mean to have a
3964 // "renderer crash" when there is more than one renderer process serving a 3981 // "renderer crash" when there is more than one renderer process serving a
3965 // webpage? Once this function is called at a more granular frame level, we 3982 // webpage? Once this function is called at a more granular frame level, we
3966 // probably will need to more granularly reset the state here. 3983 // probably will need to more granularly reset the state here.
3967 ResetLoadProgressState(); 3984 ResetLoadProgressState();
3985 NotifyDisconnected();
3986 SetIsCrashed(status, error_code);
3968 3987
3969 FOR_EACH_OBSERVER(WebContentsObserver, 3988 FOR_EACH_OBSERVER(WebContentsObserver,
3970 observers_, 3989 observers_,
3971 RenderProcessGone(GetCrashedStatus())); 3990 RenderProcessGone(GetCrashedStatus()));
3972 } 3991 }
3973 3992
3974 void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) { 3993 void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
3975 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh)); 3994 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
3976 } 3995 }
3977 3996
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
4051 delegate_->SwappedOut(this); 4070 delegate_->SwappedOut(this);
4052 } 4071 }
4053 4072
4054 void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) { 4073 void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
4055 if (delegate_ && delegate_->IsPopupOrPanel(this)) 4074 if (delegate_ && delegate_->IsPopupOrPanel(this))
4056 delegate_->MoveContents(this, new_bounds); 4075 delegate_->MoveContents(this, new_bounds);
4057 } 4076 }
4058 4077
4059 void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node, 4078 void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
4060 bool to_different_document) { 4079 bool to_different_document) {
4061 SetIsLoading(true, to_different_document, nullptr); 4080 LoadingStateChanged(true, to_different_document,
4081 paused_throbber_for_interstitial_, nullptr);
4062 4082
4063 // Notify accessibility that the user is navigating away from the 4083 // Notify accessibility that the user is navigating away from the
4064 // current document. 4084 // current document.
4065 // 4085 //
4066 // TODO(dmazzoni): do this using a WebContentsObserver. 4086 // TODO(dmazzoni): do this using a WebContentsObserver.
4067 BrowserAccessibilityManager* manager = 4087 BrowserAccessibilityManager* manager =
4068 frame_tree_node->current_frame_host()->browser_accessibility_manager(); 4088 frame_tree_node->current_frame_host()->browser_accessibility_manager();
4069 if (manager) 4089 if (manager)
4070 manager->UserIsNavigatingAway(); 4090 manager->UserIsNavigatingAway();
4071 } 4091 }
(...skipping 13 matching lines...) Expand all
4085 base::TimeTicks::Now() - navigator->GetCurrentLoadStart(); 4105 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
4086 4106
4087 details.reset(new LoadNotificationDetails( 4107 details.reset(new LoadNotificationDetails(
4088 entry->GetVirtualURL(), 4108 entry->GetVirtualURL(),
4089 entry->GetTransitionType(), 4109 entry->GetTransitionType(),
4090 elapsed, 4110 elapsed,
4091 &controller_, 4111 &controller_,
4092 controller_.GetCurrentEntryIndex())); 4112 controller_.GetCurrentEntryIndex()));
4093 } 4113 }
4094 4114
4095 SetIsLoading(false, true, details.get()); 4115 LoadingStateChanged(false, true, paused_throbber_for_interstitial_,
4116 details.get());
4096 } 4117 }
4097 4118
4098 void WebContentsImpl::DidChangeLoadProgress() { 4119 void WebContentsImpl::DidChangeLoadProgress() {
4099 double load_progress = frame_tree_.load_progress(); 4120 double load_progress = frame_tree_.load_progress();
4100 4121
4101 // The delegate is notified immediately for the first and last updates. Also, 4122 // The delegate is notified immediately for the first and last updates. Also,
4102 // since the message loop may be pretty busy when a page is loaded, it might 4123 // since the message loop may be pretty busy when a page is loaded, it might
4103 // not execute a posted task in a timely manner so the progress report is sent 4124 // not execute a posted task in a timely manner so the progress report is sent
4104 // immediately if enough time has passed. 4125 // immediately if enough time has passed.
4105 base::TimeDelta min_delay = 4126 base::TimeDelta min_delay =
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
4622 int render_frame_id, 4643 int render_frame_id,
4623 IPC::Message* reply_msg, 4644 IPC::Message* reply_msg,
4624 bool dialog_was_suppressed, 4645 bool dialog_was_suppressed,
4625 bool success, 4646 bool success,
4626 const base::string16& user_input) { 4647 const base::string16& user_input) {
4627 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id, 4648 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4628 render_frame_id); 4649 render_frame_id);
4629 last_dialog_suppressed_ = dialog_was_suppressed; 4650 last_dialog_suppressed_ = dialog_was_suppressed;
4630 4651
4631 if (is_showing_before_unload_dialog_ && !success) { 4652 if (is_showing_before_unload_dialog_ && !success) {
4632 // If a beforeunload dialog is canceled, we need to stop the throbber from
4633 // spinning, since we forced it to start spinning in Navigate.
4634 if (rfh) 4653 if (rfh)
4635 DidStopLoading(); 4654 rfh->frame_tree_node()->BeforeUnloadCanceled();
4636 controller_.DiscardNonCommittedEntries(); 4655 controller_.DiscardNonCommittedEntries();
4637 4656
4638 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 4657 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4639 BeforeUnloadDialogCancelled()); 4658 BeforeUnloadDialogCancelled());
4640 } 4659 }
4641 4660
4642 is_showing_before_unload_dialog_ = false; 4661 is_showing_before_unload_dialog_ = false;
4643 if (rfh) { 4662 if (rfh) {
4644 rfh->JavaScriptDialogClosed(reply_msg, success, user_input, 4663 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4645 dialog_was_suppressed); 4664 dialog_was_suppressed);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
4751 const WebContentsObserver::MediaPlayerId& id) { 4770 const WebContentsObserver::MediaPlayerId& id) {
4752 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id)); 4771 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id));
4753 } 4772 }
4754 4773
4755 void WebContentsImpl::MediaStoppedPlaying( 4774 void WebContentsImpl::MediaStoppedPlaying(
4756 const WebContentsObserver::MediaPlayerId& id) { 4775 const WebContentsObserver::MediaPlayerId& id) {
4757 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id)); 4776 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id));
4758 } 4777 }
4759 4778
4760 } // namespace content 4779 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | content/browser/web_contents/web_contents_impl_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698