diff options
author | jcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-15 17:14:24 +0000 |
---|---|---|
committer | jcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-15 17:14:24 +0000 |
commit | 9010941b17ea056d5dd8e28707262fa91d36b000 (patch) | |
tree | 5a8e1fa84a141794908c9d8dcbe1fa1aa699584a | |
parent | 8627eab5446ced705605ea0c2084ee4c8adcbc65 (diff) | |
download | chromium_src-9010941b17ea056d5dd8e28707262fa91d36b000.zip chromium_src-9010941b17ea056d5dd8e28707262fa91d36b000.tar.gz chromium_src-9010941b17ea056d5dd8e28707262fa91d36b000.tar.bz2 |
Plumbing load progress notifications to the browser.
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/4694006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69272 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.cc | 6 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.h | 1 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host_delegate.h | 5 | ||||
-rw-r--r-- | chrome/chrome_renderer.gypi | 2 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 4 | ||||
-rw-r--r-- | chrome/renderer/load_progress_tracker.cc | 85 | ||||
-rw-r--r-- | chrome/renderer/load_progress_tracker.h | 46 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 9 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 9 |
9 files changed, 167 insertions, 0 deletions
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 470b8ba..95844a3 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -776,6 +776,8 @@ void RenderViewHost::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnMsgRequestMove) IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartLoading, OnMsgDidStartLoading) IPC_MESSAGE_HANDLER(ViewHostMsg_DidStopLoading, OnMsgDidStopLoading) + IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeLoadProgress, + OnMsgDidChangeLoadProgress) IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentAvailableInMainFrame, OnMsgDocumentAvailableInMainFrame) IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentOnLoadCompletedInMainFrame, @@ -1162,6 +1164,10 @@ void RenderViewHost::OnMsgDidStopLoading() { delegate_->DidStopLoading(); } +void RenderViewHost::OnMsgDidChangeLoadProgress(double load_progress) { + delegate_->DidChangeLoadProgress(load_progress); +} + void RenderViewHost::OnMsgDocumentAvailableInMainFrame() { delegate_->DocumentAvailableInMainFrame(this); } diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index 81223ea..3004410 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -573,6 +573,7 @@ class RenderViewHost : public RenderWidgetHost { const GURL& target_url); void OnMsgDidStartLoading(); void OnMsgDidStopLoading(); + void OnMsgDidChangeLoadProgress(double load_progress); void OnMsgDocumentAvailableInMainFrame(); void OnMsgDocumentOnLoadCompletedInMainFrame(int32 page_id); void OnMsgDidLoadResourceFromMemoryCache(const GURL& url, diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h index 043000ab..10d4e04 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.h +++ b/chrome/browser/renderer_host/render_view_host_delegate.h @@ -769,6 +769,11 @@ class RenderViewHostDelegate { // notion of the throbber stopping. virtual void DidStopLoading() {} + // The RenderView made progress loading a page's top frame. + // |progress_load| is a value between 0 (nothing loaded) to 1.0 (top frame + // entirely loaded). + virtual void DidChangeLoadProgress(double load_progress) {} + // The RenderView's main frame document element is ready. This happens when // the document has finished parsing. virtual void DocumentAvailableInMainFrame(RenderViewHost* render_view_host) {} diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi index 2a69cd7..dc253b7 100644 --- a/chrome/chrome_renderer.gypi +++ b/chrome/chrome_renderer.gypi @@ -126,6 +126,8 @@ 'renderer/indexed_db_dispatcher.h', 'renderer/localized_error.cc', 'renderer/localized_error.h', + 'renderer/load_progress_tracker.cc', + 'renderer/load_progress_tracker.h', 'renderer/navigation_state.cc', 'renderer/navigation_state.h', 'renderer/notification_provider.cc', diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 2479c5a..63ec314 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -1203,6 +1203,10 @@ IPC_MESSAGE_ROUTED0(ViewHostMsg_DidStartLoading) // notion of the throbber stopping. IPC_MESSAGE_ROUTED0(ViewHostMsg_DidStopLoading) +// Sent when the renderer main frame has made progress loading. +IPC_MESSAGE_ROUTED1(ViewHostMsg_DidChangeLoadProgress, + double /* load_progress */) + // Sent when the document element is available for the toplevel frame. This // happens after the page starts loading, but before all resources are // finished. diff --git a/chrome/renderer/load_progress_tracker.cc b/chrome/renderer/load_progress_tracker.cc new file mode 100644 index 0000000..0ebba4b --- /dev/null +++ b/chrome/renderer/load_progress_tracker.cc @@ -0,0 +1,85 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/renderer/load_progress_tracker.h" + +#include "base/message_loop.h" +#include "chrome/renderer/render_view.h" + +namespace { + +const int kMinimumDelayBetweenUpdatesMS = 100; + +} + +LoadProgressTracker::LoadProgressTracker(RenderView* render_view) + : render_view_(render_view), + tracked_frame_(NULL), + progress_(0.0), + ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { +} + +LoadProgressTracker::~LoadProgressTracker() { +} + +void LoadProgressTracker::DidStopLoading() { + if (!tracked_frame_) + return; + + // Load stoped while we were still tracking load. Make sure we notify the + // browser that load is complete. + progress_ = 1.0; + SendChangeLoadProgress(); + // Then we clean-up our states. + ResetStates(); +} + +void LoadProgressTracker::DidChangeLoadProgress(WebKit::WebFrame* frame, + double progress) { + if (tracked_frame_ && frame != tracked_frame_) + return; + + if (!tracked_frame_) + tracked_frame_ = frame; + + progress_ = progress; + + // We send the progress change to the browser immediately for the first and + // last updates. Also, since the message loop may be pretty busy when a page + // is loaded, it might not execute a posted task in a timely manner so we make + // sure to immediately send progress report if enough time has passed. + if (progress == 1.0 || last_time_progress_sent_.is_null() || + (base::TimeTicks::Now() - last_time_progress_sent_).InMilliseconds() > + kMinimumDelayBetweenUpdatesMS) { + // If there is a pending task to send progress, it is now obsolete. + method_factory_.RevokeAll(); + SendChangeLoadProgress(); + if (progress == 1.0) + ResetStates(); + return; + } + + if (!method_factory_.empty()) + return; + + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + method_factory_.NewRunnableMethod( + &LoadProgressTracker::SendChangeLoadProgress), + kMinimumDelayBetweenUpdatesMS); +} + +void LoadProgressTracker::SendChangeLoadProgress() { + last_time_progress_sent_ = base::TimeTicks::Now(); + render_view_->Send( + new ViewHostMsg_DidChangeLoadProgress(render_view_->routing_id(), + progress_)); +} + +void LoadProgressTracker::ResetStates() { + tracked_frame_ = NULL; + progress_ = 0.0; + method_factory_.RevokeAll(); + last_time_progress_sent_ = base::TimeTicks(); +} diff --git a/chrome/renderer/load_progress_tracker.h b/chrome/renderer/load_progress_tracker.h new file mode 100644 index 0000000..a9455c3 --- /dev/null +++ b/chrome/renderer/load_progress_tracker.h @@ -0,0 +1,46 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_RENDERER_LOAD_PROGRESS_TRACKER_H_ +#define CHROME_RENDERER_LOAD_PROGRESS_TRACKER_H_ + +#include "base/logging.h" +#include "base/task.h" +#include "base/time.h" + +class RenderView; + +namespace WebKit { +class WebFrame; +} + +class LoadProgressTracker { + public: + explicit LoadProgressTracker(RenderView* render_view); + ~LoadProgressTracker(); + + void DidStopLoading(); + + void DidChangeLoadProgress(WebKit::WebFrame* frame, double progress); + + private: + void ResetStates(); + + void SendChangeLoadProgress(); + + RenderView* render_view_; + + WebKit::WebFrame* tracked_frame_; + + double progress_; + + base::TimeTicks last_time_progress_sent_; + + ScopedRunnableMethodFactory<LoadProgressTracker> method_factory_; + + DISALLOW_COPY_AND_ASSIGN(LoadProgressTracker); +}; + +#endif // CHROME_RENDERER_LOAD_PROGRESS_TRACKER_H_ + diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index ca0c0e5..b7240f5 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -69,6 +69,7 @@ #include "chrome/renderer/geolocation_dispatcher_old.h" #endif #include "chrome/renderer/ggl/ggl.h" +#include "chrome/renderer/load_progress_tracker.h" #include "chrome/renderer/localized_error.h" #include "chrome/renderer/media/audio_renderer_impl.h" #include "chrome/renderer/media/ipc_video_decoder.h" @@ -2200,6 +2201,9 @@ void RenderView::didStopLoading() { Send(new ViewHostMsg_DidStopLoading(routing_id_)); + if (load_progress_tracker_ != NULL) + load_progress_tracker_->DidStopLoading(); + MessageLoop::current()->PostDelayedTask( FROM_HERE, page_info_method_factory_.NewRunnableMethod( @@ -2207,6 +2211,11 @@ void RenderView::didStopLoading() { send_content_state_immediately_ ? 0 : kDelayForCaptureMs); } +void RenderView::didChangeLoadProgress(WebFrame* frame, double load_progress) { + if (load_progress_tracker_ != NULL) + load_progress_tracker_->DidChangeLoadProgress(frame, load_progress); +} + bool RenderView::isSmartInsertDeleteEnabled() { #if defined(OS_MACOSX) return true; diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 8b0fb5b..3d73c7c 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -68,6 +68,7 @@ class GeolocationDispatcher; class GeolocationDispatcherOld; class GURL; class ListValue; +class LoadProgressTracker; class NavigationState; class NotificationProvider; class PageClickTracker; @@ -296,6 +297,9 @@ class RenderView : public RenderWidget, bool InstallWebApplicationUsingDefinitionFile(WebKit::WebFrame* frame, string16* error); + // Sets whether the renderer should report load progress to the browser. + void SetReportLoadProgressEnabled(bool enabled); + // Extensions ---------------------------------------------------------------- void SendExtensionRequest(const ViewHostMsg_DomMessage_Params& params); @@ -412,6 +416,8 @@ class RenderView : public RenderWidget, virtual WebKit::WebNotificationPresenter* notificationPresenter(); virtual void didStartLoading(); virtual void didStopLoading(); + virtual void didChangeLoadProgress(WebKit::WebFrame* frame, + double load_progress); virtual bool isSmartInsertDeleteEnabled(); virtual bool isSelectTrailingWhitespaceEnabled(); virtual void didChangeSelection(bool is_selection_empty); @@ -1486,6 +1492,9 @@ class RenderView : public RenderWidget, // The custom menu event listener, if any. CustomMenuListener* custom_menu_listener_; + // Reports load progress to the browser. + scoped_ptr<LoadProgressTracker> load_progress_tracker_; + // --------------------------------------------------------------------------- // ADDING NEW DATA? Please see if it fits appropriately in one of the above // sections rather than throwing it randomly at the end. If you're adding a |