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_USER_SCRIPT_INJECTOR_H_
6 #define EXTENSIONS_RENDERER_USER_SCRIPT_INJECTOR_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/scoped_observer.h"
12 #include "extensions/common/user_script.h"
13 #include "extensions/renderer/script_injection.h"
14 #include "extensions/renderer/user_script_set.h"
20 namespace extensions
{
23 // A ScriptInjector for UserScripts.
24 class UserScriptInjector
: public ScriptInjector
,
25 public UserScriptSet::Observer
{
27 UserScriptInjector(const UserScript
* user_script
,
28 UserScriptSet
* user_script_set
);
29 virtual ~UserScriptInjector();
32 // UserScriptSet::Observer implementation.
33 virtual void OnUserScriptsUpdated(
34 const std::set
<std::string
>& changed_extensions
,
35 const std::vector
<UserScript
*>& scripts
) OVERRIDE
;
37 // ScriptInjector implementation.
38 virtual UserScript::InjectionType
script_type() const OVERRIDE
;
39 virtual bool ShouldExecuteInChildFrames() const OVERRIDE
;
40 virtual bool ShouldExecuteInMainWorld() const OVERRIDE
;
41 virtual bool IsUserGesture() const OVERRIDE
;
42 virtual bool ExpectsResults() const OVERRIDE
;
43 virtual bool ShouldInjectJs(
44 UserScript::RunLocation run_location
) const OVERRIDE
;
45 virtual bool ShouldInjectCss(
46 UserScript::RunLocation run_location
) const OVERRIDE
;
47 virtual PermissionsData::AccessType
CanExecuteOnFrame(
48 const Extension
* extension
,
49 blink::WebFrame
* web_frame
,
51 const GURL
& top_url
) const OVERRIDE
;
52 virtual std::vector
<blink::WebScriptSource
> GetJsSources(
53 UserScript::RunLocation run_location
) const OVERRIDE
;
54 virtual std::vector
<std::string
> GetCssSources(
55 UserScript::RunLocation run_location
) const OVERRIDE
;
56 virtual void OnInjectionComplete(
57 scoped_ptr
<base::ListValue
> execution_results
,
58 ScriptsRunInfo
* scripts_run_info
,
59 UserScript::RunLocation run_location
) OVERRIDE
;
60 virtual void OnWillNotInject(InjectFailureReason reason
) OVERRIDE
;
62 // The associated user script. Owned by the UserScriptInjector that created
64 const UserScript
* script_
;
66 // The id of the associated user script. We cache this because when we update
67 // the |script_| associated with this injection, the old referance may be
71 // The associated extension id, preserved for the same reason as |script_id|.
72 std::string extension_id_
;
74 ScopedObserver
<UserScriptSet
, UserScriptSet::Observer
>
75 user_script_set_observer_
;
77 DISALLOW_COPY_AND_ASSIGN(UserScriptInjector
);
80 } // namespace extensions
82 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_INJECTOR_H_