blob: 673a08ee598c555ef2deb5c622b4960d329f4085 [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
dchengf6f80662016-04-20 20:26:048#include <memory>
9
[email protected]c11e6592014-06-27 17:07:3410#include "base/macros.h"
rdevlin.cronin4bb32d72015-06-02 21:55:0111#include "base/values.h"
[email protected]c11e6592014-06-27 17:07:3412#include "extensions/renderer/script_injection.h"
[email protected]cde18a2d2014-07-01 03:13:0413#include "url/gurl.h"
[email protected]c11e6592014-06-27 17:07:3414
15struct ExtensionMsg_ExecuteCode_Params;
16
[email protected]cde18a2d2014-07-01 03:13:0417namespace content {
rdevlin.cronin3e11c9862015-06-04 19:54:2518class RenderFrame;
[email protected]cde18a2d2014-07-01 03:13:0419}
20
[email protected]c11e6592014-06-27 17:07:3421namespace extensions {
[email protected]c11e6592014-06-27 17:07:3422
23// A ScriptInjector to handle tabs.executeScript().
24class ProgrammaticScriptInjector : public ScriptInjector {
25 public:
jam69e71152016-11-02 01:15:4326 explicit ProgrammaticScriptInjector(
27 const ExtensionMsg_ExecuteCode_Params& params);
dcheng9168b2f2014-10-21 12:38:2428 ~ProgrammaticScriptInjector() override;
[email protected]c11e6592014-06-27 17:07:3429
30 private:
31 // ScriptInjector implementation.
dcheng9168b2f2014-10-21 12:38:2432 UserScript::InjectionType script_type() const override;
dcheng9168b2f2014-10-21 12:38:2433 bool ShouldExecuteInMainWorld() const override;
34 bool IsUserGesture() const override;
35 bool ExpectsResults() const override;
catmullingsd4faad4f2016-09-08 19:55:3036 bool ShouldInjectJs(
37 UserScript::RunLocation run_location,
38 const std::set<std::string>& executing_scripts) const override;
39 bool ShouldInjectCss(
40 UserScript::RunLocation run_location,
41 const std::set<std::string>& injected_stylesheets) const override;
dcheng9168b2f2014-10-21 12:38:2442 PermissionsData::AccessType CanExecuteOnFrame(
hanxia5c856cf2015-02-13 20:51:5843 const InjectionHost* injection_host,
rdevlin.cronin3e11c9862015-06-04 19:54:2544 blink::WebLocalFrame* web_frame,
jam69e71152016-11-02 01:15:4345 int tab_id) override;
dcheng9168b2f2014-10-21 12:38:2446 std::vector<blink::WebScriptSource> GetJsSources(
catmullingsd4faad4f2016-09-08 19:55:3047 UserScript::RunLocation run_location,
48 std::set<std::string>* executing_scripts,
49 size_t* num_injected_js_scripts) const override;
lazyboy49cc0b3a2016-08-18 21:55:1250 std::vector<blink::WebString> GetCssSources(
catmullingsd4faad4f2016-09-08 19:55:3051 UserScript::RunLocation run_location,
52 std::set<std::string>* injected_stylesheets,
53 size_t* num_injected_stylesheets) const override;
dchengf6f80662016-04-20 20:26:0454 void OnInjectionComplete(std::unique_ptr<base::Value> execution_result,
rdevlin.cronind533be962015-10-02 17:01:1855 UserScript::RunLocation run_location,
56 content::RenderFrame* render_frame) override;
57 void OnWillNotInject(InjectFailureReason reason,
58 content::RenderFrame* render_frame) override;
[email protected]c11e6592014-06-27 17:07:3459
rob52277c82016-02-07 17:28:5760 // Whether it is safe to include information about the URL in error messages.
61 bool CanShowUrlInError() const;
62
[email protected]c11e6592014-06-27 17:07:3463 // Return the run location for this injector.
64 UserScript::RunLocation GetRunLocation() const;
65
66 // Notify the browser that the script was injected (or never will be), and
67 // send along any results or errors.
rdevlin.cronind533be962015-10-02 17:01:1868 void Finish(const std::string& error, content::RenderFrame* render_frame);
[email protected]c11e6592014-06-27 17:07:3469
70 // The parameters for injecting the script.
dchengf6f80662016-04-20 20:26:0471 std::unique_ptr<ExtensionMsg_ExecuteCode_Params> params_;
[email protected]c11e6592014-06-27 17:07:3472
[email protected]cde18a2d2014-07-01 03:13:0473 // The url of the frame into which we are injecting.
74 GURL url_;
75
rob52277c82016-02-07 17:28:5776 // The serialization of the frame's origin if the frame is an about:-URL. This
77 // is used to provide user-friendly messages.
78 std::string origin_for_about_error_;
roba9e6e6422015-03-30 21:14:0279
[email protected]c11e6592014-06-27 17:07:3480 // The results of the script execution.
rdevlin.cronin4bb32d72015-06-02 21:55:0181 base::ListValue results_;
[email protected]c11e6592014-06-27 17:07:3482
83 // Whether or not this script injection has finished.
84 bool finished_;
85
86 DISALLOW_COPY_AND_ASSIGN(ProgrammaticScriptInjector);
87};
88
89} // namespace extensions
90
91#endif // EXTENSIONS_RENDERER_PROGRAMMATIC_SCRIPT_INJECTOR_H_