Mac: Fix DelegatedFrameHost not getting vsync parameters.
[chromium-blink-merge.git] / extensions / renderer / user_script_injector.h
blob748fa297ea9dc94a5d0a9023d95d3db0679147bd
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 class InjectionHost;
18 namespace blink {
19 class WebFrame;
22 namespace extensions {
24 // A ScriptInjector for UserScripts.
25 class UserScriptInjector : public ScriptInjector,
26 public UserScriptSet::Observer {
27 public:
28 UserScriptInjector(const UserScript* user_script,
29 UserScriptSet* user_script_set,
30 bool is_declarative);
31 ~UserScriptInjector() override;
33 private:
34 // UserScriptSet::Observer implementation.
35 void OnUserScriptsUpdated(const std::set<HostID>& changed_hosts,
36 const std::vector<UserScript*>& scripts) override;
38 // ScriptInjector implementation.
39 UserScript::InjectionType script_type() const override;
40 bool ShouldExecuteInChildFrames() const override;
41 bool ShouldExecuteInMainWorld() const override;
42 bool IsUserGesture() const override;
43 bool ExpectsResults() const override;
44 bool ShouldInjectJs(UserScript::RunLocation run_location) const override;
45 bool ShouldInjectCss(UserScript::RunLocation run_location) const override;
46 PermissionsData::AccessType CanExecuteOnFrame(
47 const InjectionHost* injection_host,
48 blink::WebFrame* web_frame,
49 int tab_id,
50 const GURL& top_url) const override;
51 std::vector<blink::WebScriptSource> GetJsSources(
52 UserScript::RunLocation run_location) const override;
53 std::vector<std::string> GetCssSources(
54 UserScript::RunLocation run_location) const override;
55 void GetRunInfo(ScriptsRunInfo* scripts_run_info,
56 UserScript::RunLocation run_location) const override;
57 void OnInjectionComplete(scoped_ptr<base::ListValue> execution_results,
58 UserScript::RunLocation run_location) override;
59 void OnWillNotInject(InjectFailureReason reason) override;
61 // The associated user script. Owned by the UserScriptInjector that created
62 // this object.
63 const UserScript* script_;
65 // The id of the associated user script. We cache this because when we update
66 // the |script_| associated with this injection, the old referance may be
67 // deleted.
68 int script_id_;
70 // The associated host id, preserved for the same reason as |script_id|.
71 HostID host_id_;
73 // Indicates whether or not this script is declarative. This influences which
74 // script permissions are checked before injection.
75 bool is_declarative_;
77 ScopedObserver<UserScriptSet, UserScriptSet::Observer>
78 user_script_set_observer_;
80 DISALLOW_COPY_AND_ASSIGN(UserScriptInjector);
83 } // namespace extensions
85 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_INJECTOR_H_