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

Side by Side Diff: chrome/renderer/extensions/user_script_idle_scheduler.h

Issue 9456037: Adding run_at to chrome.tabs.executeScript/insertCss. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_IDLE_SCHEDULER_H_
6 #define CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_IDLE_SCHEDULER_H_
7 #pragma once
8
9 #include <queue>
10 #include <vector>
11
12 #include "base/memory/linked_ptr.h"
13 #include "base/memory/weak_ptr.h"
14
15 class ExtensionDispatcher;
16 class RenderView;
17 struct ExtensionMsg_ExecuteCode_Params;
18
19 namespace WebKit {
20 class WebFrame;
21 }
22
23 // Implements support for injecting scripts at "document idle". Currently,
24 // determining idleness is simple: it is whichever of the following happens
25 // first:
26 //
27 // a) When the initial DOM for a page is complete + kUserScriptIdleTimeout,
28 // b) or when the page has completely loaded including all subresources.
29 //
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
32 // timely for pages with lots of slow subresources.
33 //
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
36 // RenderViews thanks to adoptNode. So we have each RenderView's
37 // ExtensionHelper proxy these calls to the renderer process'
38 // ExtensionDispatcher, which contains the mapping from WebFrame to us.
39 class UserScriptIdleScheduler {
40 public:
41 UserScriptIdleScheduler(WebKit::WebFrame* frame,
42 ExtensionDispatcher* extension_dispatcher);
43 ~UserScriptIdleScheduler();
44
45 void ExecuteCode(const ExtensionMsg_ExecuteCode_Params& params);
46 void DidFinishDocumentLoad();
47 void DidFinishLoad();
48 void DidStartProvisionalLoad();
49
50 private:
51 // Run user scripts, except if they've already run for this frame, or the
52 // frame has been destroyed.
53 void MaybeRun();
54
55 // Backend for the IPC Message ExecuteCode in addition to being used
56 // internally.
57 void ExecuteCodeImpl(const ExtensionMsg_ExecuteCode_Params& params);
58
59 // Get all child frames of parent_frame, returned by frames_vector.
60 bool GetAllChildFrames(WebKit::WebFrame* parent_frame,
61 std::vector<WebKit::WebFrame*>* frames_vector) const;
62
63 base::WeakPtrFactory<UserScriptIdleScheduler> weak_factory_;
64
65 // The Frame we will run scripts in.
66 WebKit::WebFrame* frame_;
67
68 // Whether we have already run scripts.
69 bool has_run_;
70
71 // This is only used if we're for the main frame.
72 std::queue<linked_ptr<ExtensionMsg_ExecuteCode_Params> >
73 pending_code_execution_queue_;
74
75 ExtensionDispatcher* extension_dispatcher_;
76 };
77
78 #endif // CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_IDLE_SCHEDULER_H_
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/extension_helper.cc ('k') | chrome/renderer/extensions/user_script_idle_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698