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_PROGRAMMATIC_SCRIPT_INJECTOR_H_
6 #define EXTENSIONS_RENDERER_PROGRAMMATIC_SCRIPT_INJECTOR_H_
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "extensions/renderer/script_injection.h"
13 struct ExtensionMsg_ExecuteCode_Params
;
23 namespace extensions
{
25 // A ScriptInjector to handle tabs.executeScript().
26 class ProgrammaticScriptInjector
: public ScriptInjector
{
28 ProgrammaticScriptInjector(const ExtensionMsg_ExecuteCode_Params
& params
,
29 blink::WebFrame
* web_frame
);
30 ~ProgrammaticScriptInjector() override
;
33 // ScriptInjector implementation.
34 UserScript::InjectionType
script_type() const override
;
35 bool ShouldExecuteInChildFrames() const override
;
36 bool ShouldExecuteInMainWorld() const override
;
37 bool IsUserGesture() const override
;
38 bool ExpectsResults() const override
;
39 bool ShouldInjectJs(UserScript::RunLocation run_location
) const override
;
40 bool ShouldInjectCss(UserScript::RunLocation run_location
) const override
;
41 PermissionsData::AccessType
CanExecuteOnFrame(
42 const InjectionHost
* injection_host
,
43 blink::WebFrame
* web_frame
,
45 const GURL
& top_url
) const override
;
46 std::vector
<blink::WebScriptSource
> GetJsSources(
47 UserScript::RunLocation run_location
) const override
;
48 std::vector
<std::string
> GetCssSources(
49 UserScript::RunLocation run_location
) const override
;
50 void GetRunInfo(ScriptsRunInfo
* scripts_run_info
,
51 UserScript::RunLocation run_location
) const override
;
52 void OnInjectionComplete(scoped_ptr
<base::ListValue
> execution_results
,
53 UserScript::RunLocation run_location
) override
;
54 void OnWillNotInject(InjectFailureReason reason
) override
;
56 // Return the run location for this injector.
57 UserScript::RunLocation
GetRunLocation() const;
59 // Notify the browser that the script was injected (or never will be), and
60 // send along any results or errors.
61 void Finish(const std::string
& error
);
63 // The parameters for injecting the script.
64 scoped_ptr
<ExtensionMsg_ExecuteCode_Params
> params_
;
66 // The url of the frame into which we are injecting.
69 // The URL of the frame's origin. This is usually identical to |url_|, but
70 // could be different for e.g. about:blank URLs. Do not use this value to make
71 // security decisions, to avoid race conditions (e.g. due to navigation).
74 // The RenderView to which we send the response upon completion.
75 content::RenderView
* render_view_
;
77 // The results of the script execution.
78 scoped_ptr
<base::ListValue
> results_
;
80 // Whether or not this script injection has finished.
83 DISALLOW_COPY_AND_ASSIGN(ProgrammaticScriptInjector
);
86 } // namespace extensions
88 #endif // EXTENSIONS_RENDERER_PROGRAMMATIC_SCRIPT_INJECTOR_H_