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

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: Test fix 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
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/constants.h"
12 #include "extensions/common/permissions/permissions_data.h"
11 #include "extensions/common/user_script.h" 13 #include "extensions/common/user_script.h"
12 #include "third_party/WebKit/public/web/WebScriptSource.h" 14 #include "third_party/WebKit/public/web/WebScriptSource.h"
13 15
14 class GURL; 16 class GURL;
15 17
16 namespace blink { 18 namespace blink {
17 class WebFrame; 19 class WebFrame;
18 } 20 }
19 21
20 namespace extensions { 22 namespace extensions {
21 class Extension; 23 class Extension;
22 struct ScriptsRunInfo; 24 struct ScriptsRunInfo;
23 25
24 // The pseudo-delegate class for a ScriptInjection that provides all necessary 26 // The pseudo-delegate class for a ScriptInjection that provides all necessary
25 // information about how to inject the script, including what code to inject, 27 // information about how to inject the script, including what code to inject,
26 // when (run location), and where (world), but without any injection logic. 28 // when (run location), and where (world), but without any injection logic.
27 class ScriptInjector { 29 class ScriptInjector {
28 public: 30 public:
29 // The possible reasons for not injecting the script. 31 // The possible reasons for not injecting the script.
30 enum InjectFailureReason { 32 enum InjectFailureReason {
31 EXTENSION_REMOVED, // The extension was removed before injection. 33 EXTENSION_REMOVED, // The extension was removed before injection.
32 NOT_ALLOWED, // The script is not allowed to inject. 34 NOT_ALLOWED, // The script is not allowed to inject.
33 WONT_INJECT // The injection won't inject because the user rejected 35 WONT_INJECT // The injection won't inject because the user rejected
34 // (or just did not accept) the injection. 36 // (or just did not accept) the injection.
35 }; 37 };
36 38
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() {} 39 virtual ~ScriptInjector() {}
46 40
41 // Returns the script type of this particular injection.
42 virtual extension_misc::InjectedScriptType script_type() const = 0;
43
47 // Returns true if the script should execute in child frames. 44 // Returns true if the script should execute in child frames.
48 virtual bool ShouldExecuteInChildFrames() const = 0; 45 virtual bool ShouldExecuteInChildFrames() const = 0;
49 46
50 // Returns true if the script should execute in the main world. 47 // Returns true if the script should execute in the main world.
51 virtual bool ShouldExecuteInMainWorld() const = 0; 48 virtual bool ShouldExecuteInMainWorld() const = 0;
52 49
53 // Returns true if the script is running inside a user gesture. 50 // Returns true if the script is running inside a user gesture.
54 virtual bool IsUserGesture() const = 0; 51 virtual bool IsUserGesture() const = 0;
55 52
56 // Returns ture if the script expects results. 53 // Returns ture if the script expects results.
57 virtual bool ExpectsResults() const = 0; 54 virtual bool ExpectsResults() const = 0;
58 55
59 // Returns true if the script should inject JS source at the given 56 // Returns true if the script should inject JS source at the given
60 // |run_location|. 57 // |run_location|.
61 virtual bool ShouldInjectJs(UserScript::RunLocation run_location) const = 0; 58 virtual bool ShouldInjectJs(UserScript::RunLocation run_location) const = 0;
62 59
63 // Returns true if the script should inject CSS at the given |run_location|. 60 // Returns true if the script should inject CSS at the given |run_location|.
64 virtual bool ShouldInjectCss(UserScript::RunLocation run_location) const = 0; 61 virtual bool ShouldInjectCss(UserScript::RunLocation run_location) const = 0;
65 62
66 // Returns true if the script should execute on the given |frame|. 63 // Returns true if the script should execute on the given |frame|.
67 virtual AccessType CanExecuteOnFrame(const Extension* extension, 64 virtual PermissionsData::AccessType CanExecuteOnFrame(
68 blink::WebFrame* web_frame, 65 const Extension* extension,
69 int tab_id, 66 blink::WebFrame* web_frame,
70 const GURL& top_url) const = 0; 67 int tab_id,
68 const GURL& top_url) const = 0;
71 69
72 // Returns the javascript sources to inject at the given |run_location|. 70 // Returns the javascript sources to inject at the given |run_location|.
73 // Only called if ShouldInjectJs() is true. 71 // Only called if ShouldInjectJs() is true.
74 virtual std::vector<blink::WebScriptSource> GetJsSources( 72 virtual std::vector<blink::WebScriptSource> GetJsSources(
75 UserScript::RunLocation run_location) const = 0; 73 UserScript::RunLocation run_location) const = 0;
76 74
77 // Returns the css to inject at the given |run_location|. 75 // Returns the css to inject at the given |run_location|.
78 // Only called if ShouldInjectCss() is true. 76 // Only called if ShouldInjectCss() is true.
79 virtual std::vector<std::string> GetCssSources( 77 virtual std::vector<std::string> GetCssSources(
80 UserScript::RunLocation run_location) const = 0; 78 UserScript::RunLocation run_location) const = 0;
81 79
82 // Notifies the script that injection has completed, with a possibly-populated 80 // Notifies the script that injection has completed, with a possibly-populated
83 // list of results (depending on whether or not ExpectsResults() was true). 81 // list of results (depending on whether or not ExpectsResults() was true).
84 virtual void OnInjectionComplete( 82 virtual void OnInjectionComplete(
85 scoped_ptr<base::ListValue> execution_results, 83 scoped_ptr<base::ListValue> execution_results,
86 ScriptsRunInfo* scripts_run_info, 84 ScriptsRunInfo* scripts_run_info,
87 UserScript::RunLocation run_location) = 0; 85 UserScript::RunLocation run_location) = 0;
88 86
89 // Notifies the script that injection will never occur. 87 // Notifies the script that injection will never occur.
90 virtual void OnWillNotInject(InjectFailureReason reason) = 0; 88 virtual void OnWillNotInject(InjectFailureReason reason) = 0;
91 }; 89 };
92 90
93 } // namespace extensions 91 } // namespace extensions
94 92
95 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTOR_H_ 93 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698