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

Side by Side Diff: extensions/renderer/script_injection.h

Issue 878513005: Extensions: suspend extension's scripts when V8 is paused (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_ 5 #ifndef EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_
6 #define EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_ 6 #define EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
10 #include "extensions/common/user_script.h" 11 #include "extensions/common/user_script.h"
11 #include "extensions/renderer/script_injector.h" 12 #include "extensions/renderer/script_injector.h"
12 13
13 class InjectionHost; 14 class InjectionHost;
14 struct HostID; 15 struct HostID;
15 16
16 namespace blink { 17 namespace blink {
17 class WebLocalFrame; 18 class WebLocalFrame;
19 template<typename T> class WebVector;
20 }
21
22 namespace v8 {
23 class Value;
24 template <class T> class Local;
18 } 25 }
19 26
20 namespace extensions { 27 namespace extensions {
28 class ScriptInjectionManager;
21 struct ScriptsRunInfo; 29 struct ScriptsRunInfo;
22 30
23 // A script wrapper which is aware of whether or not it is allowed to execute, 31 // A script wrapper which is aware of whether or not it is allowed to execute,
24 // and contains the implementation to do so. 32 // and contains the implementation to do so.
25 class ScriptInjection { 33 class ScriptInjection {
26 public: 34 public:
35 enum InjectionResult {
36 INJECTION_FINISHED,
37 INJECTION_BLOCKED,
38 INJECTION_WAITING
39 };
40
27 // Return the id of the injection host associated with the given world. 41 // Return the id of the injection host associated with the given world.
28 static std::string GetHostIdForIsolatedWorld(int world_id); 42 static std::string GetHostIdForIsolatedWorld(int world_id);
29 43
30 // Remove the isolated world associated with the given injection host. 44 // Remove the isolated world associated with the given injection host.
31 static void RemoveIsolatedWorld(const std::string& host_id); 45 static void RemoveIsolatedWorld(const std::string& host_id);
32 46
33 ScriptInjection(scoped_ptr<ScriptInjector> injector, 47 ScriptInjection(scoped_ptr<ScriptInjector> injector,
34 blink::WebLocalFrame* web_frame, 48 blink::WebLocalFrame* web_frame,
35 const HostID& host_id, 49 const HostID& host_id,
36 UserScript::RunLocation run_location, 50 UserScript::RunLocation run_location,
37 int tab_id); 51 int tab_id);
38 ~ScriptInjection(); 52 ~ScriptInjection();
39 53
40 // Try to inject the script at the |current_location|. This returns true if 54 // Try to inject the script at the |current_location|. This returns
41 // the script has either injected or will never inject (i.e., if the object 55 // INJECTION_FINISHED if injection has injected or will never inject, returns
42 // is done), and false if injection is delayed (either for permission purposes 56 // INJECTION_BLOCKED if injection is running asynchronously and has not
43 // or because |current_location| is not the designated |run_location_|). 57 // finished yet, returns INJECTION_WAITING if injections is delayed (either
58 // for permission purposes or because |current_location| is not the designated
59 // |run_location_|).
44 // NOTE: |injection_host| may be NULL, if the injection_host is removed! 60 // NOTE: |injection_host| may be NULL, if the injection_host is removed!
45 bool TryToInject(UserScript::RunLocation current_location, 61 InjectionResult TryToInject(UserScript::RunLocation current_location,
46 const InjectionHost* injection_host, 62 const InjectionHost* injection_host,
47 ScriptsRunInfo* scripts_run_info); 63 ScriptsRunInfo* scripts_run_info);
48 64
49 // Called when permission for the given injection has been granted. 65 // Called when permission for the given injection has been granted.
50 // Returns true if the injection ran. 66 // Returns INJECTION_FINISHED if injection has injected or will never inject,
51 bool OnPermissionGranted(const InjectionHost* injection_host, 67 // returns INJECTION_BLOCKED if injection is runned asynchronously
52 ScriptsRunInfo* scripts_run_info); 68 InjectionResult OnPermissionGranted(const InjectionHost* injection_host,
69 ScriptsRunInfo* scripts_run_info);
70
71 // Called when JS injection for the given frame has been completed.
72 void OnJSInjectionCompleted(blink::WebLocalFrame* frame,
73 const blink::WebVector<v8::Local<v8::Value> >&);
53 74
54 // Accessors. 75 // Accessors.
55 blink::WebLocalFrame* web_frame() const { return web_frame_; } 76 blink::WebLocalFrame* web_frame() const { return web_frame_; }
56 const HostID& host_id() const { return host_id_; } 77 const HostID& host_id() const { return host_id_; }
57 int64 request_id() const { return request_id_; } 78 int64 request_id() const { return request_id_; }
58 79
80 void SetScriptInjectionManager(ScriptInjectionManager* manager);
Devlin 2015/03/03 00:34:10 Instead, let's just pass in the ScriptInjectionMan
kozy 2015/03/03 13:50:19 Done.
81
59 private: 82 private:
60 // Sends a message to the browser, either that the script injection would 83 // Sends a message to the browser, either that the script injection would
61 // like to inject, or to notify the browser that it is currently injecting. 84 // like to inject, or to notify the browser that it is currently injecting.
62 void SendInjectionMessage(bool request_permission); 85 void SendInjectionMessage(bool request_permission);
63 86
64 // Injects the script, optionally populating |scripts_run_info|. 87 // Injects the script. Returns INJECTION_FINISHED if injection has finished,
65 void Inject(const InjectionHost* injection_host, 88 // otherwise INJECTION_BLOCKED.
66 ScriptsRunInfo* scripts_run_info); 89 InjectionResult Inject(const InjectionHost* injection_host,
90 ScriptsRunInfo* scripts_run_info);
67 91
68 // Inject any JS scripts into the |frame|, optionally populating 92 // Inject any JS scripts into the |frame|, optionally populating
69 // |execution_results|. 93 // |execution_results|.
70 void InjectJs(const InjectionHost* injection_host, 94 void InjectJs(const InjectionHost* injection_host,
71 blink::WebLocalFrame* frame, 95 blink::WebLocalFrame* frame);
72 base::ListValue* execution_results); 96
97 // Checks if all scripts have been injected and finished.
98 void TryToFinish();
73 99
74 // Inject any CSS source into the |frame|. 100 // Inject any CSS source into the |frame|.
75 void InjectCss(blink::WebLocalFrame* frame); 101 void InjectCss(blink::WebLocalFrame* frame);
76 102
77 // Notify that we will not inject, and mark it as acknowledged. 103 // Notify that we will not inject, and mark it as acknowledged.
78 void NotifyWillNotInject(ScriptInjector::InjectFailureReason reason); 104 void NotifyWillNotInject(ScriptInjector::InjectFailureReason reason);
79 105
80 // The injector for this injection. 106 // The injector for this injection.
81 scoped_ptr<ScriptInjector> injector_; 107 scoped_ptr<ScriptInjector> injector_;
82 108
(...skipping 10 matching lines...) Expand all
93 int tab_id_; 119 int tab_id_;
94 120
95 // This injection's request id. This will be -1 unless the injection is 121 // This injection's request id. This will be -1 unless the injection is
96 // currently waiting on permission. 122 // currently waiting on permission.
97 int64 request_id_; 123 int64 request_id_;
98 124
99 // Whether or not the injection is complete, either via injecting the script 125 // Whether or not the injection is complete, either via injecting the script
100 // or because it will never complete. 126 // or because it will never complete.
101 bool complete_; 127 bool complete_;
102 128
129 // Number of frames in which the injection is running
130 int running_frames_;
131
132 // Results storage
133 scoped_ptr<base::ListValue> execution_results_;
134
135 // Flag is true when injections for each frame started
Devlin 2015/03/03 00:34:10 nit: comments need to end in a period.
kozy 2015/03/03 13:50:19 Done.
136 bool all_injection_started_;
Devlin 2015/03/03 00:34:10 nit: all_injections_started_ (plural)
kozy 2015/03/03 13:50:20 Done.
137
138 // ScriptInjectionManager::OnInjectionFinished will be called after injection
139 // finished.
140 ScriptInjectionManager* script_injection_manager_;
141
103 DISALLOW_COPY_AND_ASSIGN(ScriptInjection); 142 DISALLOW_COPY_AND_ASSIGN(ScriptInjection);
104 }; 143 };
105 144
106 } // namespace extensions 145 } // namespace extensions
107 146
108 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_ 147 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698