diff options
Diffstat (limited to 'chrome/browser')
9 files changed, 58 insertions, 17 deletions
diff --git a/chrome/browser/extensions/api/tabs/execute_code_in_tab_function.cc b/chrome/browser/extensions/api/tabs/execute_code_in_tab_function.cc index cdcbd0d..b967b10 100644 --- a/chrome/browser/extensions/api/tabs/execute_code_in_tab_function.cc +++ b/chrome/browser/extensions/api/tabs/execute_code_in_tab_function.cc @@ -143,7 +143,8 @@ bool ExecuteCodeInTabFunction::RunImpl() { void ExecuteCodeInTabFunction::OnExecuteCodeFinished(bool success, int32 page_id, - const std::string& error) { + const std::string& error, + const ListValue& result) { if (!error.empty()) { CHECK(!success); error_ = error; @@ -152,6 +153,17 @@ void ExecuteCodeInTabFunction::OnExecuteCodeFinished(bool success, SendResponse(success); } + +void TabsExecuteScriptFunction::OnExecuteCodeFinished(bool success, + int32 page_id, + const std::string& error, + const ListValue& result) { + if (error.empty()) + result_.reset(result.DeepCopy()); + ExecuteCodeInTabFunction::OnExecuteCodeFinished(success, page_id, error, + result); +} + void ExecuteCodeInTabFunction::DidLoadFile(bool success, const std::string& data) { std::string function_name = name(); diff --git a/chrome/browser/extensions/api/tabs/execute_code_in_tab_function.h b/chrome/browser/extensions/api/tabs/execute_code_in_tab_function.h index 5c97e3e..a954ede 100644 --- a/chrome/browser/extensions/api/tabs/execute_code_in_tab_function.h +++ b/chrome/browser/extensions/api/tabs/execute_code_in_tab_function.h @@ -23,12 +23,13 @@ class ExecuteCodeInTabFunction : public AsyncExtensionFunction { // ExtensionFunction: virtual bool RunImpl() OVERRIDE; - private: // Message handler. - void OnExecuteCodeFinished(bool success, - int32 page_id, - const std::string& error); + virtual void OnExecuteCodeFinished(bool success, + int32 page_id, + const std::string& error, + const ListValue& script_result); + private: // Called when contents from the file whose path is specified in JSON // arguments has been loaded. void DidLoadFile(bool success, const std::string& data); @@ -66,6 +67,9 @@ class ExecuteCodeInTabFunction : public AsyncExtensionFunction { class TabsExecuteScriptFunction : public ExecuteCodeInTabFunction { private: virtual ~TabsExecuteScriptFunction() {} + virtual void OnExecuteCodeFinished(bool success, int32 page_id, + const std::string& error, + const ListValue& script_result) OVERRIDE; DECLARE_EXTENSION_FUNCTION_NAME("tabs.executeScript") }; diff --git a/chrome/browser/extensions/api/tabs/tabs.cc b/chrome/browser/extensions/api/tabs/tabs.cc index 8b2ed1b..f245e17 100644 --- a/chrome/browser/extensions/api/tabs/tabs.cc +++ b/chrome/browser/extensions/api/tabs/tabs.cc @@ -1363,7 +1363,8 @@ void UpdateTabFunction::PopulateResult() { void UpdateTabFunction::OnExecuteCodeFinished(bool success, int32 page_id, - const std::string& error) { + const std::string& error, + const ListValue& script_result) { if (!error.empty()) { CHECK(!success); error_ = error; diff --git a/chrome/browser/extensions/api/tabs/tabs.h b/chrome/browser/extensions/api/tabs/tabs.h index 14276a0..f44e4e2 100644 --- a/chrome/browser/extensions/api/tabs/tabs.h +++ b/chrome/browser/extensions/api/tabs/tabs.h @@ -131,7 +131,8 @@ class UpdateTabFunction : public AsyncExtensionFunction { virtual bool RunImpl() OVERRIDE; void OnExecuteCodeFinished(bool success, int32 page_id, - const std::string& error); + const std::string& error, + const ListValue& script_result); DECLARE_EXTENSION_FUNCTION_NAME("tabs.update") }; diff --git a/chrome/browser/extensions/execute_script_apitest.cc b/chrome/browser/extensions/execute_script_apitest.cc index 0594c79..1edb440 100644 --- a/chrome/browser/extensions/execute_script_apitest.cc +++ b/chrome/browser/extensions/execute_script_apitest.cc @@ -78,3 +78,9 @@ IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptRunAt) { ASSERT_TRUE(StartTestServer()); ASSERT_TRUE(RunExtensionTest("executescript/run_at")) << message_; } + +IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptCallback) { + SetupDelayedHostResolver(); + ASSERT_TRUE(StartTestServer()); + ASSERT_TRUE(RunExtensionTest("executescript/callback")) << message_; +} diff --git a/chrome/browser/extensions/script_badge_controller.cc b/chrome/browser/extensions/script_badge_controller.cc index e15b259..bb655a6 100644 --- a/chrome/browser/extensions/script_badge_controller.cc +++ b/chrome/browser/extensions/script_badge_controller.cc @@ -88,13 +88,14 @@ void ScriptBadgeController::OnExecuteScriptFinished( const ExecuteScriptCallback& callback, bool success, int32 page_id, - const std::string& error) { + const std::string& error, + const base::ListValue& script_results) { if (success && page_id == GetPageID()) { if (InsertExtension(extension_id)) Notify(); } - callback.Run(success, page_id, error); + callback.Run(success, page_id, error, script_results); } ExtensionService* ScriptBadgeController::GetExtensionService() { diff --git a/chrome/browser/extensions/script_badge_controller.h b/chrome/browser/extensions/script_badge_controller.h index 420e666b..7ae4b6c 100644 --- a/chrome/browser/extensions/script_badge_controller.h +++ b/chrome/browser/extensions/script_badge_controller.h @@ -24,6 +24,10 @@ class ExtensionAction; class ExtensionService; class TabContents; +namespace base { +class ListValue; +} + namespace IPC { class Message; } @@ -79,7 +83,8 @@ class ScriptBadgeController const ExecuteScriptCallback& callback, bool success, int32 page_id, - const std::string& error); + const std::string& error, + const base::ListValue& script_result); // Gets the ExtensionService for |tab_contents_|. ExtensionService* GetExtensionService(); diff --git a/chrome/browser/extensions/script_executor.h b/chrome/browser/extensions/script_executor.h index 2119cc6..93c423e 100644 --- a/chrome/browser/extensions/script_executor.h +++ b/chrome/browser/extensions/script_executor.h @@ -11,6 +11,10 @@ #include "base/callback_forward.h" #include "chrome/common/extensions/user_script.h" +namespace base { + class ListValue; +} + namespace content { class WebContents; } @@ -42,9 +46,10 @@ class ScriptExecutor { ISOLATED_WORLD, }; - // Callback from ExecuteScript. The arguments are (success, page_id, error). - // page_id is only valid on success, error is only valid on !success. - typedef base::Callback<void(bool, int32, const std::string&)> + // Callback from ExecuteScript. The arguments are (success, page_id, error, + // result). page_id is only valid on success, error is only valid on !success. + typedef base::Callback<void(bool, int32, const std::string&, + const base::ListValue&)> ExecuteScriptCallback; // Executes a script. The arguments match ExtensionMsg_ExecuteCode_Params in diff --git a/chrome/browser/extensions/script_executor_impl.cc b/chrome/browser/extensions/script_executor_impl.cc index e8f6199..ae8c251 100644 --- a/chrome/browser/extensions/script_executor_impl.cc +++ b/chrome/browser/extensions/script_executor_impl.cc @@ -14,6 +14,10 @@ #include "ipc/ipc_message.h" #include "ipc/ipc_message_macros.h" +namespace base { +class ListValue; +} // namespace base + namespace extensions { namespace { @@ -58,7 +62,8 @@ class Handler : public content::WebContentsObserver { } virtual void WebContentsDestroyed(content::WebContents* tab) OVERRIDE { - callback_.Run(false, -1, kRendererDestroyed); + base::ListValue val; + callback_.Run(false, -1, kRendererDestroyed, val); delete this; } @@ -66,8 +71,9 @@ class Handler : public content::WebContentsObserver { void OnExecuteCodeFinished(int request_id, bool success, int32 page_id, - const std::string& error) { - callback_.Run(success, page_id, error); + const std::string& error, + const base::ListValue& script_result) { + callback_.Run(success, page_id, error, script_result); delete this; } @@ -98,7 +104,7 @@ void ScriptExecutorImpl::ExecuteScript( params.is_javascript = (script_type == JAVASCRIPT); params.code = code; params.all_frames = (frame_scope == ALL_FRAMES); - params.run_at = (int) run_at; + params.run_at = static_cast<int>(run_at); params.in_main_world = (world_type == MAIN_WORLD); // Handler handles IPCs and deletes itself on completion. |