OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_RENDERER_USER_SCRIPT_IDLE_SCHEDULER_H_ |
| 6 #define CHROME_RENDERER_USER_SCRIPT_IDLE_SCHEDULER_H_ |
| 7 |
| 8 #include "base/task.h" |
| 9 |
| 10 class RenderView; |
| 11 |
| 12 namespace WebKit { |
| 13 class WebFrame; |
| 14 } |
| 15 |
| 16 // Implements support for injecting scripts at "document idle". Currently, |
| 17 // determining idleness is simple: it is whichever of the following happens |
| 18 // first: |
| 19 // |
| 20 // a) When the initial DOM for a page is complete + kUserScriptIdleTimeout, |
| 21 // b) or when the page has completely loaded including all subresources. |
| 22 // |
| 23 // The intent of this mechanism is to prevent user scripts from slowing down |
| 24 // fast pages (run after load), while still allowing them to run relatively |
| 25 // timelily for pages with lots of slow subresources. |
| 26 class UserScriptIdleScheduler { |
| 27 public: |
| 28 UserScriptIdleScheduler(RenderView* view, WebKit::WebFrame* frame); |
| 29 |
| 30 bool has_run() { return has_run_; } |
| 31 |
| 32 // Called when the DOM has been completely constructed. |
| 33 void DidFinishDocumentLoad(); |
| 34 |
| 35 // Called when the document has completed loading. |
| 36 void DidFinishLoad(); |
| 37 |
| 38 // Called when the client has gone away and we should no longer run scripts. |
| 39 void Cancel(); |
| 40 |
| 41 private: |
| 42 // Run user scripts, except if they've already run for this frame, or the |
| 43 // frame has been destroyed. |
| 44 void MaybeRun(); |
| 45 |
| 46 // The RenderView we will call back to when it is time to run scripts. |
| 47 RenderView* view_; |
| 48 |
| 49 // The Frame we will run scripts in. |
| 50 WebKit::WebFrame* frame_; |
| 51 |
| 52 // Whether we have already run scripts. |
| 53 bool has_run_; |
| 54 |
| 55 ScopedRunnableMethodFactory<UserScriptIdleScheduler> method_factory_; |
| 56 }; |
| 57 |
| 58 #endif // CHROME_RENDERER_USER_SCRIPT_IDLE_SCHEDULER_H_ |
OLD | NEW |