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..05a2d79e970747b1c69e6cf350d791bbd27e7151 100644 |
--- a/chrome/browser/extensions/script_executor.h |
+++ b/chrome/browser/extensions/script_executor.h |
@@ -9,6 +9,8 @@ |
#include <string> |
#include "base/callback_forward.h" |
+#include "base/observer_list.h" |
+#include "base/scoped_observer.h" |
#include "chrome/common/extensions/user_script.h" |
namespace content { |
@@ -22,7 +24,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 +51,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); |
+ ~Observer() {} |
Jeffrey Yasskin
2012/07/10 19:14:44
This explicit destructor is required by chromium's
|
+ |
+ virtual void OnExecuteScriptFinished(const std::string& extension_id, |
+ bool success, |
+ int32 page_id, |
+ const std::string& error) = 0; |
+ private: |
+ ScopedObserver<ScriptExecutor, Observer> scoped_observer_; |
+ }; |
+ |
// 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 |