OLD | NEW |
---|---|
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_USER_SCRIPT_INJECTOR_H_ | 5 #ifndef EXTENSIONS_RENDERER_USER_SCRIPT_INJECTOR_H_ |
6 #define EXTENSIONS_RENDERER_USER_SCRIPT_INJECTOR_H_ | 6 #define EXTENSIONS_RENDERER_USER_SCRIPT_INJECTOR_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/scoped_observer.h" | 12 #include "base/scoped_observer.h" |
13 #include "extensions/common/user_script.h" | 13 #include "extensions/common/user_script.h" |
14 #include "extensions/renderer/script_injection.h" | 14 #include "extensions/renderer/script_injection.h" |
15 #include "extensions/renderer/user_script_set.h" | 15 #include "extensions/renderer/user_script_set.h" |
16 | 16 |
17 class InjectionHost; | 17 class InjectionHost; |
18 | 18 |
19 namespace blink { | 19 namespace blink { |
20 class WebLocalFrame; | 20 class WebLocalFrame; |
21 } | 21 } |
22 | 22 |
23 namespace extensions { | 23 namespace extensions { |
24 struct ScriptsRunInfo; | |
Devlin
2016/09/08 17:47:32
not needed
| |
24 | 25 |
25 // A ScriptInjector for UserScripts. | 26 // A ScriptInjector for UserScripts. |
26 class UserScriptInjector : public ScriptInjector, | 27 class UserScriptInjector : public ScriptInjector, |
27 public UserScriptSet::Observer { | 28 public UserScriptSet::Observer { |
28 public: | 29 public: |
29 UserScriptInjector(const UserScript* user_script, | 30 UserScriptInjector(const UserScript* user_script, |
30 UserScriptSet* user_script_set, | 31 UserScriptSet* user_script_set, |
31 bool is_declarative); | 32 bool is_declarative); |
32 ~UserScriptInjector() override; | 33 ~UserScriptInjector() override; |
33 | 34 |
34 private: | 35 private: |
35 // UserScriptSet::Observer implementation. | 36 // UserScriptSet::Observer implementation. |
36 void OnUserScriptsUpdated(const std::set<HostID>& changed_hosts, | 37 void OnUserScriptsUpdated(const std::set<HostID>& changed_hosts, |
37 const UserScriptList& scripts) override; | 38 const UserScriptList& scripts) override; |
38 | 39 |
39 // ScriptInjector implementation. | 40 // ScriptInjector implementation. |
40 UserScript::InjectionType script_type() const override; | 41 UserScript::InjectionType script_type() const override; |
41 bool ShouldExecuteInMainWorld() const override; | 42 bool ShouldExecuteInMainWorld() const override; |
42 bool IsUserGesture() const override; | 43 bool IsUserGesture() const override; |
43 bool ExpectsResults() const override; | 44 bool ExpectsResults() const override; |
44 bool ShouldInjectJs(UserScript::RunLocation run_location) const override; | 45 bool ShouldInjectJs( |
45 bool ShouldInjectCss(UserScript::RunLocation run_location) const override; | 46 UserScript::RunLocation run_location, |
47 const std::set<std::string>& executing_scripts) const override; | |
48 bool ShouldInjectCss( | |
49 UserScript::RunLocation run_location, | |
50 const std::set<std::string>& injected_stylesheets) const override; | |
46 PermissionsData::AccessType CanExecuteOnFrame( | 51 PermissionsData::AccessType CanExecuteOnFrame( |
47 const InjectionHost* injection_host, | 52 const InjectionHost* injection_host, |
48 blink::WebLocalFrame* web_frame, | 53 blink::WebLocalFrame* web_frame, |
49 int tab_id) const override; | 54 int tab_id) const override; |
50 std::vector<blink::WebScriptSource> GetJsSources( | 55 std::vector<blink::WebScriptSource> GetJsSources( |
51 UserScript::RunLocation run_location) const override; | 56 UserScript::RunLocation run_location, |
57 std::set<std::string>* executing_scripts, | |
58 size_t* num_injected_js_scripts) const override; | |
52 std::vector<blink::WebString> GetCssSources( | 59 std::vector<blink::WebString> GetCssSources( |
53 UserScript::RunLocation run_location) const override; | 60 UserScript::RunLocation run_location, |
54 void GetRunInfo(ScriptsRunInfo* scripts_run_info, | 61 std::set<std::string>* injected_stylesheets, |
55 UserScript::RunLocation run_location) const override; | 62 size_t* num_injected_stylesheets) const override; |
56 void OnInjectionComplete(std::unique_ptr<base::Value> execution_result, | 63 void OnInjectionComplete(std::unique_ptr<base::Value> execution_result, |
57 UserScript::RunLocation run_location, | 64 UserScript::RunLocation run_location, |
58 content::RenderFrame* render_frame) override; | 65 content::RenderFrame* render_frame) override; |
59 void OnWillNotInject(InjectFailureReason reason, | 66 void OnWillNotInject(InjectFailureReason reason, |
60 content::RenderFrame* render_frame) override; | 67 content::RenderFrame* render_frame) override; |
61 | 68 |
62 // The associated user script. Owned by the UserScriptInjector that created | 69 // The associated user script. Owned by the UserScriptInjector that created |
63 // this object. | 70 // this object. |
64 const UserScript* script_; | 71 const UserScript* script_; |
65 | 72 |
(...skipping 16 matching lines...) Expand all Loading... | |
82 | 89 |
83 ScopedObserver<UserScriptSet, UserScriptSet::Observer> | 90 ScopedObserver<UserScriptSet, UserScriptSet::Observer> |
84 user_script_set_observer_; | 91 user_script_set_observer_; |
85 | 92 |
86 DISALLOW_COPY_AND_ASSIGN(UserScriptInjector); | 93 DISALLOW_COPY_AND_ASSIGN(UserScriptInjector); |
87 }; | 94 }; |
88 | 95 |
89 } // namespace extensions | 96 } // namespace extensions |
90 | 97 |
91 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_INJECTOR_H_ | 98 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_INJECTOR_H_ |
OLD | NEW |