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