OLD | NEW |
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 #ifndef CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SCHEDULER_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SCHEDULER_H_ |
6 #define CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SCHEDULER_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SCHEDULER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <queue> | 9 #include <queue> |
10 | 10 |
11 #include "chrome/common/extensions/user_script.h" | 11 #include "chrome/common/extensions/user_script.h" |
12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 | 14 |
15 class ExtensionDispatcher; | |
16 class RenderView; | 15 class RenderView; |
17 struct ExtensionMsg_ExecuteCode_Params; | 16 struct ExtensionMsg_ExecuteCode_Params; |
18 | 17 |
19 namespace WebKit { | 18 namespace WebKit { |
20 class WebFrame; | 19 class WebFrame; |
21 } | 20 } |
22 | 21 |
23 namespace extensions { | 22 namespace extensions { |
| 23 class Dispatcher; |
24 | 24 |
25 // Implements support for injecting scripts at different times in the document | 25 // Implements support for injecting scripts at different times in the document |
26 // loading process. The different possible time are described in | 26 // loading process. The different possible time are described in |
27 // UserScript::RunLocation. | 27 // UserScript::RunLocation. |
28 // | 28 // |
29 // Currently, determining idleness is simple: it is whichever of the following | 29 // Currently, determining idleness is simple: it is whichever of the following |
30 // happens first: | 30 // happens first: |
31 // | 31 // |
32 // a) When the initial DOM for a page is complete + kUserScriptIdleTimeout, | 32 // a) When the initial DOM for a page is complete + kUserScriptIdleTimeout, |
33 // b) or when the page has completely loaded including all subresources. | 33 // b) or when the page has completely loaded including all subresources. |
34 // | 34 // |
35 // The intent of this mechanism is to prevent user scripts from slowing down | 35 // The intent of this mechanism is to prevent user scripts from slowing down |
36 // fast pages (run after load), while still allowing them to run relatively | 36 // fast pages (run after load), while still allowing them to run relatively |
37 // timely for pages with lots of slow subresources. | 37 // timely for pages with lots of slow subresources. |
38 // | 38 // |
39 // NOTE: this class does not inherit from RenderViewObserver on purpose. The | 39 // NOTE: this class does not inherit from RenderViewObserver on purpose. The |
40 // reason is that this object is per frame, and a frame can move across | 40 // reason is that this object is per frame, and a frame can move across |
41 // RenderViews thanks to adoptNode. So we have each RenderView's | 41 // RenderViews thanks to adoptNode. So we have each RenderView's |
42 // ExtensionHelper proxy these calls to the renderer process' | 42 // ExtensionHelper proxy these calls to the renderer process' Dispatcher, |
43 // ExtensionDispatcher, which contains the mapping from WebFrame to us. | 43 // which contains the mapping from WebFrame to us. |
44 class UserScriptScheduler { | 44 class UserScriptScheduler { |
45 public: | 45 public: |
46 UserScriptScheduler(WebKit::WebFrame* frame, | 46 UserScriptScheduler(WebKit::WebFrame* frame, Dispatcher* dispatcher); |
47 ExtensionDispatcher* extension_dispatcher); | |
48 ~UserScriptScheduler(); | 47 ~UserScriptScheduler(); |
49 | 48 |
50 void ExecuteCode(const ExtensionMsg_ExecuteCode_Params& params); | 49 void ExecuteCode(const ExtensionMsg_ExecuteCode_Params& params); |
51 void DidCreateDocumentElement(); | 50 void DidCreateDocumentElement(); |
52 void DidFinishDocumentLoad(); | 51 void DidFinishDocumentLoad(); |
53 void DidFinishLoad(); | 52 void DidFinishLoad(); |
54 void DidStartProvisionalLoad(); | 53 void DidStartProvisionalLoad(); |
55 | 54 |
56 private: | 55 private: |
57 typedef | 56 typedef |
(...skipping 23 matching lines...) Expand all Loading... |
81 // The current location in the document loading process. | 80 // The current location in the document loading process. |
82 // Will be UserScript::UNDEFINED if it is before any scripts should be run. | 81 // Will be UserScript::UNDEFINED if it is before any scripts should be run. |
83 UserScript::RunLocation current_location_; | 82 UserScript::RunLocation current_location_; |
84 | 83 |
85 // Whether we have already run the idle scripts. | 84 // Whether we have already run the idle scripts. |
86 bool has_run_idle_; | 85 bool has_run_idle_; |
87 | 86 |
88 // This is only used if we're for the main frame. | 87 // This is only used if we're for the main frame. |
89 std::map<UserScript::RunLocation, ExecutionQueue> pending_execution_map_; | 88 std::map<UserScript::RunLocation, ExecutionQueue> pending_execution_map_; |
90 | 89 |
91 ExtensionDispatcher* extension_dispatcher_; | 90 Dispatcher* dispatcher_; |
92 }; | 91 }; |
93 | 92 |
94 } // namespace extensions | 93 } // namespace extensions |
95 | 94 |
96 #endif // CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SCHEDULER_H_ | 95 #endif // CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SCHEDULER_H_ |
OLD | NEW |