Add some instrumentation for jank in URLRequest::Start.
[chromium-blink-merge.git] / extensions / renderer / script_injector.h
blob1c98aa0b9f4e62f29ea8d1fb27591275b38abd88
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_SCRIPT_INJECTOR_H_
6 #define EXTENSIONS_RENDERER_SCRIPT_INJECTOR_H_
8 #include <vector>
10 #include "base/memory/scoped_ptr.h"
11 #include "extensions/common/permissions/permissions_data.h"
12 #include "extensions/common/user_script.h"
13 #include "third_party/WebKit/public/web/WebScriptSource.h"
15 class GURL;
16 class InjectionHost;
18 namespace blink {
19 class WebFrame;
22 namespace extensions {
23 struct ScriptsRunInfo;
25 // The pseudo-delegate class for a ScriptInjection that provides all necessary
26 // information about how to inject the script, including what code to inject,
27 // when (run location), and where (world), but without any injection logic.
28 class ScriptInjector {
29 public:
30 // The possible reasons for not injecting the script.
31 enum InjectFailureReason {
32 EXTENSION_REMOVED, // The extension was removed before injection.
33 NOT_ALLOWED, // The script is not allowed to inject.
34 WONT_INJECT // The injection won't inject because the user rejected
35 // (or just did not accept) the injection.
38 virtual ~ScriptInjector() {}
40 // Returns the script type of this particular injection.
41 virtual UserScript::InjectionType script_type() const = 0;
43 // Returns true if the script should execute in child frames.
44 virtual bool ShouldExecuteInChildFrames() const = 0;
46 // Returns true if the script should execute in the main world.
47 virtual bool ShouldExecuteInMainWorld() const = 0;
49 // Returns true if the script is running inside a user gesture.
50 virtual bool IsUserGesture() const = 0;
52 // Returns true if the script expects results.
53 virtual bool ExpectsResults() const = 0;
55 // Returns true if the script should inject JS source at the given
56 // |run_location|.
57 virtual bool ShouldInjectJs(UserScript::RunLocation run_location) const = 0;
59 // Returns true if the script should inject CSS at the given |run_location|.
60 virtual bool ShouldInjectCss(UserScript::RunLocation run_location) const = 0;
62 // Returns true if the script should execute on the given |frame|.
63 virtual PermissionsData::AccessType CanExecuteOnFrame(
64 const InjectionHost* injection_host,
65 blink::WebFrame* web_frame,
66 int tab_id,
67 const GURL& top_url) const = 0;
69 // Returns the javascript sources to inject at the given |run_location|.
70 // Only called if ShouldInjectJs() is true.
71 virtual std::vector<blink::WebScriptSource> GetJsSources(
72 UserScript::RunLocation run_location) const = 0;
74 // Returns the css to inject at the given |run_location|.
75 // Only called if ShouldInjectCss() is true.
76 virtual std::vector<std::string> GetCssSources(
77 UserScript::RunLocation run_location) const = 0;
79 // Fill scriptrs run info based on information about injection.
80 virtual void GetRunInfo(
81 ScriptsRunInfo* scripts_run_info,
82 UserScript::RunLocation run_location) const = 0;
84 // Notifies the script that injection has completed, with a possibly-populated
85 // list of results (depending on whether or not ExpectsResults() was true).
86 virtual void OnInjectionComplete(
87 scoped_ptr<base::ListValue> execution_results,
88 UserScript::RunLocation run_location) = 0;
90 // Notifies the script that injection will never occur.
91 virtual void OnWillNotInject(InjectFailureReason reason) = 0;
94 } // namespace extensions
96 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTOR_H_