OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_SCRIPT_EXECUTOR_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_SCRIPT_EXECUTOR_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 |
| 11 #include "base/callback_forward.h" |
| 12 #include "chrome/common/extensions/user_script.h" |
| 13 |
| 14 namespace content { |
| 15 class WebContents; |
| 16 } |
| 17 |
| 18 namespace extensions { |
| 19 |
| 20 // Interface for executing extension content scripts (e.g. executeScript) as |
| 21 // described by the ExtensionMsg_ExecuteCode_Params IPC, and notifying the |
| 22 // caller when responded with ExtensionHostMsg_ExecuteCodeFinished. |
| 23 class ScriptExecutor { |
| 24 public: |
| 25 virtual ~ScriptExecutor() {} |
| 26 |
| 27 // The type of script being injected. |
| 28 enum ScriptType { |
| 29 JAVASCRIPT, |
| 30 CSS, |
| 31 }; |
| 32 |
| 33 // The scope of the script injection across the frames. |
| 34 enum FrameScope { |
| 35 TOP_FRAME, |
| 36 ALL_FRAMES, |
| 37 }; |
| 38 |
| 39 // The type of world to inject into (main world, or its own isolated world). |
| 40 enum WorldType { |
| 41 MAIN_WORLD, |
| 42 ISOLATED_WORLD, |
| 43 }; |
| 44 |
| 45 // Callback from ExecuteScript. The arguments are (success, error). |
| 46 typedef base::Callback<void(bool, const std::string&)> ExecuteScriptCallback; |
| 47 |
| 48 // Executes a script. The arguments match ExtensionMsg_ExecuteCode_Params in |
| 49 // extension_messages.h (request_id is populated automatically). |
| 50 // |
| 51 // |callback| will always be called even if the IPC'd renderer is destroyed |
| 52 // before a response is received (in this case the callback will be with a |
| 53 // failure and appropriate error message). |
| 54 virtual void ExecuteScript(const std::string& extension_id, |
| 55 ScriptType script_type, |
| 56 const std::string& code, |
| 57 FrameScope frame_scope, |
| 58 UserScript::RunLocation run_at, |
| 59 WorldType world_type, |
| 60 const ExecuteScriptCallback& callback) = 0; |
| 61 }; |
| 62 |
| 63 } // namespace extensions |
| 64 |
| 65 #endif // CHROME_BROWSER_EXTENSIONS_SCRIPT_EXECUTOR_H_ |
OLD | NEW |