Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: extensions/renderer/script_injector.h

Issue 348313003: Create withheld permissions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Latest master Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « extensions/renderer/script_injection.cc ('k') | extensions/renderer/user_script_injector.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef EXTENSIONS_RENDERER_SCRIPT_INJECTOR_H_ 5 #ifndef EXTENSIONS_RENDERER_SCRIPT_INJECTOR_H_
6 #define EXTENSIONS_RENDERER_SCRIPT_INJECTOR_H_ 6 #define EXTENSIONS_RENDERER_SCRIPT_INJECTOR_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "extensions/common/permissions/permissions_data.h"
11 #include "extensions/common/user_script.h" 12 #include "extensions/common/user_script.h"
12 #include "third_party/WebKit/public/web/WebScriptSource.h" 13 #include "third_party/WebKit/public/web/WebScriptSource.h"
13 14
14 class GURL; 15 class GURL;
15 16
16 namespace blink { 17 namespace blink {
17 class WebFrame; 18 class WebFrame;
18 } 19 }
19 20
20 namespace extensions { 21 namespace extensions {
21 class Extension; 22 class Extension;
22 struct ScriptsRunInfo; 23 struct ScriptsRunInfo;
23 24
24 // The pseudo-delegate class for a ScriptInjection that provides all necessary 25 // The pseudo-delegate class for a ScriptInjection that provides all necessary
25 // information about how to inject the script, including what code to inject, 26 // information about how to inject the script, including what code to inject,
26 // when (run location), and where (world), but without any injection logic. 27 // when (run location), and where (world), but without any injection logic.
27 class ScriptInjector { 28 class ScriptInjector {
28 public: 29 public:
29 // The possible reasons for not injecting the script. 30 // The possible reasons for not injecting the script.
30 enum InjectFailureReason { 31 enum InjectFailureReason {
31 EXTENSION_REMOVED, // The extension was removed before injection. 32 EXTENSION_REMOVED, // The extension was removed before injection.
32 NOT_ALLOWED, // The script is not allowed to inject. 33 NOT_ALLOWED, // The script is not allowed to inject.
33 WONT_INJECT // The injection won't inject because the user rejected 34 WONT_INJECT // The injection won't inject because the user rejected
34 // (or just did not accept) the injection. 35 // (or just did not accept) the injection.
35 }; 36 };
36 37
37 // The possible types of access for a given frame.
38 enum AccessType {
39 DENY_ACCESS, // The script cannot access the given frame.
40 ALLOW_ACCESS, // The script can access the given frame.
41 REQUEST_ACCESS // The browser must determine if the script can access the
42 // given frame.
43 };
44
45 virtual ~ScriptInjector() {} 38 virtual ~ScriptInjector() {}
46 39
40 // Returns the script type of this particular injection.
41 virtual UserScript::InjectionType script_type() const = 0;
42
47 // Returns true if the script should execute in child frames. 43 // Returns true if the script should execute in child frames.
48 virtual bool ShouldExecuteInChildFrames() const = 0; 44 virtual bool ShouldExecuteInChildFrames() const = 0;
49 45
50 // Returns true if the script should execute in the main world. 46 // Returns true if the script should execute in the main world.
51 virtual bool ShouldExecuteInMainWorld() const = 0; 47 virtual bool ShouldExecuteInMainWorld() const = 0;
52 48
53 // Returns true if the script is running inside a user gesture. 49 // Returns true if the script is running inside a user gesture.
54 virtual bool IsUserGesture() const = 0; 50 virtual bool IsUserGesture() const = 0;
55 51
56 // Returns ture if the script expects results. 52 // Returns ture if the script expects results.
57 virtual bool ExpectsResults() const = 0; 53 virtual bool ExpectsResults() const = 0;
58 54
59 // Returns true if the script should inject JS source at the given 55 // Returns true if the script should inject JS source at the given
60 // |run_location|. 56 // |run_location|.
61 virtual bool ShouldInjectJs(UserScript::RunLocation run_location) const = 0; 57 virtual bool ShouldInjectJs(UserScript::RunLocation run_location) const = 0;
62 58
63 // Returns true if the script should inject CSS at the given |run_location|. 59 // Returns true if the script should inject CSS at the given |run_location|.
64 virtual bool ShouldInjectCss(UserScript::RunLocation run_location) const = 0; 60 virtual bool ShouldInjectCss(UserScript::RunLocation run_location) const = 0;
65 61
66 // Returns true if the script should execute on the given |frame|. 62 // Returns true if the script should execute on the given |frame|.
67 virtual AccessType CanExecuteOnFrame(const Extension* extension, 63 virtual PermissionsData::AccessType CanExecuteOnFrame(
68 blink::WebFrame* web_frame, 64 const Extension* extension,
69 int tab_id, 65 blink::WebFrame* web_frame,
70 const GURL& top_url) const = 0; 66 int tab_id,
67 const GURL& top_url) const = 0;
71 68
72 // Returns the javascript sources to inject at the given |run_location|. 69 // Returns the javascript sources to inject at the given |run_location|.
73 // Only called if ShouldInjectJs() is true. 70 // Only called if ShouldInjectJs() is true.
74 virtual std::vector<blink::WebScriptSource> GetJsSources( 71 virtual std::vector<blink::WebScriptSource> GetJsSources(
75 UserScript::RunLocation run_location) const = 0; 72 UserScript::RunLocation run_location) const = 0;
76 73
77 // Returns the css to inject at the given |run_location|. 74 // Returns the css to inject at the given |run_location|.
78 // Only called if ShouldInjectCss() is true. 75 // Only called if ShouldInjectCss() is true.
79 virtual std::vector<std::string> GetCssSources( 76 virtual std::vector<std::string> GetCssSources(
80 UserScript::RunLocation run_location) const = 0; 77 UserScript::RunLocation run_location) const = 0;
81 78
82 // Notifies the script that injection has completed, with a possibly-populated 79 // Notifies the script that injection has completed, with a possibly-populated
83 // list of results (depending on whether or not ExpectsResults() was true). 80 // list of results (depending on whether or not ExpectsResults() was true).
84 virtual void OnInjectionComplete( 81 virtual void OnInjectionComplete(
85 scoped_ptr<base::ListValue> execution_results, 82 scoped_ptr<base::ListValue> execution_results,
86 ScriptsRunInfo* scripts_run_info, 83 ScriptsRunInfo* scripts_run_info,
87 UserScript::RunLocation run_location) = 0; 84 UserScript::RunLocation run_location) = 0;
88 85
89 // Notifies the script that injection will never occur. 86 // Notifies the script that injection will never occur.
90 virtual void OnWillNotInject(InjectFailureReason reason) = 0; 87 virtual void OnWillNotInject(InjectFailureReason reason) = 0;
91 }; 88 };
92 89
93 } // namespace extensions 90 } // namespace extensions
94 91
95 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTOR_H_ 92 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTOR_H_
OLDNEW
« no previous file with comments | « extensions/renderer/script_injection.cc ('k') | extensions/renderer/user_script_injector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698