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
{
26 // A ScriptInjector to handle tabs.executeScript().
27 class ProgrammaticScriptInjector
: public ScriptInjector
{
29 ProgrammaticScriptInjector(const ExtensionMsg_ExecuteCode_Params
& params
,
30 blink::WebFrame
* web_frame
);
31 virtual ~ProgrammaticScriptInjector();
34 // ScriptInjector implementation.
35 virtual UserScript::InjectionType
script_type() const OVERRIDE
;
36 virtual bool ShouldExecuteInChildFrames() const OVERRIDE
;
37 virtual bool ShouldExecuteInMainWorld() const OVERRIDE
;
38 virtual bool IsUserGesture() const OVERRIDE
;
39 virtual bool ExpectsResults() const OVERRIDE
;
40 virtual bool ShouldInjectJs(
41 UserScript::RunLocation run_location
) const OVERRIDE
;
42 virtual bool ShouldInjectCss(
43 UserScript::RunLocation run_location
) const OVERRIDE
;
44 virtual PermissionsData::AccessType
CanExecuteOnFrame(
45 const Extension
* extension
,
46 blink::WebFrame
* web_frame
,
48 const GURL
& top_url
) const OVERRIDE
;
49 virtual std::vector
<blink::WebScriptSource
> GetJsSources(
50 UserScript::RunLocation run_location
) const OVERRIDE
;
51 virtual std::vector
<std::string
> GetCssSources(
52 UserScript::RunLocation run_location
) const OVERRIDE
;
53 virtual void OnInjectionComplete(
54 scoped_ptr
<base::ListValue
> execution_results
,
55 ScriptsRunInfo
* scripts_run_info
,
56 UserScript::RunLocation run_location
) OVERRIDE
;
57 virtual void OnWillNotInject(InjectFailureReason reason
) OVERRIDE
;
59 // Return the run location for this injector.
60 UserScript::RunLocation
GetRunLocation() const;
62 // Notify the browser that the script was injected (or never will be), and
63 // send along any results or errors.
64 void Finish(const std::string
& error
);
66 // The parameters for injecting the script.
67 scoped_ptr
<ExtensionMsg_ExecuteCode_Params
> params_
;
69 // The url of the frame into which we are injecting.
72 // The RenderView to which we send the response upon completion.
73 content::RenderView
* render_view_
;
75 // The results of the script execution.
76 scoped_ptr
<base::ListValue
> results_
;
78 // Whether or not this script injection has finished.
81 DISALLOW_COPY_AND_ASSIGN(ProgrammaticScriptInjector
);
84 } // namespace extensions
86 #endif // EXTENSIONS_RENDERER_PROGRAMMATIC_SCRIPT_INJECTOR_H_