OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_IDLE_SCHEDULER_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_IDLE_SCHEDULER_H_ |
6 #define CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_IDLE_SCHEDULER_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_IDLE_SCHEDULER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <queue> | 9 #include <queue> |
10 #include <vector> | 10 #include <vector> |
(...skipping 18 matching lines...) Expand all Loading... | |
29 // | 29 // |
30 // The intent of this mechanism is to prevent user scripts from slowing down | 30 // The intent of this mechanism is to prevent user scripts from slowing down |
31 // fast pages (run after load), while still allowing them to run relatively | 31 // fast pages (run after load), while still allowing them to run relatively |
32 // timely for pages with lots of slow subresources. | 32 // timely for pages with lots of slow subresources. |
33 // | 33 // |
34 // NOTE: this class does not inherit from RenderViewObserver on purpose. The | 34 // NOTE: this class does not inherit from RenderViewObserver on purpose. The |
35 // reason is that this object is per frame, and a frame can move across | 35 // reason is that this object is per frame, and a frame can move across |
36 // RenderViews thanks to adoptNode. So we have each RenderView's | 36 // RenderViews thanks to adoptNode. So we have each RenderView's |
37 // ExtensionHelper proxy these calls to the renderer process' | 37 // ExtensionHelper proxy these calls to the renderer process' |
38 // ExtensionDispatcher, which contains the mapping from WebFrame to us. | 38 // ExtensionDispatcher, which contains the mapping from WebFrame to us. |
39 class UserScriptIdleScheduler { | 39 class UserScriptIdleScheduler { |
Aaron Boodman
2012/03/03 00:59:10
Can you change the name of this class and rename t
eaugusti
2012/03/27 00:43:34
Done.
| |
40 public: | 40 public: |
41 typedef | |
Mihai Parparita -not on Chrome
2012/03/01 00:40:08
This typedef should be private.
eaugusti
2012/03/27 00:43:34
Done.
| |
42 std::vector<std::queue<linked_ptr<ExtensionMsg_ExecuteCode_Params> > > | |
Mihai Parparita -not on Chrome
2012/03/01 00:40:08
Why not make this a map from RunLocation to the qu
eaugusti
2012/03/27 00:43:34
Done.
| |
43 Schedule; | |
44 | |
41 UserScriptIdleScheduler(WebKit::WebFrame* frame, | 45 UserScriptIdleScheduler(WebKit::WebFrame* frame, |
42 ExtensionDispatcher* extension_dispatcher); | 46 ExtensionDispatcher* extension_dispatcher); |
43 ~UserScriptIdleScheduler(); | 47 ~UserScriptIdleScheduler(); |
44 | 48 |
45 void ExecuteCode(const ExtensionMsg_ExecuteCode_Params& params); | 49 void ExecuteCode(const ExtensionMsg_ExecuteCode_Params& params); |
50 void DidCreateDocumentElement(); | |
46 void DidFinishDocumentLoad(); | 51 void DidFinishDocumentLoad(); |
47 void DidFinishLoad(); | 52 void DidFinishLoad(); |
48 void DidStartProvisionalLoad(); | 53 void DidStartProvisionalLoad(); |
49 | 54 |
50 private: | 55 private: |
51 // Run user scripts, except if they've already run for this frame, or the | 56 // Run user scripts, except if they've already run for this frame, or the |
52 // frame has been destroyed. | 57 // frame has been destroyed. |
53 void MaybeRun(); | 58 void MaybeRun(); |
54 | 59 |
55 // Backend for the IPC Message ExecuteCode in addition to being used | 60 // Backend for the IPC Message ExecuteCode in addition to being used |
56 // internally. | 61 // internally. |
57 void ExecuteCodeImpl(const ExtensionMsg_ExecuteCode_Params& params); | 62 void ExecuteCodeImpl(const ExtensionMsg_ExecuteCode_Params& params); |
58 | 63 |
59 // Get all child frames of parent_frame, returned by frames_vector. | 64 // Get all child frames of parent_frame, returned by frames_vector. |
60 bool GetAllChildFrames(WebKit::WebFrame* parent_frame, | 65 bool GetAllChildFrames(WebKit::WebFrame* parent_frame, |
61 std::vector<WebKit::WebFrame*>* frames_vector) const; | 66 std::vector<WebKit::WebFrame*>* frames_vector) const; |
62 | 67 |
68 // Call to signify thet the idle timeout has expired. | |
69 void IdleTimeout(); | |
70 | |
63 base::WeakPtrFactory<UserScriptIdleScheduler> weak_factory_; | 71 base::WeakPtrFactory<UserScriptIdleScheduler> weak_factory_; |
64 | 72 |
65 // The Frame we will run scripts in. | 73 // The Frame we will run scripts in. |
66 WebKit::WebFrame* frame_; | 74 WebKit::WebFrame* frame_; |
67 | 75 |
68 // Whether we have already run scripts. | 76 // Whether we have already run scripts. |
69 bool has_run_; | 77 bool has_run_; |
70 | 78 |
79 // The current location in the document lodaing process. | |
Mihai Parparita -not on Chrome
2012/03/01 00:40:08
Typo ("lodaing").
eaugusti
2012/03/27 00:43:34
Done.
| |
80 // Will be -1 if it is before any scripts should be run. | |
81 // Otherwise it will be one of UserScript::RunLocation | |
82 int current_location_; | |
83 | |
71 // This is only used if we're for the main frame. | 84 // This is only used if we're for the main frame. |
72 std::queue<linked_ptr<ExtensionMsg_ExecuteCode_Params> > | 85 Schedule pending_code_execution_queue_; |
73 pending_code_execution_queue_; | |
74 | 86 |
75 ExtensionDispatcher* extension_dispatcher_; | 87 ExtensionDispatcher* extension_dispatcher_; |
76 }; | 88 }; |
77 | 89 |
78 #endif // CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_IDLE_SCHEDULER_H_ | 90 #endif // CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_IDLE_SCHEDULER_H_ |
OLD | NEW |