| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_SCRIPT_EXECUTOR_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_SCRIPT_EXECUTOR_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_SCRIPT_EXECUTOR_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_SCRIPT_EXECUTOR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 TOP_FRAME, | 48 TOP_FRAME, |
| 49 ALL_FRAMES, | 49 ALL_FRAMES, |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 // The type of world to inject into (main world, or its own isolated world). | 52 // The type of world to inject into (main world, or its own isolated world). |
| 53 enum WorldType { | 53 enum WorldType { |
| 54 MAIN_WORLD, | 54 MAIN_WORLD, |
| 55 ISOLATED_WORLD, | 55 ISOLATED_WORLD, |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // The type of process the target is. |
| 59 enum ProcessType { |
| 60 DEFAULT_PROCESS, |
| 61 WEB_VIEW_PROCESS, |
| 62 }; |
| 63 |
| 64 // The type of result the caller is interested in. |
| 65 enum ResultType { |
| 66 NO_RESULT, |
| 67 JSON_SERIALIZED_RESULT, |
| 68 }; |
| 69 |
| 58 // Callback from ExecuteScript. The arguments are (error, on_page_id, on_url, | 70 // Callback from ExecuteScript. The arguments are (error, on_page_id, on_url, |
| 59 // result). Success is implied by an empty error. | 71 // result). Success is implied by an empty error. |
| 60 typedef base::Callback<void(const std::string&, int32, const GURL&, | 72 typedef base::Callback<void(const std::string&, int32, const GURL&, |
| 61 const base::ListValue&)> | 73 const base::ListValue&)> |
| 62 ExecuteScriptCallback; | 74 ExecuteScriptCallback; |
| 63 | 75 |
| 64 // Executes a script. The arguments match ExtensionMsg_ExecuteCode_Params in | 76 // Executes a script. The arguments match ExtensionMsg_ExecuteCode_Params in |
| 65 // extension_messages.h (request_id is populated automatically). | 77 // extension_messages.h (request_id is populated automatically). |
| 66 // | 78 // |
| 67 // |callback| will always be called even if the IPC'd renderer is destroyed | 79 // |callback| will always be called even if the IPC'd renderer is destroyed |
| 68 // before a response is received (in this case the callback will be with a | 80 // before a response is received (in this case the callback will be with a |
| 69 // failure and appropriate error message). | 81 // failure and appropriate error message). |
| 70 void ExecuteScript(const std::string& extension_id, | 82 void ExecuteScript(const std::string& extension_id, |
| 71 ScriptType script_type, | 83 ScriptType script_type, |
| 72 const std::string& code, | 84 const std::string& code, |
| 73 FrameScope frame_scope, | 85 FrameScope frame_scope, |
| 74 UserScript::RunLocation run_at, | 86 UserScript::RunLocation run_at, |
| 75 WorldType world_type, | 87 WorldType world_type, |
| 76 bool is_web_view, | 88 ProcessType process_type, |
| 89 ResultType result_type, |
| 77 const ExecuteScriptCallback& callback); | 90 const ExecuteScriptCallback& callback); |
| 78 | 91 |
| 79 private: | 92 private: |
| 80 // The next value to use for request_id in ExtensionMsg_ExecuteCode_Params. | 93 // The next value to use for request_id in ExtensionMsg_ExecuteCode_Params. |
| 81 int next_request_id_; | 94 int next_request_id_; |
| 82 | 95 |
| 83 content::WebContents* web_contents_; | 96 content::WebContents* web_contents_; |
| 84 | 97 |
| 85 ObserverList<TabHelper::ScriptExecutionObserver>* script_observers_; | 98 ObserverList<TabHelper::ScriptExecutionObserver>* script_observers_; |
| 86 }; | 99 }; |
| 87 | 100 |
| 88 } // namespace extensions | 101 } // namespace extensions |
| 89 | 102 |
| 90 #endif // CHROME_BROWSER_EXTENSIONS_SCRIPT_EXECUTOR_H_ | 103 #endif // CHROME_BROWSER_EXTENSIONS_SCRIPT_EXECUTOR_H_ |
| OLD | NEW |