Chromium Code Reviews| 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_BROWSER_SCRIPT_EXECUTOR_H_ | 5 #ifndef EXTENSIONS_BROWSER_SCRIPT_EXECUTOR_H_ |
| 6 #define EXTENSIONS_BROWSER_SCRIPT_EXECUTOR_H_ | 6 #define EXTENSIONS_BROWSER_SCRIPT_EXECUTOR_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
| 10 #include "extensions/common/user_script.h" | 10 #include "extensions/common/user_script.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 ~ScriptExecutor(); | 37 ~ScriptExecutor(); |
| 38 | 38 |
| 39 // The type of script being injected. | 39 // The type of script being injected. |
| 40 enum ScriptType { | 40 enum ScriptType { |
| 41 JAVASCRIPT, | 41 JAVASCRIPT, |
| 42 CSS, | 42 CSS, |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 // The scope of the script injection across the frames. | 45 // The scope of the script injection across the frames. |
| 46 enum FrameScope { | 46 enum FrameScope { |
| 47 TOP_FRAME, | 47 SINGLE_FRAME, |
| 48 ALL_FRAMES, | 48 INCLUDE_SUB_FRAMES, |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 // Whether to insert the script in about: frames when its origin matches | 51 // Whether to insert the script in about: frames when its origin matches |
| 52 // the extension's host permissions. | 52 // the extension's host permissions. |
| 53 enum MatchAboutBlank { | 53 enum MatchAboutBlank { |
| 54 DONT_MATCH_ABOUT_BLANK, | 54 DONT_MATCH_ABOUT_BLANK, |
| 55 MATCH_ABOUT_BLANK, | 55 MATCH_ABOUT_BLANK, |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // The type of world to inject into (main world, or its own isolated world). | 58 // The type of world to inject into (main world, or its own isolated world). |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 75 | 75 |
| 76 // Callback from ExecuteScript. The arguments are (error, on_url, result). | 76 // Callback from ExecuteScript. The arguments are (error, on_url, result). |
| 77 // Success is implied by an empty error. | 77 // Success is implied by an empty error. |
| 78 typedef base::Callback< | 78 typedef base::Callback< |
| 79 void(const std::string&, const GURL&, const base::ListValue&)> | 79 void(const std::string&, const GURL&, const base::ListValue&)> |
| 80 ExecuteScriptCallback; | 80 ExecuteScriptCallback; |
| 81 | 81 |
| 82 // Executes a script. The arguments match ExtensionMsg_ExecuteCode_Params in | 82 // Executes a script. The arguments match ExtensionMsg_ExecuteCode_Params in |
| 83 // extension_messages.h (request_id is populated automatically). | 83 // extension_messages.h (request_id is populated automatically). |
| 84 // | 84 // |
| 85 // The script will be executed in the frame identified by |frame_id| (which is | |
| 86 // an extension API frame ID). If |frame_scope| is ALL_FRAMES, then the script | |
|
Devlin
2016/02/01 19:04:07
nit: s/ALL_FRAMES/INCLUDE_SUB_FRAMES
robwu
2016/02/02 15:28:19
Done.
| |
| 87 // will also be executed in all descendants of the frame. | |
| 88 // | |
| 85 // |callback| will always be called even if the IPC'd renderer is destroyed | 89 // |callback| will always be called even if the IPC'd renderer is destroyed |
| 86 // before a response is received (in this case the callback will be with a | 90 // before a response is received (in this case the callback will be with a |
| 87 // failure and appropriate error message). | 91 // failure and appropriate error message). |
| 88 void ExecuteScript(const HostID& host_id, | 92 void ExecuteScript(const HostID& host_id, |
| 89 ScriptType script_type, | 93 ScriptType script_type, |
| 90 const std::string& code, | 94 const std::string& code, |
| 91 FrameScope frame_scope, | 95 FrameScope frame_scope, |
| 96 int frame_id, | |
| 92 MatchAboutBlank match_about_blank, | 97 MatchAboutBlank match_about_blank, |
| 93 UserScript::RunLocation run_at, | 98 UserScript::RunLocation run_at, |
| 94 WorldType world_type, | 99 WorldType world_type, |
| 95 ProcessType process_type, | 100 ProcessType process_type, |
| 96 const GURL& webview_src, | 101 const GURL& webview_src, |
| 97 const GURL& file_url, | 102 const GURL& file_url, |
| 98 bool user_gesture, | 103 bool user_gesture, |
| 99 ResultType result_type, | 104 ResultType result_type, |
| 100 const ExecuteScriptCallback& callback); | 105 const ExecuteScriptCallback& callback); |
| 101 | 106 |
| 102 private: | 107 private: |
| 103 // The next value to use for request_id in ExtensionMsg_ExecuteCode_Params. | 108 // The next value to use for request_id in ExtensionMsg_ExecuteCode_Params. |
| 104 int next_request_id_; | 109 int next_request_id_; |
| 105 | 110 |
| 106 content::WebContents* web_contents_; | 111 content::WebContents* web_contents_; |
| 107 | 112 |
| 108 base::ObserverList<ScriptExecutionObserver>* script_observers_; | 113 base::ObserverList<ScriptExecutionObserver>* script_observers_; |
| 109 }; | 114 }; |
| 110 | 115 |
| 111 } // namespace extensions | 116 } // namespace extensions |
| 112 | 117 |
| 113 #endif // EXTENSIONS_BROWSER_SCRIPT_EXECUTOR_H_ | 118 #endif // EXTENSIONS_BROWSER_SCRIPT_EXECUTOR_H_ |
| OLD | NEW |