OLD | NEW |
---|---|
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/permissions/permissions_data.h" |
12 #include "extensions/common/user_script.h" | 12 #include "extensions/common/user_script.h" |
13 #include "third_party/WebKit/public/web/WebScriptSource.h" | 13 #include "third_party/WebKit/public/web/WebScriptSource.h" |
14 | 14 |
15 class Host; | |
15 class GURL; | 16 class GURL; |
16 | 17 |
17 namespace blink { | 18 namespace blink { |
18 class WebFrame; | 19 class WebFrame; |
19 } | 20 } |
20 | 21 |
21 namespace extensions { | 22 namespace extensions { |
22 class Extension; | 23 class Extension; |
Devlin
2015/02/09 17:40:25
Don't need this, right?
Xi Han
2015/02/09 23:28:11
Done.
| |
23 struct ScriptsRunInfo; | 24 struct ScriptsRunInfo; |
24 | 25 |
25 // The pseudo-delegate class for a ScriptInjection that provides all necessary | 26 // The pseudo-delegate class for a ScriptInjection that provides all necessary |
26 // 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, |
27 // when (run location), and where (world), but without any injection logic. | 28 // when (run location), and where (world), but without any injection logic. |
28 class ScriptInjector { | 29 class ScriptInjector { |
29 public: | 30 public: |
30 // The possible reasons for not injecting the script. | 31 // The possible reasons for not injecting the script. |
31 enum InjectFailureReason { | 32 enum InjectFailureReason { |
32 EXTENSION_REMOVED, // The extension was removed before injection. | 33 EXTENSION_REMOVED, // The extension was removed before injection. |
(...skipping 21 matching lines...) Expand all Loading... | |
54 | 55 |
55 // 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 |
56 // |run_location|. | 57 // |run_location|. |
57 virtual bool ShouldInjectJs(UserScript::RunLocation run_location) const = 0; | 58 virtual bool ShouldInjectJs(UserScript::RunLocation run_location) const = 0; |
58 | 59 |
59 // 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|. |
60 virtual bool ShouldInjectCss(UserScript::RunLocation run_location) const = 0; | 61 virtual bool ShouldInjectCss(UserScript::RunLocation run_location) const = 0; |
61 | 62 |
62 // Returns true if the script should execute on the given |frame|. | 63 // Returns true if the script should execute on the given |frame|. |
63 virtual PermissionsData::AccessType CanExecuteOnFrame( | 64 virtual PermissionsData::AccessType CanExecuteOnFrame( |
64 const Extension* extension, | 65 const Host* host, |
65 blink::WebFrame* web_frame, | 66 blink::WebFrame* web_frame, |
66 int tab_id, | 67 int tab_id, |
67 const GURL& top_url) const = 0; | 68 const GURL& top_url) const = 0; |
68 | 69 |
69 // Returns the javascript sources to inject at the given |run_location|. | 70 // Returns the javascript sources to inject at the given |run_location|. |
70 // Only called if ShouldInjectJs() is true. | 71 // Only called if ShouldInjectJs() is true. |
71 virtual std::vector<blink::WebScriptSource> GetJsSources( | 72 virtual std::vector<blink::WebScriptSource> GetJsSources( |
72 UserScript::RunLocation run_location) const = 0; | 73 UserScript::RunLocation run_location) const = 0; |
73 | 74 |
74 // Returns the css to inject at the given |run_location|. | 75 // Returns the css to inject at the given |run_location|. |
75 // Only called if ShouldInjectCss() is true. | 76 // Only called if ShouldInjectCss() is true. |
76 virtual std::vector<std::string> GetCssSources( | 77 virtual std::vector<std::string> GetCssSources( |
77 UserScript::RunLocation run_location) const = 0; | 78 UserScript::RunLocation run_location) const = 0; |
78 | 79 |
79 // Notifies the script that injection has completed, with a possibly-populated | 80 // Notifies the script that injection has completed, with a possibly-populated |
80 // list of results (depending on whether or not ExpectsResults() was true). | 81 // list of results (depending on whether or not ExpectsResults() was true). |
81 virtual void OnInjectionComplete( | 82 virtual void OnInjectionComplete( |
82 scoped_ptr<base::ListValue> execution_results, | 83 scoped_ptr<base::ListValue> execution_results, |
83 ScriptsRunInfo* scripts_run_info, | 84 ScriptsRunInfo* scripts_run_info, |
84 UserScript::RunLocation run_location) = 0; | 85 UserScript::RunLocation run_location) = 0; |
85 | 86 |
86 // Notifies the script that injection will never occur. | 87 // Notifies the script that injection will never occur. |
87 virtual void OnWillNotInject(InjectFailureReason reason) = 0; | 88 virtual void OnWillNotInject(InjectFailureReason reason) = 0; |
88 }; | 89 }; |
89 | 90 |
90 } // namespace extensions | 91 } // namespace extensions |
91 | 92 |
92 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTOR_H_ | 93 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTOR_H_ |
OLD | NEW |