| 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/renderer_user_script.h" |
| 14 #include "extensions/renderer/script_injection.h" | 15 #include "extensions/renderer/script_injection.h" |
| 15 #include "extensions/renderer/user_script_set.h" | 16 #include "extensions/renderer/user_script_set.h" |
| 16 | 17 |
| 17 class InjectionHost; | 18 class InjectionHost; |
| 18 | 19 |
| 19 namespace blink { | 20 namespace blink { |
| 20 class WebLocalFrame; | 21 class WebLocalFrame; |
| 21 } | 22 } |
| 22 | 23 |
| 23 namespace extensions { | 24 namespace extensions { |
| 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 RendererUserScript* 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( | 37 void OnUserScriptsUpdated( |
| 37 const std::set<HostID>& changed_hosts, | 38 const std::set<HostID>& changed_hosts, |
| 38 const std::vector<std::unique_ptr<UserScript>>& scripts) override; | 39 const std::vector<std::unique_ptr<RendererUserScript>>& scripts) override; |
| 39 | 40 |
| 40 // ScriptInjector implementation. | 41 // ScriptInjector implementation. |
| 41 UserScript::InjectionType script_type() const override; | 42 UserScript::InjectionType script_type() const override; |
| 42 bool ShouldExecuteInMainWorld() const override; | 43 bool ShouldExecuteInMainWorld() const override; |
| 43 bool IsUserGesture() const override; | 44 bool IsUserGesture() const override; |
| 44 bool ExpectsResults() const override; | 45 bool ExpectsResults() const override; |
| 45 bool ShouldInjectJs(UserScript::RunLocation run_location) const override; | 46 bool ShouldInjectJs(UserScript::RunLocation run_location) const override; |
| 46 bool ShouldInjectCss(UserScript::RunLocation run_location) const override; | 47 bool ShouldInjectCss(UserScript::RunLocation run_location) const override; |
| 47 PermissionsData::AccessType CanExecuteOnFrame( | 48 PermissionsData::AccessType CanExecuteOnFrame( |
| 48 const InjectionHost* injection_host, | 49 const InjectionHost* injection_host, |
| 49 blink::WebLocalFrame* web_frame, | 50 blink::WebLocalFrame* web_frame, |
| 50 int tab_id) const override; | 51 int tab_id) const override; |
| 51 std::vector<blink::WebScriptSource> GetJsSources( | 52 std::vector<blink::WebScriptSource> GetJsSources( |
| 52 UserScript::RunLocation run_location) const override; | 53 UserScript::RunLocation run_location) const override; |
| 53 std::vector<std::string> GetCssSources( | 54 std::vector<std::string> GetCssSources( |
| 54 UserScript::RunLocation run_location) const override; | 55 UserScript::RunLocation run_location) const override; |
| 55 void GetRunInfo(ScriptsRunInfo* scripts_run_info, | 56 void GetRunInfo(ScriptsRunInfo* scripts_run_info, |
| 56 UserScript::RunLocation run_location) const override; | 57 UserScript::RunLocation run_location) const override; |
| 57 void OnInjectionComplete(std::unique_ptr<base::Value> execution_result, | 58 void OnInjectionComplete(std::unique_ptr<base::Value> execution_result, |
| 58 UserScript::RunLocation run_location, | 59 UserScript::RunLocation run_location, |
| 59 content::RenderFrame* render_frame) override; | 60 content::RenderFrame* render_frame) override; |
| 60 void OnWillNotInject(InjectFailureReason reason, | 61 void OnWillNotInject(InjectFailureReason reason, |
| 61 content::RenderFrame* render_frame) override; | 62 content::RenderFrame* render_frame) override; |
| 62 | 63 |
| 63 // The associated user script. Owned by the UserScriptInjector that created | 64 // The associated user script. Owned by the UserScriptInjector that created |
| 64 // this object. | 65 // this object. |
| 65 const UserScript* script_; | 66 const RendererUserScript* script_; |
| 66 | 67 |
| 67 // The id of the associated user script. We cache this because when we update | 68 // The id of the associated user script. We cache this because when we update |
| 68 // the |script_| associated with this injection, the old referance may be | 69 // the |script_| associated with this injection, the old referance may be |
| 69 // deleted. | 70 // deleted. |
| 70 int script_id_; | 71 int script_id_; |
| 71 | 72 |
| 72 // The associated host id, preserved for the same reason as |script_id|. | 73 // The associated host id, preserved for the same reason as |script_id|. |
| 73 HostID host_id_; | 74 HostID host_id_; |
| 74 | 75 |
| 75 // Indicates whether or not this script is declarative. This influences which | 76 // Indicates whether or not this script is declarative. This influences which |
| 76 // script permissions are checked before injection. | 77 // script permissions are checked before injection. |
| 77 bool is_declarative_; | 78 bool is_declarative_; |
| 78 | 79 |
| 79 ScopedObserver<UserScriptSet, UserScriptSet::Observer> | 80 ScopedObserver<UserScriptSet, UserScriptSet::Observer> |
| 80 user_script_set_observer_; | 81 user_script_set_observer_; |
| 81 | 82 |
| 82 DISALLOW_COPY_AND_ASSIGN(UserScriptInjector); | 83 DISALLOW_COPY_AND_ASSIGN(UserScriptInjector); |
| 83 }; | 84 }; |
| 84 | 85 |
| 85 } // namespace extensions | 86 } // namespace extensions |
| 86 | 87 |
| 87 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_INJECTOR_H_ | 88 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_INJECTOR_H_ |
| OLD | NEW |