Index: chrome/browser/extensions/script_executor.h |
diff --git a/chrome/browser/extensions/script_executor.h b/chrome/browser/extensions/script_executor.h |
index 2119cc63ce82f4ddc9287e757dddf1287f6440ea..d81fa14805d201dbec339b3d0bf96f4d9bc1b043 100644 |
--- a/chrome/browser/extensions/script_executor.h |
+++ b/chrome/browser/extensions/script_executor.h |
@@ -9,6 +9,7 @@ |
#include <string> |
#include "base/callback_forward.h" |
+#include "base/observer_list.h" |
#include "chrome/common/extensions/user_script.h" |
namespace content { |
@@ -22,7 +23,9 @@ namespace extensions { |
// caller when responded with ExtensionHostMsg_ExecuteCodeFinished. |
class ScriptExecutor { |
public: |
- virtual ~ScriptExecutor() {} |
+ explicit ScriptExecutor(content::WebContents* web_contents); |
+ |
+ ~ScriptExecutor(); |
// The type of script being injected. |
enum ScriptType { |
@@ -47,19 +50,51 @@ class ScriptExecutor { |
typedef base::Callback<void(bool, int32, const std::string&)> |
ExecuteScriptCallback; |
+ class Observer { |
+ public: |
+ // Automatically observes and unobserves *script_executor on construction |
+ // and destruction. *script_executor must outlive *this. |
+ explicit Observer(ScriptExecutor* script_executor); |
+ virtual ~Observer(); |
+ |
+ virtual void OnExecuteScriptFinished(const std::string& extension_id, |
+ bool success, |
+ int32 page_id, |
+ const std::string& error) = 0; |
+ private: |
+ ScriptExecutor& script_executor_; |
+ }; |
+ |
// Executes a script. The arguments match ExtensionMsg_ExecuteCode_Params in |
// extension_messages.h (request_id is populated automatically). |
// |
// |callback| will always be called even if the IPC'd renderer is destroyed |
// before a response is received (in this case the callback will be with a |
// failure and appropriate error message). |
- virtual void ExecuteScript(const std::string& extension_id, |
- ScriptType script_type, |
- const std::string& code, |
- FrameScope frame_scope, |
- UserScript::RunLocation run_at, |
- WorldType world_type, |
- const ExecuteScriptCallback& callback) = 0; |
+ void ExecuteScript(const std::string& extension_id, |
+ ScriptType script_type, |
+ const std::string& code, |
+ FrameScope frame_scope, |
+ UserScript::RunLocation run_at, |
+ WorldType world_type, |
+ const ExecuteScriptCallback& callback); |
+ |
+ void AddObserver(Observer* obs) { |
+ observer_list_.AddObserver(obs); |
+ } |
+ |
+ void RemoveObserver(Observer* obs) { |
+ observer_list_.RemoveObserver(obs); |
+ } |
+ |
+ private: |
+ // The next value to use for request_id in ExtensionMsg_ExecuteCode_Params. |
+ int next_request_id_; |
+ |
+ // The WebContents this is bound to. |
+ content::WebContents* web_contents_; |
+ |
+ ObserverList<Observer> observer_list_; |
}; |
} // namespace extensions |