Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / extensions / renderer / programmatic_script_injector.h
blob1f5584c65e41d8ae92e73a38b8d2eaeeb1d055e1
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.
5 #ifndef EXTENSIONS_RENDERER_PROGRAMMATIC_SCRIPT_INJECTOR_H_
6 #define EXTENSIONS_RENDERER_PROGRAMMATIC_SCRIPT_INJECTOR_H_
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h"
11 #include "extensions/renderer/script_injection.h"
12 #include "url/gurl.h"
14 struct ExtensionMsg_ExecuteCode_Params;
16 namespace content {
17 class RenderFrame;
20 namespace extensions {
22 // A ScriptInjector to handle tabs.executeScript().
23 class ProgrammaticScriptInjector : public ScriptInjector {
24 public:
25 ProgrammaticScriptInjector(const ExtensionMsg_ExecuteCode_Params& params,
26 content::RenderFrame* render_frame);
27 ~ProgrammaticScriptInjector() override;
29 private:
30 class FrameWatcher;
32 // ScriptInjector implementation.
33 UserScript::InjectionType script_type() const override;
34 bool ShouldExecuteInMainWorld() const override;
35 bool IsUserGesture() const override;
36 bool ExpectsResults() const override;
37 bool ShouldInjectJs(UserScript::RunLocation run_location) const override;
38 bool ShouldInjectCss(UserScript::RunLocation run_location) const override;
39 PermissionsData::AccessType CanExecuteOnFrame(
40 const InjectionHost* injection_host,
41 blink::WebLocalFrame* web_frame,
42 int tab_id) const override;
43 std::vector<blink::WebScriptSource> GetJsSources(
44 UserScript::RunLocation run_location) const override;
45 std::vector<std::string> GetCssSources(
46 UserScript::RunLocation run_location) const override;
47 void GetRunInfo(ScriptsRunInfo* scripts_run_info,
48 UserScript::RunLocation run_location) const override;
49 void OnInjectionComplete(scoped_ptr<base::Value> execution_result,
50 UserScript::RunLocation run_location) override;
51 void OnWillNotInject(InjectFailureReason reason) override;
53 // Return the run location for this injector.
54 UserScript::RunLocation GetRunLocation() const;
56 // Notify the browser that the script was injected (or never will be), and
57 // send along any results or errors.
58 void Finish(const std::string& error);
60 // The parameters for injecting the script.
61 scoped_ptr<ExtensionMsg_ExecuteCode_Params> params_;
63 // The url of the frame into which we are injecting.
64 GURL url_;
66 // 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_;
71 // A helper class to hold the render frame and watch for its deletion.
72 scoped_ptr<FrameWatcher> frame_watcher_;
74 // The results of the script execution.
75 base::ListValue results_;
77 // Whether or not this script injection has finished.
78 bool finished_;
80 DISALLOW_COPY_AND_ASSIGN(ProgrammaticScriptInjector);
83 } // namespace extensions
85 #endif // EXTENSIONS_RENDERER_PROGRAMMATIC_SCRIPT_INJECTOR_H_