OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef EXTENSIONS_RENDERER_USER_SCRIPT_INJECTION_H_ |
| 6 #define EXTENSIONS_RENDERER_USER_SCRIPT_INJECTION_H_ |
| 7 |
| 8 #include "extensions/renderer/script_injection.h" |
| 9 |
| 10 #include <string> |
| 11 |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/scoped_observer.h" |
| 14 #include "extensions/common/user_script.h" |
| 15 #include "extensions/renderer/user_script_injection_list.h" |
| 16 |
| 17 namespace blink { |
| 18 class WebFrame; |
| 19 } |
| 20 |
| 21 namespace extensions { |
| 22 class Extension; |
| 23 |
| 24 // A ScriptInjection for UserScripts. |
| 25 class UserScriptInjection : public ScriptInjection, |
| 26 public UserScriptInjectionList::Observer { |
| 27 public: |
| 28 UserScriptInjection(blink::WebFrame* web_frame, |
| 29 const std::string& extension_id, |
| 30 UserScript::RunLocation run_location, |
| 31 int tab_id, |
| 32 UserScriptInjectionList* script_list, |
| 33 const UserScript* script, |
| 34 bool inject_js, |
| 35 bool inject_css); |
| 36 virtual ~UserScriptInjection(); |
| 37 |
| 38 int64 script_id() const { return script_id_; } |
| 39 void set_script(const UserScript* script) { script_ = script; } |
| 40 |
| 41 private: |
| 42 // Inject the JS/CSS specified in |script_|. |
| 43 void InjectJS(const Extension* extension, ScriptsRunInfo* scripts_run_info); |
| 44 void InjectCSS(ScriptsRunInfo* scripts_run_info); |
| 45 |
| 46 // ScriptInjection implementation. |
| 47 virtual bool Allowed(const Extension* extension) OVERRIDE; |
| 48 virtual void Inject(ScriptsRunInfo* scripts_run_info, |
| 49 const Extension* extension) OVERRIDE; |
| 50 |
| 51 // UserScriptInjectionList::Observer implementation. |
| 52 virtual void OnUserScriptsUpdated( |
| 53 const std::set<std::string>& changed_extensions, |
| 54 const std::vector<UserScript*>& scripts) OVERRIDE; |
| 55 |
| 56 // The associated user script. Owned by the UserScriptInjection that created |
| 57 // this object. |
| 58 const UserScript* script_; |
| 59 |
| 60 // The id of the associated user script. |
| 61 int64 script_id_; |
| 62 |
| 63 // Whether or not this should inject JS. |
| 64 bool inject_js_; |
| 65 |
| 66 // Whether or not this should inject CSS. |
| 67 bool inject_css_; |
| 68 |
| 69 ScopedObserver<UserScriptInjectionList, UserScriptInjectionList::Observer> |
| 70 user_script_injection_list_observer_; |
| 71 }; |
| 72 |
| 73 } // namespace extensions |
| 74 |
| 75 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_INJECTION_H_ |
OLD | NEW |