ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / extensions / renderer / script_injection.h
bloba8835457d95312b220ded68cba089261eb05e745
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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_
6 #define EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_
8 #include "base/basictypes.h"
9 #include "base/macros.h"
10 #include "extensions/common/user_script.h"
11 #include "extensions/renderer/script_injector.h"
13 class InjectionHost;
14 struct HostID;
16 namespace blink {
17 class WebLocalFrame;
20 namespace extensions {
21 struct ScriptsRunInfo;
23 // A script wrapper which is aware of whether or not it is allowed to execute,
24 // and contains the implementation to do so.
25 class ScriptInjection {
26 public:
27 // Return the id of the injection host associated with the given world.
28 static std::string GetHostIdForIsolatedWorld(int world_id);
30 // Remove the isolated world associated with the given injection host.
31 static void RemoveIsolatedWorld(const std::string& host_id);
33 ScriptInjection(scoped_ptr<ScriptInjector> injector,
34 blink::WebLocalFrame* web_frame,
35 const HostID& host_id,
36 UserScript::RunLocation run_location,
37 int tab_id);
38 ~ScriptInjection();
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
42 // is done), and false if injection is delayed (either for permission purposes
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,
46 const InjectionHost* injection_host,
47 ScriptsRunInfo* scripts_run_info);
49 // Called when permission for the given injection has been granted.
50 // Returns true if the injection ran.
51 bool OnPermissionGranted(const InjectionHost* injection_host,
52 ScriptsRunInfo* scripts_run_info);
54 // Accessors.
55 blink::WebLocalFrame* web_frame() const { return web_frame_; }
56 const HostID& host_id() const { return host_id_; }
57 int64 request_id() const { return request_id_; }
59 private:
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.
62 void SendInjectionMessage(bool request_permission);
64 // Injects the script, optionally populating |scripts_run_info|.
65 void Inject(const InjectionHost* injection_host,
66 ScriptsRunInfo* scripts_run_info);
68 // Inject any JS scripts into the |frame|, optionally populating
69 // |execution_results|.
70 void InjectJs(const InjectionHost* injection_host,
71 blink::WebLocalFrame* frame,
72 base::ListValue* execution_results);
74 // Inject any CSS source into the |frame|.
75 void InjectCss(blink::WebLocalFrame* frame);
77 // Notify that we will not inject, and mark it as acknowledged.
78 void NotifyWillNotInject(ScriptInjector::InjectFailureReason reason);
80 // The injector for this injection.
81 scoped_ptr<ScriptInjector> injector_;
83 // The (main) WebFrame into which this should inject the script.
84 blink::WebLocalFrame* web_frame_;
86 // The id of the associated injection_host.
87 HostID host_id_;
89 // The location in the document load at which we inject the script.
90 UserScript::RunLocation run_location_;
92 // The tab id associated with the frame.
93 int tab_id_;
95 // This injection's request id. This will be -1 unless the injection is
96 // currently waiting on permission.
97 int64 request_id_;
99 // Whether or not the injection is complete, either via injecting the script
100 // or because it will never complete.
101 bool complete_;
103 DISALLOW_COPY_AND_ASSIGN(ScriptInjection);
106 } // namespace extensions
108 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_