| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/scoped_observer.h" | 11 #include "base/scoped_observer.h" |
| 12 #include "extensions/common/user_script.h" | 12 #include "extensions/common/user_script.h" |
| 13 #include "extensions/renderer/script_injection.h" | 13 #include "extensions/renderer/script_injection.h" |
| 14 #include "extensions/renderer/user_script_set.h" | 14 #include "extensions/renderer/user_script_set.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 class WebFrame; | 17 class WebFrame; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 class Extension; | 21 class Extension; |
| 22 | 22 |
| 23 // A ScriptInjector for UserScripts. | 23 // A ScriptInjector for UserScripts. |
| 24 class UserScriptInjector : public ScriptInjector, | 24 class UserScriptInjector : public ScriptInjector, |
| 25 public UserScriptSet::Observer { | 25 public UserScriptSet::Observer { |
| 26 public: | 26 public: |
| 27 UserScriptInjector(const UserScript* user_script, | 27 UserScriptInjector(const UserScript* user_script, |
| 28 UserScriptSet* user_script_set, | 28 UserScriptSet* user_script_set, |
| 29 bool is_declarative); | 29 bool is_declarative); |
| 30 virtual ~UserScriptInjector(); | 30 ~UserScriptInjector() override; |
| 31 | 31 |
| 32 private: | 32 private: |
| 33 // UserScriptSet::Observer implementation. | 33 // UserScriptSet::Observer implementation. |
| 34 virtual void OnUserScriptsUpdated( | 34 void OnUserScriptsUpdated(const std::set<std::string>& changed_extensions, |
| 35 const std::set<std::string>& changed_extensions, | 35 const std::vector<UserScript*>& scripts) override; |
| 36 const std::vector<UserScript*>& scripts) override; | |
| 37 | 36 |
| 38 // ScriptInjector implementation. | 37 // ScriptInjector implementation. |
| 39 virtual UserScript::InjectionType script_type() const override; | 38 UserScript::InjectionType script_type() const override; |
| 40 virtual bool ShouldExecuteInChildFrames() const override; | 39 bool ShouldExecuteInChildFrames() const override; |
| 41 virtual bool ShouldExecuteInMainWorld() const override; | 40 bool ShouldExecuteInMainWorld() const override; |
| 42 virtual bool IsUserGesture() const override; | 41 bool IsUserGesture() const override; |
| 43 virtual bool ExpectsResults() const override; | 42 bool ExpectsResults() const override; |
| 44 virtual bool ShouldInjectJs( | 43 bool ShouldInjectJs(UserScript::RunLocation run_location) const override; |
| 45 UserScript::RunLocation run_location) const override; | 44 bool ShouldInjectCss(UserScript::RunLocation run_location) const override; |
| 46 virtual bool ShouldInjectCss( | 45 PermissionsData::AccessType CanExecuteOnFrame( |
| 47 UserScript::RunLocation run_location) const override; | |
| 48 virtual PermissionsData::AccessType CanExecuteOnFrame( | |
| 49 const Extension* extension, | 46 const Extension* extension, |
| 50 blink::WebFrame* web_frame, | 47 blink::WebFrame* web_frame, |
| 51 int tab_id, | 48 int tab_id, |
| 52 const GURL& top_url) const override; | 49 const GURL& top_url) const override; |
| 53 virtual std::vector<blink::WebScriptSource> GetJsSources( | 50 std::vector<blink::WebScriptSource> GetJsSources( |
| 54 UserScript::RunLocation run_location) const override; | 51 UserScript::RunLocation run_location) const override; |
| 55 virtual std::vector<std::string> GetCssSources( | 52 std::vector<std::string> GetCssSources( |
| 56 UserScript::RunLocation run_location) const override; | 53 UserScript::RunLocation run_location) const override; |
| 57 virtual void OnInjectionComplete( | 54 void OnInjectionComplete(scoped_ptr<base::ListValue> execution_results, |
| 58 scoped_ptr<base::ListValue> execution_results, | 55 ScriptsRunInfo* scripts_run_info, |
| 59 ScriptsRunInfo* scripts_run_info, | 56 UserScript::RunLocation run_location) override; |
| 60 UserScript::RunLocation run_location) override; | 57 void OnWillNotInject(InjectFailureReason reason) override; |
| 61 virtual void OnWillNotInject(InjectFailureReason reason) override; | |
| 62 | 58 |
| 63 // The associated user script. Owned by the UserScriptInjector that created | 59 // The associated user script. Owned by the UserScriptInjector that created |
| 64 // this object. | 60 // this object. |
| 65 const UserScript* script_; | 61 const UserScript* script_; |
| 66 | 62 |
| 67 // The id of the associated user script. We cache this because when we update | 63 // 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 | 64 // the |script_| associated with this injection, the old referance may be |
| 69 // deleted. | 65 // deleted. |
| 70 int script_id_; | 66 int script_id_; |
| 71 | 67 |
| 72 // The associated extension id, preserved for the same reason as |script_id|. | 68 // The associated extension id, preserved for the same reason as |script_id|. |
| 73 std::string extension_id_; | 69 std::string extension_id_; |
| 74 | 70 |
| 75 // Indicates whether or not this script is declarative. This influences which | 71 // Indicates whether or not this script is declarative. This influences which |
| 76 // script permissions are checked before injection. | 72 // script permissions are checked before injection. |
| 77 bool is_declarative_; | 73 bool is_declarative_; |
| 78 | 74 |
| 79 ScopedObserver<UserScriptSet, UserScriptSet::Observer> | 75 ScopedObserver<UserScriptSet, UserScriptSet::Observer> |
| 80 user_script_set_observer_; | 76 user_script_set_observer_; |
| 81 | 77 |
| 82 DISALLOW_COPY_AND_ASSIGN(UserScriptInjector); | 78 DISALLOW_COPY_AND_ASSIGN(UserScriptInjector); |
| 83 }; | 79 }; |
| 84 | 80 |
| 85 } // namespace extensions | 81 } // namespace extensions |
| 86 | 82 |
| 87 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_INJECTOR_H_ | 83 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_INJECTOR_H_ |
| OLD | NEW |