[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 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. | ||||
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.cronin | 4bb32d7 | 2015-06-02 21:55:01 | [diff] [blame] | 10 | #include "base/values.h" |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 11 | #include "extensions/renderer/script_injection.h" |
[email protected] | cde18a2d | 2014-07-01 03:13:04 | [diff] [blame] | 12 | #include "url/gurl.h" |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 13 | |
14 | struct ExtensionMsg_ExecuteCode_Params; | ||||
15 | |||||
[email protected] | cde18a2d | 2014-07-01 03:13:04 | [diff] [blame] | 16 | namespace content { |
rdevlin.cronin | 3e11c986 | 2015-06-04 19:54:25 | [diff] [blame] | 17 | class RenderFrame; |
[email protected] | cde18a2d | 2014-07-01 03:13:04 | [diff] [blame] | 18 | } |
19 | |||||
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 20 | namespace extensions { |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 21 | |
22 | // A ScriptInjector to handle tabs.executeScript(). | ||||
23 | class ProgrammaticScriptInjector : public ScriptInjector { | ||||
24 | public: | ||||
25 | ProgrammaticScriptInjector(const ExtensionMsg_ExecuteCode_Params& params, | ||||
rdevlin.cronin | 3e11c986 | 2015-06-04 19:54:25 | [diff] [blame] | 26 | content::RenderFrame* render_frame); |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 27 | ~ProgrammaticScriptInjector() override; |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 28 | |
29 | private: | ||||
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 30 | // ScriptInjector implementation. |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 31 | UserScript::InjectionType script_type() const override; |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 32 | bool ShouldExecuteInMainWorld() const override; |
33 | bool IsUserGesture() const override; | ||||
34 | bool ExpectsResults() const override; | ||||
35 | bool ShouldInjectJs(UserScript::RunLocation run_location) const override; | ||||
36 | bool ShouldInjectCss(UserScript::RunLocation run_location) const override; | ||||
37 | PermissionsData::AccessType CanExecuteOnFrame( | ||||
hanxi | a5c856cf | 2015-02-13 20:51:58 | [diff] [blame] | 38 | const InjectionHost* injection_host, |
rdevlin.cronin | 3e11c986 | 2015-06-04 19:54:25 | [diff] [blame] | 39 | blink::WebLocalFrame* web_frame, |
rdevlin.cronin | f994d1e | 2015-06-03 22:28:19 | [diff] [blame] | 40 | int tab_id) const override; |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 41 | std::vector<blink::WebScriptSource> GetJsSources( |
mostynb | 0eac4e1b | 2014-10-03 16:32:19 | [diff] [blame] | 42 | UserScript::RunLocation run_location) const override; |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 43 | std::vector<std::string> GetCssSources( |
mostynb | 0eac4e1b | 2014-10-03 16:32:19 | [diff] [blame] | 44 | UserScript::RunLocation run_location) const override; |
kozyatinskiy | c8bc9a58 | 2015-03-06 09:33:41 | [diff] [blame] | 45 | void GetRunInfo(ScriptsRunInfo* scripts_run_info, |
46 | UserScript::RunLocation run_location) const override; | ||||
rdevlin.cronin | 4bb32d7 | 2015-06-02 21:55:01 | [diff] [blame] | 47 | void OnInjectionComplete(scoped_ptr<base::Value> execution_result, |
rdevlin.cronin | d533be96 | 2015-10-02 17:01:18 | [diff] [blame] | 48 | UserScript::RunLocation run_location, |
49 | content::RenderFrame* render_frame) override; | ||||
50 | void OnWillNotInject(InjectFailureReason reason, | ||||
51 | content::RenderFrame* render_frame) override; | ||||
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 52 | |
rob | 52277c8 | 2016-02-07 17:28:57 | [diff] [blame^] | 53 | // Whether it is safe to include information about the URL in error messages. |
54 | bool CanShowUrlInError() const; | ||||
55 | |||||
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 56 | // Return the run location for this injector. |
57 | UserScript::RunLocation GetRunLocation() const; | ||||
58 | |||||
59 | // Notify the browser that the script was injected (or never will be), and | ||||
60 | // send along any results or errors. | ||||
rdevlin.cronin | d533be96 | 2015-10-02 17:01:18 | [diff] [blame] | 61 | void Finish(const std::string& error, content::RenderFrame* render_frame); |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 62 | |
63 | // The parameters for injecting the script. | ||||
64 | scoped_ptr<ExtensionMsg_ExecuteCode_Params> params_; | ||||
65 | |||||
[email protected] | cde18a2d | 2014-07-01 03:13:04 | [diff] [blame] | 66 | // The url of the frame into which we are injecting. |
67 | GURL url_; | ||||
68 | |||||
rob | 52277c8 | 2016-02-07 17:28:57 | [diff] [blame^] | 69 | // The serialization of the frame's origin if the frame is an about:-URL. This |
70 | // is used to provide user-friendly messages. | ||||
71 | std::string origin_for_about_error_; | ||||
rob | a9e6e642 | 2015-03-30 21:14:02 | [diff] [blame] | 72 | |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 73 | // The results of the script execution. |
rdevlin.cronin | 4bb32d7 | 2015-06-02 21:55:01 | [diff] [blame] | 74 | base::ListValue results_; |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 75 | |
76 | // Whether or not this script injection has finished. | ||||
77 | bool finished_; | ||||
78 | |||||
79 | DISALLOW_COPY_AND_ASSIGN(ProgrammaticScriptInjector); | ||||
80 | }; | ||||
81 | |||||
82 | } // namespace extensions | ||||
83 | |||||
84 | #endif // EXTENSIONS_RENDERER_PROGRAMMATIC_SCRIPT_INJECTOR_H_ |