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

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

Issue 934763003: Refactoring: de-couple Extensions from "script injection System" [render side]:3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@decouple_brower_isolated_world_routingid_user_script_1
Patch Set: Rebase. 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 "extensions/common/user_script.h" 10 #include "extensions/common/user_script.h"
11 #include "extensions/renderer/injection_host.h"
11 #include "extensions/renderer/script_injector.h" 12 #include "extensions/renderer/script_injector.h"
12 13
13 class InjectionHost;
14 struct HostID; 14 struct HostID;
15 15
16 namespace blink { 16 namespace blink {
17 class WebLocalFrame; 17 class WebLocalFrame;
18 } 18 }
19 19
20 namespace extensions { 20 namespace extensions {
21 struct ScriptsRunInfo; 21 struct ScriptsRunInfo;
22 22
23 // A script wrapper which is aware of whether or not it is allowed to execute, 23 // A script wrapper which is aware of whether or not it is allowed to execute,
24 // and contains the implementation to do so. 24 // and contains the implementation to do so.
25 class ScriptInjection { 25 class ScriptInjection {
26 public: 26 public:
27 // Return the id of the injection host associated with the given world. 27 // Return the id of the injection host associated with the given world.
28 static std::string GetHostIdForIsolatedWorld(int world_id); 28 static std::string GetHostIdForIsolatedWorld(int world_id);
29 29
30 // Remove the isolated world associated with the given injection host. 30 // Remove the isolated world associated with the given injection host.
31 static void RemoveIsolatedWorld(const std::string& host_id); 31 static void RemoveIsolatedWorld(const std::string& host_id);
32 32
33 ScriptInjection(scoped_ptr<ScriptInjector> injector, 33 ScriptInjection(scoped_ptr<ScriptInjector> injector,
34 blink::WebLocalFrame* web_frame, 34 blink::WebLocalFrame* web_frame,
35 const HostID& host_id, 35 scoped_ptr<const InjectionHost> injection_host,
36 UserScript::RunLocation run_location, 36 UserScript::RunLocation run_location,
37 int tab_id); 37 int tab_id);
38 ~ScriptInjection(); 38 ~ScriptInjection();
39 39
40 // Try to inject the script at the |current_location|. This returns true if 40 // Try to inject the script at the |current_location|. This returns true if
41 // the script has either injected or will never inject (i.e., if the object 41 // the script has either injected or will never inject (i.e., if the object
42 // is done), and false if injection is delayed (either for permission purposes 42 // is done), and false if injection is delayed (either for permission purposes
43 // or because |current_location| is not the designated |run_location_|). 43 // or because |current_location| is not the designated |run_location_|).
44 // NOTE: |injection_host| may be NULL, if the injection_host is removed!
45 bool TryToInject(UserScript::RunLocation current_location, 44 bool TryToInject(UserScript::RunLocation current_location,
46 const InjectionHost* injection_host,
47 ScriptsRunInfo* scripts_run_info); 45 ScriptsRunInfo* scripts_run_info);
48 46
49 // Called when permission for the given injection has been granted. 47 // Called when permission for the given injection has been granted.
50 // Returns true if the injection ran. 48 // Returns true if the injection ran.
51 bool OnPermissionGranted(const InjectionHost* injection_host, 49 bool OnPermissionGranted(ScriptsRunInfo* scripts_run_info);
52 ScriptsRunInfo* scripts_run_info); 50
51 // Resets the pointer of the injection host when the host is gone.
52 void OnHostRemoved();
53 53
54 // Accessors. 54 // Accessors.
55 blink::WebLocalFrame* web_frame() const { return web_frame_; } 55 blink::WebLocalFrame* web_frame() const { return web_frame_; }
56 const HostID& host_id() const { return host_id_; } 56 const HostID& host_id() const { return injection_host_->id(); }
57 int64 request_id() const { return request_id_; } 57 int64 request_id() const { return request_id_; }
58 58
59 private: 59 private:
60 // Sends a message to the browser, either that the script injection would 60 // 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. 61 // like to inject, or to notify the browser that it is currently injecting.
62 void SendInjectionMessage(bool request_permission); 62 void SendInjectionMessage(bool request_permission);
63 63
64 // Injects the script, optionally populating |scripts_run_info|. 64 // Injects the script, optionally populating |scripts_run_info|.
65 void Inject(const InjectionHost* injection_host, 65 void Inject(ScriptsRunInfo* scripts_run_info);
66 ScriptsRunInfo* scripts_run_info);
67 66
68 // Inject any JS scripts into the |frame|, optionally populating 67 // Inject any JS scripts into the |frame|, optionally populating
69 // |execution_results|. 68 // |execution_results|.
70 void InjectJs(const InjectionHost* injection_host, 69 void InjectJs(blink::WebLocalFrame* frame,
71 blink::WebLocalFrame* frame,
72 base::ListValue* execution_results); 70 base::ListValue* execution_results);
73 71
74 // Inject any CSS source into the |frame|. 72 // Inject any CSS source into the |frame|.
75 void InjectCss(blink::WebLocalFrame* frame); 73 void InjectCss(blink::WebLocalFrame* frame);
76 74
77 // Notify that we will not inject, and mark it as acknowledged. 75 // Notify that we will not inject, and mark it as acknowledged.
78 void NotifyWillNotInject(ScriptInjector::InjectFailureReason reason); 76 void NotifyWillNotInject(ScriptInjector::InjectFailureReason reason);
79 77
80 // The injector for this injection. 78 // The injector for this injection.
81 scoped_ptr<ScriptInjector> injector_; 79 scoped_ptr<ScriptInjector> injector_;
82 80
83 // The (main) WebFrame into which this should inject the script. 81 // The (main) WebFrame into which this should inject the script.
84 blink::WebLocalFrame* web_frame_; 82 blink::WebLocalFrame* web_frame_;
85 83
86 // The id of the associated injection_host. 84 // The associated injection host.
87 HostID host_id_; 85 scoped_ptr<const InjectionHost> injection_host_;
88 86
89 // The location in the document load at which we inject the script. 87 // The location in the document load at which we inject the script.
90 UserScript::RunLocation run_location_; 88 UserScript::RunLocation run_location_;
91 89
92 // The tab id associated with the frame. 90 // The tab id associated with the frame.
93 int tab_id_; 91 int tab_id_;
94 92
95 // This injection's request id. This will be -1 unless the injection is 93 // This injection's request id. This will be -1 unless the injection is
96 // currently waiting on permission. 94 // currently waiting on permission.
97 int64 request_id_; 95 int64 request_id_;
98 96
99 // Whether or not the injection is complete, either via injecting the script 97 // Whether or not the injection is complete, either via injecting the script
100 // or because it will never complete. 98 // or because it will never complete.
101 bool complete_; 99 bool complete_;
102 100
103 DISALLOW_COPY_AND_ASSIGN(ScriptInjection); 101 DISALLOW_COPY_AND_ASSIGN(ScriptInjection);
104 }; 102 };
105 103
106 } // namespace extensions 104 } // namespace extensions
107 105
108 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_ 106 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698