blob: 8caca0f582fb8c08b9a8523294c53599ca376b8a [file] [log] [blame]
[email protected]c11e6592014-06-27 17:07:341// 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.
4
5#ifndef EXTENSIONS_RENDERER_PROGRAMMATIC_SCRIPT_INJECTOR_H_
6#define EXTENSIONS_RENDERER_PROGRAMMATIC_SCRIPT_INJECTOR_H_
7
8#include "base/macros.h"
9#include "base/memory/scoped_ptr.h"
rdevlin.cronin4bb32d72015-06-02 21:55:0110#include "base/values.h"
[email protected]c11e6592014-06-27 17:07:3411#include "extensions/renderer/script_injection.h"
[email protected]cde18a2d2014-07-01 03:13:0412#include "url/gurl.h"
[email protected]c11e6592014-06-27 17:07:3413
14struct ExtensionMsg_ExecuteCode_Params;
15
16namespace blink {
17class WebFrame;
18}
19
[email protected]cde18a2d2014-07-01 03:13:0420namespace content {
21class RenderView;
22}
23
[email protected]c11e6592014-06-27 17:07:3424namespace extensions {
[email protected]c11e6592014-06-27 17:07:3425
26// A ScriptInjector to handle tabs.executeScript().
27class ProgrammaticScriptInjector : public ScriptInjector {
28 public:
29 ProgrammaticScriptInjector(const ExtensionMsg_ExecuteCode_Params& params,
30 blink::WebFrame* web_frame);
dcheng9168b2f2014-10-21 12:38:2431 ~ProgrammaticScriptInjector() override;
[email protected]c11e6592014-06-27 17:07:3432
33 private:
34 // ScriptInjector implementation.
dcheng9168b2f2014-10-21 12:38:2435 UserScript::InjectionType script_type() const override;
dcheng9168b2f2014-10-21 12:38:2436 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(
hanxia5c856cf2015-02-13 20:51:5842 const InjectionHost* injection_host,
[email protected]23a85362014-07-07 23:26:1943 blink::WebFrame* web_frame,
rdevlin.croninf994d1e2015-06-03 22:28:1944 int tab_id) const override;
dcheng9168b2f2014-10-21 12:38:2445 std::vector<blink::WebScriptSource> GetJsSources(
mostynb0eac4e1b2014-10-03 16:32:1946 UserScript::RunLocation run_location) const override;
dcheng9168b2f2014-10-21 12:38:2447 std::vector<std::string> GetCssSources(
mostynb0eac4e1b2014-10-03 16:32:1948 UserScript::RunLocation run_location) const override;
kozyatinskiyc8bc9a582015-03-06 09:33:4149 void GetRunInfo(ScriptsRunInfo* scripts_run_info,
50 UserScript::RunLocation run_location) const override;
rdevlin.cronin4bb32d72015-06-02 21:55:0151 void OnInjectionComplete(scoped_ptr<base::Value> execution_result,
dcheng9168b2f2014-10-21 12:38:2452 UserScript::RunLocation run_location) override;
53 void OnWillNotInject(InjectFailureReason reason) override;
[email protected]c11e6592014-06-27 17:07:3454
55 // Return the run location for this injector.
56 UserScript::RunLocation GetRunLocation() const;
57
58 // Notify the browser that the script was injected (or never will be), and
59 // send along any results or errors.
60 void Finish(const std::string& error);
61
62 // The parameters for injecting the script.
63 scoped_ptr<ExtensionMsg_ExecuteCode_Params> params_;
64
[email protected]cde18a2d2014-07-01 03:13:0465 // The url of the frame into which we are injecting.
66 GURL url_;
67
roba9e6e6422015-03-30 21:14:0268 // The URL of the frame's origin. This is usually identical to |url_|, but
69 // could be different for e.g. about:blank URLs. Do not use this value to make
70 // security decisions, to avoid race conditions (e.g. due to navigation).
71 GURL effective_url_;
72
[email protected]cde18a2d2014-07-01 03:13:0473 // The RenderView to which we send the response upon completion.
74 content::RenderView* render_view_;
[email protected]c11e6592014-06-27 17:07:3475
76 // The results of the script execution.
rdevlin.cronin4bb32d72015-06-02 21:55:0177 base::ListValue results_;
[email protected]c11e6592014-06-27 17:07:3478
79 // Whether or not this script injection has finished.
80 bool finished_;
81
82 DISALLOW_COPY_AND_ASSIGN(ProgrammaticScriptInjector);
83};
84
85} // namespace extensions
86
87#endif // EXTENSIONS_RENDERER_PROGRAMMATIC_SCRIPT_INJECTOR_H_