blob: 159ff1c5f4dd072e89ceee87751cc4e69f576803 [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
[email protected]cde18a2d2014-07-01 03:13:0416namespace content {
rdevlin.cronin3e11c9862015-06-04 19:54:2517class RenderFrame;
[email protected]cde18a2d2014-07-01 03:13:0418}
19
[email protected]c11e6592014-06-27 17:07:3420namespace extensions {
[email protected]c11e6592014-06-27 17:07:3421
22// A ScriptInjector to handle tabs.executeScript().
23class ProgrammaticScriptInjector : public ScriptInjector {
24 public:
25 ProgrammaticScriptInjector(const ExtensionMsg_ExecuteCode_Params& params,
rdevlin.cronin3e11c9862015-06-04 19:54:2526 content::RenderFrame* render_frame);
dcheng9168b2f2014-10-21 12:38:2427 ~ProgrammaticScriptInjector() override;
[email protected]c11e6592014-06-27 17:07:3428
29 private:
[email protected]c11e6592014-06-27 17:07:3430 // ScriptInjector implementation.
dcheng9168b2f2014-10-21 12:38:2431 UserScript::InjectionType script_type() const override;
dcheng9168b2f2014-10-21 12:38:2432 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(
hanxia5c856cf2015-02-13 20:51:5838 const InjectionHost* injection_host,
rdevlin.cronin3e11c9862015-06-04 19:54:2539 blink::WebLocalFrame* web_frame,
rdevlin.croninf994d1e2015-06-03 22:28:1940 int tab_id) const override;
dcheng9168b2f2014-10-21 12:38:2441 std::vector<blink::WebScriptSource> GetJsSources(
mostynb0eac4e1b2014-10-03 16:32:1942 UserScript::RunLocation run_location) const override;
dcheng9168b2f2014-10-21 12:38:2443 std::vector<std::string> GetCssSources(
mostynb0eac4e1b2014-10-03 16:32:1944 UserScript::RunLocation run_location) const override;
kozyatinskiyc8bc9a582015-03-06 09:33:4145 void GetRunInfo(ScriptsRunInfo* scripts_run_info,
46 UserScript::RunLocation run_location) const override;
rdevlin.cronin4bb32d72015-06-02 21:55:0147 void OnInjectionComplete(scoped_ptr<base::Value> execution_result,
rdevlin.cronind533be962015-10-02 17:01:1848 UserScript::RunLocation run_location,
49 content::RenderFrame* render_frame) override;
50 void OnWillNotInject(InjectFailureReason reason,
51 content::RenderFrame* render_frame) override;
[email protected]c11e6592014-06-27 17:07:3452
53 // Return the run location for this injector.
54 UserScript::RunLocation GetRunLocation() const;
55
56 // Notify the browser that the script was injected (or never will be), and
57 // send along any results or errors.
rdevlin.cronind533be962015-10-02 17:01:1858 void Finish(const std::string& error, content::RenderFrame* render_frame);
[email protected]c11e6592014-06-27 17:07:3459
60 // The parameters for injecting the script.
61 scoped_ptr<ExtensionMsg_ExecuteCode_Params> params_;
62
[email protected]cde18a2d2014-07-01 03:13:0463 // The url of the frame into which we are injecting.
64 GURL url_;
65
roba9e6e6422015-03-30 21:14:0266 // The URL of the frame's origin. This is usually identical to |url_|, but
67 // could be different for e.g. about:blank URLs. Do not use this value to make
68 // security decisions, to avoid race conditions (e.g. due to navigation).
69 GURL effective_url_;
70
[email protected]c11e6592014-06-27 17:07:3471 // The results of the script execution.
rdevlin.cronin4bb32d72015-06-02 21:55:0172 base::ListValue results_;
[email protected]c11e6592014-06-27 17:07:3473
74 // Whether or not this script injection has finished.
75 bool finished_;
76
77 DISALLOW_COPY_AND_ASSIGN(ProgrammaticScriptInjector);
78};
79
80} // namespace extensions
81
82#endif // EXTENSIONS_RENDERER_PROGRAMMATIC_SCRIPT_INJECTOR_H_