[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" |
| 10 | #include "extensions/renderer/script_injection.h" |
[email protected] | cde18a2d | 2014-07-01 03:13:04 | [diff] [blame] | 11 | #include "url/gurl.h" |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 12 | |
| 13 | struct ExtensionMsg_ExecuteCode_Params; |
| 14 | |
| 15 | namespace blink { |
| 16 | class WebFrame; |
| 17 | } |
| 18 | |
[email protected] | cde18a2d | 2014-07-01 03:13:04 | [diff] [blame] | 19 | namespace content { |
| 20 | class RenderView; |
| 21 | } |
| 22 | |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 23 | namespace extensions { |
| 24 | class Extension; |
| 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; |
| 36 | bool ShouldExecuteInChildFrames() const override; |
| 37 | bool ShouldExecuteInMainWorld() const override; |
| 38 | bool IsUserGesture() const override; |
| 39 | bool ExpectsResults() const override; |
| 40 | bool ShouldInjectJs(UserScript::RunLocation run_location) const override; |
| 41 | bool ShouldInjectCss(UserScript::RunLocation run_location) const override; |
| 42 | PermissionsData::AccessType CanExecuteOnFrame( |
[email protected] | 23a8536 | 2014-07-07 23:26:19 | [diff] [blame] | 43 | const Extension* extension, |
| 44 | blink::WebFrame* web_frame, |
| 45 | int tab_id, |
mostynb | 0eac4e1b | 2014-10-03 16:32:19 | [diff] [blame] | 46 | const GURL& top_url) const override; |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame^] | 47 | std::vector<blink::WebScriptSource> GetJsSources( |
mostynb | 0eac4e1b | 2014-10-03 16:32:19 | [diff] [blame] | 48 | UserScript::RunLocation run_location) const override; |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame^] | 49 | std::vector<std::string> GetCssSources( |
mostynb | 0eac4e1b | 2014-10-03 16:32:19 | [diff] [blame] | 50 | UserScript::RunLocation run_location) const override; |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame^] | 51 | void OnInjectionComplete(scoped_ptr<base::ListValue> execution_results, |
| 52 | ScriptsRunInfo* scripts_run_info, |
| 53 | UserScript::RunLocation run_location) override; |
| 54 | void OnWillNotInject(InjectFailureReason reason) override; |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 55 | |
| 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. |
| 61 | void Finish(const std::string& error); |
| 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 | |
| 69 | // The RenderView to which we send the response upon completion. |
| 70 | content::RenderView* render_view_; |
[email protected] | c11e659 | 2014-06-27 17:07:34 | [diff] [blame] | 71 | |
| 72 | // The results of the script execution. |
| 73 | scoped_ptr<base::ListValue> results_; |
| 74 | |
| 75 | // Whether or not this script injection has finished. |
| 76 | bool finished_; |
| 77 | |
| 78 | DISALLOW_COPY_AND_ASSIGN(ProgrammaticScriptInjector); |
| 79 | }; |
| 80 | |
| 81 | } // namespace extensions |
| 82 | |
| 83 | #endif // EXTENSIONS_RENDERER_PROGRAMMATIC_SCRIPT_INJECTOR_H_ |