Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / extensions / renderer / user_script_injector.h
blob3314bb05a18f75bc7ab0a4b0b06f362112e14696
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_
8 #include <string>
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"
16 namespace blink {
17 class WebFrame;
20 namespace extensions {
21 class Extension;
23 // A ScriptInjector for UserScripts.
24 class UserScriptInjector : public ScriptInjector,
25 public UserScriptSet::Observer {
26 public:
27 UserScriptInjector(const UserScript* user_script,
28 UserScriptSet* user_script_set);
29 virtual ~UserScriptInjector();
31 private:
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,
50 int tab_id,
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
63 // this object.
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
68 // deleted.
69 int script_id_;
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_