Reland the ULONG -> SIZE_T change from 317177
[chromium-blink-merge.git] / extensions / renderer / user_script_injector.h
blob86d9e9fa86886404d1f2824b77f9f45178befd99
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<std::string>& changed_extensions,
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 OnInjectionComplete(scoped_ptr<base::ListValue> execution_results,
56 ScriptsRunInfo* scripts_run_info,
57 UserScript::RunLocation run_location) override;
58 void OnWillNotInject(InjectFailureReason reason) override;
60 // The associated user script. Owned by the UserScriptInjector that created
61 // this object.
62 const UserScript* script_;
64 // The id of the associated user script. We cache this because when we update
65 // the |script_| associated with this injection, the old referance may be
66 // deleted.
67 int script_id_;
69 // The associated extension id, preserved for the same reason as |script_id|.
70 std::string extension_id_;
72 // Indicates whether or not this script is declarative. This influences which
73 // script permissions are checked before injection.
74 bool is_declarative_;
76 ScopedObserver<UserScriptSet, UserScriptSet::Observer>
77 user_script_set_observer_;
79 DISALLOW_COPY_AND_ASSIGN(UserScriptInjector);
82 } // namespace extensions
84 #endif // EXTENSIONS_RENDERER_USER_SCRIPT_INJECTOR_H_