[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 | |
| 16 | namespace blink { |
| 17 | class WebFrame; |
| 18 | } |
| 19 | |
[email protected] | cde18a2d | 2014-07-01 03:13:04 | [diff] [blame] | 20 | namespace content { |
| 21 | class RenderView; |
| 22 | } |
| 23 | |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 24 | namespace extensions { |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 25 | |
| 26 | // A ScriptInjector to handle tabs.executeScript(). |
| 27 | class ProgrammaticScriptInjector : public ScriptInjector { |
| 28 | public: |
| 29 | ProgrammaticScriptInjector(const ExtensionMsg_ExecuteCode_Params& params, |
| 30 | blink::WebFrame* web_frame); |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 31 | ~ProgrammaticScriptInjector() override; |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 32 | |
| 33 | private: |
| 34 | // ScriptInjector implementation. |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 35 | UserScript::InjectionType script_type() const override; |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 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( |
hanxi | a5c856cf | 2015-02-13 20:51:58 | [diff] [blame] | 42 | const InjectionHost* injection_host, |
[email protected] | 23a8536 | 2014-07-07 23:26:19 | [diff] [blame] | 43 | blink::WebFrame* web_frame, |
rdevlin.cronin | f994d1e | 2015-06-03 22:28:19 | [diff] [blame^] | 44 | int tab_id) const override; |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 45 | std::vector<blink::WebScriptSource> GetJsSources( |
mostynb | 0eac4e1b | 2014-10-03 16:32:19 | [diff] [blame] | 46 | UserScript::RunLocation run_location) const override; |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 47 | std::vector<std::string> GetCssSources( |
mostynb | 0eac4e1b | 2014-10-03 16:32:19 | [diff] [blame] | 48 | UserScript::RunLocation run_location) const override; |
kozyatinskiy | c8bc9a58 | 2015-03-06 09:33:41 | [diff] [blame] | 49 | void GetRunInfo(ScriptsRunInfo* scripts_run_info, |
| 50 | UserScript::RunLocation run_location) const override; |
rdevlin.cronin | 4bb32d7 | 2015-06-02 21:55:01 | [diff] [blame] | 51 | void OnInjectionComplete(scoped_ptr<base::Value> execution_result, |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 52 | UserScript::RunLocation run_location) override; |
| 53 | void OnWillNotInject(InjectFailureReason reason) override; |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 54 | |
| 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] | cde18a2d | 2014-07-01 03:13:04 | [diff] [blame] | 65 | // The url of the frame into which we are injecting. |
| 66 | GURL url_; |
| 67 | |
rob | a9e6e642 | 2015-03-30 21:14:02 | [diff] [blame] | 68 | // 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] | cde18a2d | 2014-07-01 03:13:04 | [diff] [blame] | 73 | // The RenderView to which we send the response upon completion. |
| 74 | content::RenderView* render_view_; |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 75 | |
| 76 | // The results of the script execution. |
rdevlin.cronin | 4bb32d7 | 2015-06-02 21:55:01 | [diff] [blame] | 77 | base::ListValue results_; |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 78 | |
| 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_ |