Fix WebsitePreference::compareTo.
[chromium-blink-merge.git] / extensions / renderer / user_script_injector.h
blob85e557891334fd5faa8392f4b7ceafd2ca5a1dbd
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 bool is_declarative);
30 ~UserScriptInjector() override;
32 private:
33 // UserScriptSet::Observer implementation.
34 void OnUserScriptsUpdated(const std::set<std::string>& changed_extensions,
35 const std::vector<UserScript*>& scripts) override;
37 // ScriptInjector implementation.
38 UserScript::InjectionType script_type() const override;
39 bool ShouldExecuteInChildFrames() const override;
40 bool ShouldExecuteInMainWorld() const override;
41 bool IsUserGesture() const override;
42 bool ExpectsResults() const override;
43 bool ShouldInjectJs(UserScript::RunLocation run_location) const override;
44 bool ShouldInjectCss(UserScript::RunLocation run_location) const override;
45 PermissionsData::AccessType CanExecuteOnFrame(
46 const Extension* extension,
47 blink::WebFrame* web_frame,
48 int tab_id,
49 const GURL& top_url) const override;
50 std::vector<blink::WebScriptSource> GetJsSources(
51 UserScript::RunLocation run_location) const override;
52 std::vector<std::string> GetCssSources(
53 UserScript::RunLocation run_location) const override;
54 void OnInjectionComplete(scoped_ptr<base::ListValue> execution_results,
55 ScriptsRunInfo* scripts_run_info,
56 UserScript::RunLocation run_location) override;
57 void OnWillNotInject(InjectFailureReason reason) override;
59 // The associated user script. Owned by the UserScriptInjector that created
60 // this object.
61 const UserScript* script_;
63 // The id of the associated user script. We cache this because when we update
64 // the |script_| associated with this injection, the old referance may be
65 // deleted.
66 int script_id_;
68 // The associated extension id, preserved for the same reason as |script_id|.
69 std::string extension_id_;
71 // Indicates whether or not this script is declarative. This influences which
72 // script permissions are checked before injection.
73 bool is_declarative_;
75 ScopedObserver<UserScriptSet, UserScriptSet::Observer>
76 user_script_set_observer_;
78 DISALLOW_COPY_AND_ASSIGN(UserScriptInjector);
81 } // namespace extensions
83 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_INJECTOR_H_